Пример #1
0
void _AmControlTarget::Perform(const AmSong* song, const AmSelectionsI* selections)
{
	if (!song || !selections) return;
	const AmTrack*		track = song->Track(TrackWinProperties().OrderedTrackAt(0).TrackId());
	if (!track) return;
	AmFilterHolderI*	output = track->Filter(OUTPUT_PIPELINE);
	if (!output) return;
	AmEvent*	event = selections->AsPlaybackList(song);
	if (!event) return;

	AmNoteOn*	on = new AmNoteOn(64, 100, 0);
	if (!on) {
		event->DeleteChain();
		return;
	}
	on->SetNextFilter(output);
	event = on->MergeEvent(event);
	if (!event) return;
	AmEvent*	e = event;
	while ( e->NextEvent() ) e = e->NextEvent();
	if (e) on->SetEndTime( e->EndTime() );
	if (on->Duration() < PPQN / 8) on->SetEndTime( on->StartTime() + (PPQN / 8) );

	mPerformer.SetBPM(song->BPM() );
	mPerformer.Play(event);
}
Пример #2
0
void AmFilterTest1::TestBasic01()
{
	int i;
	
	printf("Making a vector.\n");
	vector<int, allocator<int> > myVect(2);
	myVect[0] = 1;
	
	printf("Making a map.\n");
	map< int, int, less<int>, allocator<int> > myMap;
	myMap[0] = 1;
	
	printf("Creating example filter object...\n");
	fflush(stdout);
	ArpExampleFilterAddon* exAddon = new ArpExampleFilterAddon;
	AmFilterHolder* exHolder = new AmFilterHolder;
	exHolder->SetFilter(exAddon->NewInstance(exHolder));
	
	printf("Creating BSynth filter object...\n");
	fflush(stdout);
#if 1
	AmConsumerFilterAddon* syAddon = new AmConsumerFilterAddon();
#else
	AmConsumerFilterAddon* syAddon = new AmConsumerFilterAddon("<midi port name>");
#endif
	/* NOTE:  The second consumer filter is not valid.  You need to
	 * supply the name of the midi port you want to use.
	 */
	AmFilterHolder* syHolder = new AmFilterHolder;
	syHolder->SetFilter(syAddon->NewInstance(syHolder));
	
	printf("Creating debug filter object...\n");
	fflush(stdout);
	ArpDebugFilterAddon* dbAddon = new ArpDebugFilterAddon(true);
	AmFilterHolder* dbHolder = new AmFilterHolder;
	dbHolder->SetFilter(dbAddon->NewInstance(dbHolder));
	
	printf("Attaching BSynth filter to example filter...\n");
	fflush(stdout);
	exHolder->AddSuccessor(syHolder);
	
	printf("Attaching debug filter to BSynth filter...\n");
	fflush(stdout);
	syHolder->AddSuccessor(dbHolder);
	
	printf("Creating a chain of NoteOn events...\n");
	fflush(stdout);
	AmEventI* evHead=NULL;
	AmEventI* evTail=NULL;
	for( i=1; i<=4; i++ ) {
		{
			AmProgramChange* ev = new AmProgramChange((i-1)*10,
																PPQN*4*i-((PPQN*3)/2));
			if( !evHead ) {
				evHead = ev;
			} else {
				evTail->AppendEvent(ev);
			}
			ev->SetNextFilter(exHolder);
			evTail = ev;
		}
		
		{
			AmNoteOn* ev = new AmNoteOn(60+5*i,100,PPQN*4*i);
			ev->SetRelVelocity(80);
			if( !evHead ) {
				evHead = ev;
			} else {
				evTail->AppendEvent(ev);
			}
			ev->SetNextFilter(exHolder);
			evTail = ev;
		}
		
		{
			AmTempoChange* ev = new AmTempoChange(120 + 40*i,PPQN*4*i);
			if( !evHead ) {
				evHead = ev;
			} else {
				evTail->AppendEvent(ev);
			}
			ev->SetNextFilter(exHolder);
			evTail = ev;
		}
	}
	
	printf("Initial Event Chain:\n");
	fflush(stdout);
	PrintEventChain(evHead);
	fflush(stdout);
	
	printf("Processing filters on event chain...\n");
	fflush(stdout);
	evHead = ArpExecFilters(evHead);
	
	printf("Final event chain:\n");
	fflush(stdout);
	PrintEventChain(evHead);
	fflush(stdout);
	
	printf("Performing the song!\n");
	fflush(stdout);
	{
		AmPerformer p;
		p.Start(evHead);
		// this is a bit of a hack to wait for it to finish;
		// it will be better when we flesh out the performer
		// interface to be able to send messages.
		do {
			snooze(1 * 1000000);	// wait for a sec
		} while( p.IsPlaying() );
	}
	fflush(stdout);
	
	printf("Placing the BSynth filter in its own list...\n");
	fflush(stdout);
	exHolder->RemoveSuccessor(syHolder);
	syHolder->RemoveSuccessor(dbHolder);
	
	printf("Creating a chain of sixteenth notes...\n");
	fflush(stdout);
	evHead = evTail = new AmProgramChange(B_KALIMBA, 0);
	evTail->SetNextFilter(syHolder);
	evTail->AppendEvent(new AmTempoChange(480, 0));
	evTail = evTail->TailEvent();
	evTail->SetNextFilter(syHolder);
	for( i=1; i<=4*4*4; i++ ) {
		{
			AmNoteOn* ev = new AmNoteOn(70+2*(i/(4*4)),100,PPQN*i/4);
			ev->SetDuration(PPQN/8);
			ev->SetRelVelocity(80);
			if( !evHead ) {
				evHead = ev;
			} else {
				evTail->AppendEvent(ev);
			}
			ev->SetNextFilter(syHolder);
			evTail = ev;
		}
	}
	
	printf("Performing the next song!\n");
	fflush(stdout);
	{
		AmPerformer p;
		p.Start(evHead);
		// this is a bit of a hack to wait for it to finish;
		// it will be better when we flesh out the performer
		// interface to be able to send messages.
		do {
			snooze(1 * 1000000);	// wait for a sec
		} while( p.IsPlaying() );
	}
	fflush(stdout);
	
	printf("Deleting filters -- WHICH FOR SOME REASON IS CRASHING, SO IT'S BEEN REMOVED.\n");
#if 0
	exHolder->Delete();
	exAddon->RemReference();
	syHolder->Delete();
	syAddon->RemReference();
	dbHolder->Delete();
	dbAddon->RemReference();
#endif	
	DoBigTest();
	
	printf("Repeating test...\n");
	fflush(stdout);
	
	DoBigTest();
}