Deleting Instruments:

I've been trying to make deleting instruments during playback crash- and x-
run-free (it's fun to switch back and forth between different kits while a song 
is playing.) I haven't succeeded yet (actually I'm way off I think :-s ): While 
it does work most of the time, if you really torture Hydrogen, it can be made 
to crash. 
        One way is to fill a pattern with 32th notes on some instrument, play 
the 
pattern and delete the instrument. 
        Another way is to keep sending MIDI notes on instrument 16, and then 
loading 
a drumkit with less than 16 different sounds.

While trying to debug this problem I ran into an interesting problem: While 
trying to add a Note* (C++ pointer) to the song note queue, Hydrogen would 
sometimes fail an assertion in the Note class _constructor_! This means (and I 
could see from the debugger frame stack) that Note objects are created in 
memory, in order to sort a queue of Note _pointers_. It's not a memory leak, 
but it _could_ be a slowdown, as it happens in the realtime code.

I ended up putting the blame for this on the code that defines the note queue 
itself, and, most importantly, the _sorting criterion_ for that queue. This is 
on (or outside) my insight in C++; but the following patch is an attempt to 
define the comparison in a way that operates on pointers directly. I'd 
especially like

        a) wolke to try the patch and check if it further improves DSP load (I 
can't 
really see the difference on my machine, probably because it's a shit machine - 
the DSP% flutters about too much)
        b) Scott's comment (he's the one who implemented the priority queue 
first - 
perhaps he knows what's going on with this stuff :-) )

Enjoy
 - Jakob Lund.

Index: libs/hydrogen/src/hydrogen.cpp
===================================================================
--- libs/hydrogen/src/hydrogen.cpp	(revision 333)
+++ libs/hydrogen/src/hydrogen.cpp	(working copy)
@@ -108,12 +108,15 @@
 MidiInput *m_pMidiDriver = NULL;	///< MIDI input
 
 // overload the the > operator of Note objects for priority_queue
-bool operator> (const Note& pNote1, const Note &pNote2) {
-	return (pNote1.m_nHumanizeDelay + pNote1.get_position() * m_pAudioDriver->m_transport.m_nTickSize) > \
-		(pNote2.m_nHumanizeDelay + pNote2.get_position() * m_pAudioDriver->m_transport.m_nTickSize);
+struct compare_Notes {
+bool operator() ( Note* pNote1, Note* pNote2) {
+	return (pNote1->m_nHumanizeDelay + pNote1->get_position() * m_pAudioDriver->m_transport.m_nTickSize) > \
+		(pNote2->m_nHumanizeDelay + pNote2->get_position() * m_pAudioDriver->m_transport.m_nTickSize);
 }
+};
 
-std::priority_queue<Note*, std::deque<Note*>, std::greater<Note> > m_songNoteQueue;	/// Song Note FIFO
+//std::priority_queue<Note*, std::deque<Note*>, std::greater<Note> > m_songNoteQueue;	/// Song Note FIFO
+std::priority_queue<Note*, std::deque<Note*>, compare_Notes > m_songNoteQueue;	/// Song Note FIFO
 std::deque<Note*> m_midiNoteQueue;	///< Midi Note FIFO

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to