std::vector<AudioChannel*> getAudioEvents( std::vector<AudioChannel*> channels, int bufferPosition, int bufferEnd, bool addLiveInstruments ) { // clear previous channel contents (note we don't delete the channels anywhere as we re-use them) channels.clear(); int i, l; // note we update the channels mix properties here as they might change during playback for ( i = 0, l = instruments.size(); i < l; ++i ) { BaseInstrument* instrument = instruments.at( i ); AudioChannel* instrumentChannel = instrument->audioChannel; instrumentChannel->reset(); instrumentChannel->mixVolume = instrument->volume; if ( !instrumentChannel->muted ) { if ( AudioEngine::playing ) collectSequencedEvents( instrument, bufferPosition, bufferEnd ); if ( addLiveInstruments && instrument->hasLiveEvents() ) collectLiveEvents( instrument ); channels.push_back( instrumentChannel ); } } return channels; }
bool Sequencer::getAudioEvents( std::vector<AudioChannel*>* channels, int bufferPosition, int bufferSize, bool addLiveInstruments, bool flushChannels ) { channels->clear(); int bufferEnd = bufferPosition + ( bufferSize - 1 ); // the highest SampleEnd value we'll query bool loopStarted = bufferEnd > AudioEngine::max_buffer_position; // whether this request exceeds the min_buffer_position - max_buffer_position range int i, l; // note we update the channels mix properties here as they might change during playback for ( i = 0, l = ( int ) instruments.size(); i < l; ++i ) { BaseInstrument* instrument = instruments.at( i ); AudioChannel* instrumentChannel = instrument->audioChannel; // clear previous channel contents when requested if ( flushChannels ) instrumentChannel->reset(); if ( !instrumentChannel->muted ) { if ( playing ) collectSequencedEvents( instrument, bufferPosition, bufferEnd ); if ( addLiveInstruments && instrument->hasLiveEvents() ) collectLiveEvents( instrument ); channels->push_back( instrumentChannel ); } } return loopStarted; }
TEST( BaseAudioEvent, AddRemoveSequencer ) { BaseInstrument* instrument = new BaseInstrument(); BaseAudioEvent* audioEvent = new BaseAudioEvent( instrument ); // expect AudioEvent not be in any of the event queues of the instrument after construction bool found = false; for ( int i = 0; i < instrument->getEvents()->size(); ++i ) { if ( instrument->getEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected event not to be present in the event list after construction"; found = false; for ( int i = 0; i < instrument->getLiveEvents()->size(); ++i ) { if ( instrument->getLiveEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected event not to be present in the live event list after construction"; // 1. add the event to the sequencer audioEvent->addToSequencer(); // expect AudioEvent to be in the sequenced event list, not the live list found = false; for ( int i = 0; i < instrument->getEvents()->size(); ++i ) { if ( instrument->getEvents()->at( i ) == audioEvent ) found = true; } ASSERT_TRUE( found ) << "expected event to be present in the event list after addition"; found = false; for ( int i = 0; i < instrument->getLiveEvents()->size(); ++i ) { if ( instrument->getLiveEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected event not to be present in the live event list after addition"; // 2. remove the event from the sequencer audioEvent->removeFromSequencer(); // expect AudioEvent not to be in the sequenced event list anymore found = false; for ( int i = 0; i < instrument->getEvents()->size(); ++i ) { if ( instrument->getEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected event not to be present in the event list after removal"; // 3. add live event to the sequencer audioEvent->isSequenced = false; audioEvent->addToSequencer(); // expect AudioEvent to be in the live event list, not the sequenced list found = false; for ( int i = 0; i < instrument->getEvents()->size(); ++i ) { if ( instrument->getEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected live event not to be present in the sequenced event list after addition"; found = false; for ( int i = 0; i < instrument->getLiveEvents()->size(); ++i ) { if ( instrument->getLiveEvents()->at( i ) == audioEvent ) found = true; } ASSERT_TRUE( found ) << "expected live event to be present in the live event list after addition"; // 4. remove live event from sequencer audioEvent->removeFromSequencer(); // expect AudioEvent not be in any of the event queues of the instrument after removal found = false; for ( int i = 0; i < instrument->getEvents()->size(); ++i ) { if ( instrument->getEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected event not to be present in the event list after removal"; found = false; for ( int i = 0; i < instrument->getLiveEvents()->size(); ++i ) { if ( instrument->getLiveEvents()->at( i ) == audioEvent ) found = true; } ASSERT_FALSE( found ) << "expected event not to be present in the live event list after removal"; delete audioEvent; delete instrument; }