Skip to content

Commit

Permalink
Update MidiSynthesizer.setReceiver method
Browse files Browse the repository at this point in the history
  • Loading branch information
kshoji committed May 5, 2024
1 parent 64517f9 commit 22ca703
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void onMidiOutputDeviceAttached(@NonNull final MidiOutputDevice midiOutpu
try {
existingSynthesizer.setReceiver(addedDevice.getReceiver());
} catch (final MidiUnavailableException ignored) {
existingSynthesizer.setReceiver(null);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,7 @@ public BleMidiSynthesizer(final BleMidiDevice bleMidiDevice) {
} catch (final MidiUnavailableException ignored) {
}

if (receiver == null) {
// empty
channels = new MidiChannel[0];
voiceStatuses = new VoiceStatus[0];
} else {
// 16 channels
voiceStatuses = new VoiceStatus[16];
channels = new MidiChannel[16];
for (int channel = 0; channel < 16; channel++) {
voiceStatuses[channel] = new VoiceStatus();
channels[channel] = new MidiChannelImpl(channel, receiver, voiceStatuses[channel]);
}
}
setReceiver(receiver);
}

@NonNull
Expand Down Expand Up @@ -196,12 +184,18 @@ public List<Transmitter> getTransmitters() {
}

public void setReceiver(final Receiver receiver) {
// 16 channels
voiceStatuses = new VoiceStatus[16];
channels = new MidiChannel[16];
for (int channel = 0; channel < 16; channel++) {
voiceStatuses[channel] = new VoiceStatus();
channels[channel] = new MidiChannelImpl(channel, receiver, voiceStatuses[channel]);
if (receiver == null) {
// empty
channels = new MidiChannel[0];
voiceStatuses = new VoiceStatus[0];
} else {
// 16 channels
voiceStatuses = new VoiceStatus[16];
channels = new MidiChannel[16];
for (int channel = 0; channel < 16; channel++) {
voiceStatuses[channel] = new VoiceStatus();
channels[channel] = new MidiChannelImpl(channel, receiver, voiceStatuses[channel]);
}
}
}
}

0 comments on commit 22ca703

Please sign in to comment.