phillintheblank / tonfall

Automatically exported from code.google.com/p/tonfall
0 stars 0 forks source link

How to replay MIDI data? #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am trying out tonfall as possible replacement for a java player. In the 
online application, users can edit instrument notes and then play back.

I have successfully adapted the demo MidiPlayer to load midi data from the 
server (the editor data gets converted to MIDI by Perl).

The idea is to play multiple instruments simultaneously, but that is for later 
concern.

My current issue is that the data gets played, but I cannot get the player to 
play again after new data is received.

Function 'play' gets called after a loaded complete event:

public function play(midiData : ByteArray) : void {
    midiFormat = MidiFormat.decode(midiData);
    sequencer = new TimeEventContainerSequencer(midiFormat.toTimeEventContainer(1.0 / 96.0));
    sequencer.timeEventTarget = generator;
    engine.processors.push( sequencer );
    engine.processors.push( generator );
    engine.input = generator.signalOutput;
}

It seems that either sequence, engine, or generator do not get initialized. And 
because these are singletons I cannot re-create them.

Original issue reported on code.google.com by arthurclemens on 17 Apr 2011 at 8:39

GoogleCodeExporter commented 8 years ago
My solution so far is to add a method to Engine:

public function clearProcessors() : void
{
    _processors = new Vector.<Processor>();
}

and reset the engine every time I am preparing to play a new score:

const engine : Engine = Engine.getInstance();
engine.clearProcessors();
engine.barPosition = 0.0;

Original comment by arthurclemens on 1 Jun 2011 at 9:00