# HG changeset patch # User samer # Date 1554479036 -3600 # Node ID 74cc9e431818f645bd7950325eb9135d50fbf3f4 # Parent 5df24c91468d683074cb48789bc3c5989ffda206 Revert change to MidiSynth diff -r 5df24c91468d -r 74cc9e431818 src/samer/midi/MidiSynth.java --- a/src/samer/midi/MidiSynth.java Fri Apr 05 16:26:00 2019 +0100 +++ b/src/samer/midi/MidiSynth.java Fri Apr 05 16:43:56 2019 +0100 @@ -36,6 +36,9 @@ public class MidiSynth extends Viewable implements Agent, Task, Saveable { + VVector in; + Synthesizer synthesizer=null; + protected int n; protected double [] x; protected int [] nnums; @@ -46,7 +49,7 @@ protected VInteger offset; protected VBoolean pedal; - public MidiSynth(VVector input, Synthesizer synth) + public MidiSynth(VVector input) { super("midisynth"); @@ -58,9 +61,9 @@ addAgent(new Saver(this)); Shell.pop(); - n = input.size(); - x = input.array(); - cc = synth.getChannels(); + in = input; + n = in.size(); + x = in.array(); nnums = new int[n]; chans = new int[n]; @@ -82,8 +85,26 @@ }; } - public void open() { } - public void close() { } + public void open() throws Exception { + if (synthesizer!=null) { Shell.print("already open"); return; } + if ((synthesizer = MidiSystem.getSynthesizer()) == null) { + throw new Exception("getSynthesizer() failed"); + } + Shell.print("opening synthesizer"); + synthesizer.open(); + + cc = synthesizer.getChannels(); + Shell.print("got synth and channel:"+synthesizer+cc); + } + + public void close() { + if (synthesizer != null) { + Shell.print("closing synthesiser"); + synthesizer.close(); + synthesizer = null; + } + } + public void dispose() { close(); factor.dispose(); @@ -102,6 +123,8 @@ public void stopping() {} public void run() { + if (synthesizer==null) return; + for (int i=0; i0) { cc[chans[i]].noteOn(nnums[i]+offset.value,mapVelocity(x[i]));