mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
refactoring of MIDI helper
This commit is contained in:
parent
dd041f0da9
commit
145e59ea2f
@ -96,12 +96,8 @@ public final class MIDIHelper {
|
||||
*/
|
||||
public MidiChannel getChannel(int num, String instrument) throws NodeException {
|
||||
Instrument instr = null;
|
||||
if (!instrument.isEmpty()) {
|
||||
if (!getSynthesizer().loadInstruments())
|
||||
throw new NodeException(Lang.get("err_midiInstrumentsNotAvailable"));
|
||||
|
||||
if (!instrument.isEmpty())
|
||||
instr = getInstrument(instrument);
|
||||
}
|
||||
|
||||
MidiChannel[] channels = getSynthesizer().getChannels();
|
||||
if (num >= channels.length) {
|
||||
@ -154,8 +150,6 @@ public final class MIDIHelper {
|
||||
|
||||
void close();
|
||||
|
||||
boolean loadInstruments();
|
||||
|
||||
Instrument[] getAvailableInstruments();
|
||||
|
||||
MidiChannel[] getChannels();
|
||||
@ -171,6 +165,13 @@ public final class MIDIHelper {
|
||||
@Override
|
||||
public void open() throws MidiUnavailableException {
|
||||
synthesizer.open();
|
||||
|
||||
Soundbank soundbank = synthesizer.getDefaultSoundbank();
|
||||
if (soundbank == null)
|
||||
throw new MidiUnavailableException();
|
||||
|
||||
if (!synthesizer.loadAllInstruments(soundbank))
|
||||
throw new MidiUnavailableException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -178,14 +179,6 @@ public final class MIDIHelper {
|
||||
synthesizer.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadInstruments() {
|
||||
Soundbank soundbank = synthesizer.getDefaultSoundbank();
|
||||
if (soundbank == null)
|
||||
return false;
|
||||
return synthesizer.loadAllInstruments(soundbank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instrument[] getAvailableInstruments() {
|
||||
return synthesizer.getAvailableInstruments();
|
||||
@ -199,18 +192,13 @@ public final class MIDIHelper {
|
||||
|
||||
private static final class SynthesizerMock implements SynthesizerInterface {
|
||||
@Override
|
||||
public void open() throws MidiUnavailableException {
|
||||
public void open() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadInstruments() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instrument[] getAvailableInstruments() {
|
||||
return new Instrument[0];
|
||||
|
Loading…
x
Reference in New Issue
Block a user