Mercurial > hg > jslab
changeset 2:74cc9e431818
Revert change to MidiSynth
author | samer |
---|---|
date | Fri, 05 Apr 2019 16:43:56 +0100 |
parents | 5df24c91468d |
children | 15b93db27c04 |
files | src/samer/midi/MidiSynth.java |
diffstat | 1 files changed, 29 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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; i<n; i++) { if (x[i]>0) { cc[chans[i]].noteOn(nnums[i]+offset.value,mapVelocity(x[i]));