Tag Archives: C++

C++ (chew slowly)

I spent a some time on the weekend looking at Rosegarden for Windows for the first time in a while.  I’ve been meaning to get the device allocation working correctly with RtMidi and get the MIDI recording also working but it’s slightly more challenging when you have to pass stuff back from it’s own thread rather than having access to all the nice Driver level features we’ve built into Rosegarden.

Rosegarden has the concept of a Studio – originally this was designed around the idea of device templates and the autoload document in Logic Audio – so essentially you can set up your external MIDI and audio devices once and then save it all to your autoload file and every time you hit ‘New Composition’ you get a fresh canvas with all you devices all set up and raring to go.   In my original design I’d also expanded the idea of the Studio to encompass audio placement eventually so that you’d be able to mimic acoustics of virtual instruments and such like – so being able to place MIDI and audio instruments in the stereo (or more) sound field and have consistent effects.  However it just became a layer in the end whereby we could try and put sensible names onto MIDI instruments and provide something approaching a consistent interface across audio and MIDI.   Perhaps in this regard it wasn’t such a good idea simply copying the Logic Audio model because to be honest it wasn’t a very elegant solution – I just didn’t know any better.

Have a look at Albeton if you want to see a way that this can be addressed for recording purposes.

Anyway – I digress – Rosegarden has a Studio concept which is an abstraction of MIDI and Audio devices and I need to tie up my outgoing and incoming MIDI events to the Studio model if I’m to make Rosegarden understand what the events are and where they come from.  So I have to jump through a few hoops to make the MappedStudio (as it’s known at the sequencer level) available to the MidiThread.  At this point I got a great remind of how hokey C++ syntax is – as my RtMidi event callback is a static method I have to declare any data structures that it wants to use also as static.  As I’ve been used to the wonderful world of C# for a long time now I tried to write:

static public MyStructure m_myStructure;

In the class definition.  Forgetting of course that my scope definitions are section based in C++.  Then for the life of me could I remember how to initialise this static public structure in the code and where?  No – first I tried in the header (of course no joy), then in the body but of course I got the naming convention wrong.  Eventually I got my definitions correct after a lot of fiddling and probably some swearing and of course waiting for the rebuilds (don’t forget the linker errors) but it demonstrates to me just why I moved on around 2004 and tried another language or two after being mired in C++ land for a while.  It can all drive you insane and I’m just now thinking that I’ve not even started to think about debugging the undoubted mistakes I’ve made in memory management with the changes I’ve made.

So bear it in mind, C++ is wonderful for connecting across the seemingly impassable chasms of disparate functionality and fixing holes between APIs but it takes a bit of your soul with you every time you lose your temper.  So take small bites, chew slowly and keep topped up with plenty of fluids.  It’s going to get warm and shouty out there.