Devise – Demo Event Tool

I'm a developer and I enjoy programming.. :)
One of my play-projects is a tool called Devise. It's build for the demo group "Edge of Panic".
(We've made several releases (see bottom of this page))

I've did 3d coding for Edge of Panic a few years ago (look at the ugly recursive ball scene in the Breakpoint 2010 demo), but the the last two years I'm way to busy with my company to work on the 3d engine (which btw resulted in the development http://edbee.net/).

Though I'm very busy, I've managed to find some spare time to work on Devise.

Devise is used for creating timing events and triggers in the demo. The tool imports both midi-data of the music track and the audio data and visualizes these items. The events can be moved, resized altered etc.
Events can be as simple as on or off, or can contain spline data and in the future it should be possible to write code in the event bars.

The next image shows a screenshot of this tool (written in C++ Qt)

Screen Shot 2013-10-03 at 23.06.36

Last week we had a BBQ which was used to demonstrate the state of the engine. Watch the movie below:
Lights and other events are synced on the music. This syncing is done with the help of the devise tool.

Notice the transparency in combination with deferred lighting. Our engine is improving (great work blackstar!) :)

Some releases we've done:
- Breakpoint 2010 - http://www.youtube.com/watch?v=mkuS1COsHgQ (a quick demo hack build in a few weeks)
- Revision 2012 - http://www.youtube.com/watch?v=vkkftgkw56A (a more mature release)

We've planned to finish out next production on Revision 2014, with some great music from Mr-Z and Davizion

edbee

Edbee screenshot

Last week I released edbee to Github.
Edbee in the essence is an editor QWidget designed for use with Qt.

edbee logo

Edbee screenshot

Some history

I've started with this editor component in the summer of 2012 as an in house product.
Edbee has been created because I needed a source-code editor for my Qt Application. I'm developing a very specialistic developers tool, which requires some advanced editor handling. Unfortunately my attempts with diverse standard products failed.

QTextEdit didn't fit my needs, because it was to complex at some points (The richtext part) and way to limited at other parts (replacing the document backend).
I've given it a try but it really didn't do what I needed it to do.

Scintilla was a much better attempt, except it gave me problems with editor-synchronisation. The cause for this was a sort of incompatibility Iv'e got with the messaging system that Scintilla uses and the connection-system of Qt. I probably could have solved this (and I've did solved part of it), but it required me to make considerable changes in the Scintilla source code. I really didn't like the idea of maintaining a fork of Scintilla. (Btw. Scintilla is a very nice editor-component used by several products like Scite and Notepad++)

This lead me to think I could write an editor myself, so it would fit my needs. This shouldn't be that hard, just move the cursor and draw some letters (so I thought). Well I was very wrong :)
I really like Sublime Text, it really has really some awesome features, so while writing this editor I just implement one of my favorite features: multi-caret support.
Well this last decision really made the development a much harder, especially the undo part.

When the editor was at a certain level I needed support for syntax highlighting, I've first tried to implement a system like the one that Scintilla uses, because of the simplicity of implementing it. But after realizing that I needed to write a lexer for every language I really freaked out and decided to stick with the Textmate/Sublime grammar files.

But using textmate grammer-files required the inclusion of scopes to identify items in the text. So I build in supporting classes for scopes. To recognize these scopes I needed to run the regular expressions used in the grammar files.
Running these regexps in Qt with QRegExp doesn't work. Really it doesn't I tried it..!! I've included Oniguruma for this (The regexp engine of Textmate, Sublime and Ruby)

Now I was able to identify the scopes in the editor. When I had the scopes It was more then logical to use the theme files of Textmate because these were scope-based.

Why Opensource it?

Well I don't see any real big market for it. To be honestly I don't think the quality of the editor at this moment is at the required level for a commercial product. Also I hope to improve the quality of this product by open sourcing it. Though I'm a bit afraid for the criticism I might get on the written code, I hope that critics and remarks will improve my Qt coding knowledge and the overall quality of the editor component.
Also I really would like to see multi-caret support in many more products!

The Editor App

I've written an editor application for this text-component. The initial purpose was to create a simple application that could be used for playing with the component in a simple setting. The first version was a simple form of irresponsible code to quickly play with the thing. It still has a lot of dirty hacks in it.

The plan I have with this editor is to expand it to a full cross platform scriptable editor-environment.

I've build some binaries and placed the at https://bintray.com/gamecreature/edbee/edbee-app. Be warned though, I still need to figure out all dependencies of these executables (especially the windows version) and need a better way to distribute the editor.

There's still a lot of work todo..
If anybody is interested in helping please drop me an email ( rick, blommersit, nl )* or a tweet!@gamecreature :)
* Replace the comma/spaces with the correct two symbols

Crash when deleting QGraphicsProxyWidget

Currently I'm working on a track-based event editor. I'm building this editor with a QGraphicsScene. I use multiple QGraphicsViews for showing tracks and midi-events. Wave files etc...

To rename a track I was trying to show a QLineEdit directly above the track-name and commit the result when editing was completed.

Adding it to the scene like this:

QLineEdit* lineEdit = new QLineEdit("My Text");
// a few connected signals for listening to editingFinished and enterPressed
QGraphicsProxyWidget* proxyWidget = graphicsScene->addWidget( lineEdit )

While I was trying to delete a simple QGraphicsProxyWidget from my QGraphicsScene
it resulted in a crash. (Deleting proxyWidget also delete's it's QLineEdit child)

delete proxyWidget;

The stack-trace shows something about focus function withing Qt.
I tried several things like deleteLater. Calling clearFocus myself.
It all did not work..

The solution that worked for me is the following:

void editingFinishedHandler()
{
  scene()->removeItem( proxyWidget );
  proxyWidget->deleteLater();
}


(My previous solution, that's inferior to the one above: )

[code language="cpp"]
void editingFinishedHandler()
{
  proxyWidget->setWidget(0);  // < inferior solution, please see solution above
  proxyWidget->deleteLater();      
  lineEdit->deleteLater();    
}

QThread deleteLater not called on application Quit

Threading in Qt is not very hard (so it seems).
But there's no definitive way to use use QThread. Look at the different articles and opinions.

My opinion is to be pragmatic and consider the context and situation of your problem, and just use what's best for it. :)

In this article I would like to describe a problem I had with threading. I've got a gui application that uses several threads. It's an application with multiple tabs, and every tab has got several (always running) threads. These threads are event-queue threads and are waiting on messages (jobs) they need to process.

My application uses memory-leak detection so when an object doesn't get deleted I get an horrible message at the end.

I've made the threads self-destroy when you call quit:

  connect( thread, SIGNAL(finished()), thread, SLOT(deleteLater()) );

When you close the application directly via (Alt-F4 windows, or Cmd-Q on Mac) I destroy the different tabs an stop the threads.

I process this in the signal QApplication::aboutToQuit:

  thread->quit();
  thread->wait()

Calling quit ends the eventQueue of the thread and emits a finished() signal to the event queue..

But now there's a problem. I'm in the aboutToQuit signal. And it seems that the finished signal is placed on the event queue.

But the eventQueue isn't processed any more. The application exits the exec loop:

  qApp->exec();

When my application know exits I've got a problem the QThread is not deleted.

The finished() signal is placed on the qApp event queue, but isn't processed.

I've solved it by processing the eventQueue after my exec call.

int result =  qApp->exec();
int counter = 0;

while( qapp->eventDispatcher()->processEvents( QEventLoop::ExcludeUserInputEvents ) && counter < 25  ) 
{         
  ++counter;
}

I've created a loop to allow pending events to be processed. To be sure it will quit I've added a counter, but in my situation the loop is processed 2 times:

  • The first time: finished() is processed, and deleteLater() is posted to the eventQueue
  • The second time the deleteLater() is processed and the my QThread is deleted

Now I've finally got rid of that annoying memory leak message :)

** The non-deletion of QThread is not a real big issue, but the situation I describe here also applies to other slots I've connected to the finished() signal of the thread. These slot's aren't called without the method described above.