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