156 lines
3.7 KiB
C++
156 lines
3.7 KiB
C++
#include "Soundwich.h"
|
|
#include <Windows.h>
|
|
#include <stdio.h>
|
|
|
|
/*
|
|
|
|
This sample app creates a synth that delays an event
|
|
|
|
In this case the synth is created by a script in code with no exported data required
|
|
The script can be used to create multiple instances of the synth and can optionally be saved to a file.
|
|
|
|
The script is the same format as is exported from the soundwich studio tool.
|
|
|
|
The synth has a module that delays an EventIn signal and fires an EventOut after the specified time (default is 2 seconds).
|
|
|
|
The test signals the EventIn and when the delayed EventOut is fired it retriggers the EventIn. this will loop for 10 seconds.
|
|
|
|
*/
|
|
|
|
using namespace Soundwich;
|
|
|
|
Engine* soundwich;
|
|
|
|
|
|
// A class to create and manage the event delay component graph, the class inherits from IEventOutCallback to receive EventOut callbacks
|
|
|
|
class EventDelay : public IEventOutCallback
|
|
{
|
|
public:
|
|
static void CreateScripts( )
|
|
{
|
|
// create a module script
|
|
|
|
//ModuleScript::Create( &_moduleScript );
|
|
|
|
//// add commands to create components
|
|
|
|
//_moduleScript->AddEventInComponent( "EventIn" );
|
|
//_moduleScript->AddTimerComponent( "Delay", 0.0f, 1.0f, 2.0f );
|
|
//_moduleScript->AddEventOutComponent( "EventOut" );
|
|
|
|
//// add commands to connect components
|
|
|
|
//_moduleScript->ConnectComponents( "EventConnection", "EventIn", "Out", "Delay", "Reset" );
|
|
//_moduleScript->ConnectComponents( "EventConnection", "EventIn", "Out", "Delay", "Start" );
|
|
//_moduleScript->ConnectComponents( "EventConnection", "Delay", "Elapsed", "EventOut", "In" );
|
|
|
|
//// register the module script
|
|
|
|
//soundwich->RegisterModuleScript( _moduleScript, "DelayScript" );
|
|
|
|
//// create a synth script
|
|
|
|
//SynthScript::Create( &_synthScript );
|
|
|
|
//// add the module script
|
|
|
|
//_synthScript->AddModule( "DelayScript", "Delay" );
|
|
|
|
//// register the synth script
|
|
|
|
//soundwich->RegisterSynthScript( _synthScript, "DelayScript" );
|
|
}
|
|
|
|
public:
|
|
EventDelay( )
|
|
{
|
|
printf( "Testing EventDelay\n" );
|
|
|
|
// create the synth
|
|
|
|
//soundwich->CreateSynth( _synthScript, "Demo", &_synth );
|
|
//soundwich->CreateSynthFromXmlFile( "Demo", &_synth, );
|
|
|
|
// get the module
|
|
|
|
// get the input and output components
|
|
|
|
soundwich->GetEventInComponent( _synth, "EventIn", &_in );
|
|
soundwich->GetEventOutComponent( _synth, "EventOut", &_out );
|
|
|
|
// register the event callback
|
|
|
|
soundwich->RegisterEventOutCallback( this, _out );
|
|
|
|
// activate the synth
|
|
|
|
soundwich->ActivateSynth( _synth );
|
|
|
|
// signal the event in
|
|
|
|
printf( "Signalling event input\n" );
|
|
|
|
soundwich->SetEventIn( _in );
|
|
}
|
|
|
|
~EventDelay( )
|
|
{
|
|
// unregister the event callback
|
|
|
|
soundwich->UnregisterEventOutCallback( this, _out );
|
|
|
|
// deactivate the synth
|
|
|
|
soundwich->DeactivateSynth( _synth );
|
|
|
|
// destroy the synth
|
|
|
|
soundwich->DestroySynth( _synth );
|
|
}
|
|
|
|
void OnEventOut( const EventOut* eventOut )
|
|
{
|
|
if( eventOut == _out )
|
|
{
|
|
printf( "Delayed event output signalled, signalling event input again\n" );
|
|
|
|
soundwich->SetEventIn( _in );
|
|
}
|
|
}
|
|
|
|
private:
|
|
Engine* _soundwich;
|
|
|
|
Synth* _synth;
|
|
|
|
EventIn* _in;
|
|
EventOut* _out;
|
|
};
|
|
|
|
void TestEventDelay( )
|
|
{
|
|
EventDelay::CreateScripts( );
|
|
|
|
EventDelay synth;
|
|
|
|
int32 count = 100;
|
|
|
|
while( count-- )
|
|
{
|
|
soundwich->Tick( );
|
|
|
|
Sleep( 100 );
|
|
}
|
|
};
|
|
|
|
int main( int32 argc, char* argv[ ] )
|
|
{
|
|
Engine::Create( &soundwich );
|
|
|
|
TestEventDelay( );
|
|
|
|
Engine::Destroy( soundwich );
|
|
|
|
system( "pause" );
|
|
}
|