use of de.mossgrabers.controller.osc.OSCConfiguration in project DrivenByMoss by git-moss.
the class MidiModule method parseMidi.
/**
* Parse virtual MIDI note commands.
*
* @param path The rest of the path
* @param value The value
* @throws MissingCommandException Could not find the sub-command
* @throws UnknownCommandException Unknown sub-command
* @throws IllegalParameterException Added an illegal parameter
*/
private void parseMidi(final LinkedList<String> path, final Object value) throws IllegalParameterException, UnknownCommandException, MissingCommandException {
final OSCConfiguration conf = this.surface.getConfiguration();
final String command = getSubCommand(path);
switch(command) {
case "velocity":
final int numValue = toInteger(value);
conf.setAccentEnabled(numValue > 0);
if (numValue > 0)
conf.setFixedAccentValue(numValue);
return;
case "noterepeat":
this.parseNoteRepeat(path, value);
return;
default:
// Fall through
break;
}
int midiChannel;
try {
midiChannel = Math.min(Math.max(0, Integer.parseInt(command) - 1), 15);
} catch (final NumberFormatException ex) {
throw new UnknownCommandException(command);
}
final String subCommand = getSubCommand(path);
final IMidiInput input = this.surface.getMidiInput();
final Scales scales = this.model.getScales();
switch(subCommand) {
case "note":
if (path.isEmpty()) {
final Object[] array = (Object[]) value;
final int note = ((Number) array[0]).intValue();
final int velocity = ((Number) array[1]).intValue();
this.sendNote(conf, midiChannel, input, note, velocity);
return;
}
final String n = getSubCommand(path);
switch(n) {
case "+":
if (isTrigger(value)) {
scales.incOctave();
this.updateNoteMatrix(scales);
}
break;
case "-":
if (isTrigger(value)) {
scales.decOctave();
this.updateNoteMatrix(scales);
}
break;
default:
this.sendNote(conf, midiChannel, input, Integer.parseInt(n), toInteger(value));
break;
}
break;
case "drum":
final String n2 = getSubCommand(path);
switch(n2) {
case "+":
if (isTrigger(value)) {
scales.incDrumOctave();
this.surface.getDisplay().notify(scales.getDrumRangeText());
}
break;
case "-":
if (isTrigger(value)) {
scales.decDrumOctave();
this.surface.getDisplay().notify(scales.getDrumRangeText());
}
break;
default:
final int note = Integer.parseInt(n2);
int numValue = toInteger(value);
if (numValue > 0)
numValue = conf.isAccentActive() ? conf.getFixedAccentValue() : numValue;
final int data0 = this.model.getScales().getDrumMatrix()[note];
if (data0 >= 0)
input.sendRawMidiEvent(0x90 + midiChannel, data0, numValue);
break;
}
break;
case "cc":
if (path.isEmpty()) {
this.host.println("Missing MIDI CC value.");
return;
}
final int cc = Integer.parseInt(path.removeFirst());
input.sendRawMidiEvent(0xB0 + midiChannel, cc, toInteger(value));
break;
case "aftertouch":
int numValue = toInteger(value);
if (numValue > 0)
numValue = conf.isAccentActive() ? conf.getFixedAccentValue() : numValue;
if (path.isEmpty()) {
input.sendRawMidiEvent(0xD0 + midiChannel, 0, numValue);
return;
}
final int note = Integer.parseInt(path.removeFirst());
input.sendRawMidiEvent(0xA0 + midiChannel, this.surface.getKeyTranslationTable()[note], numValue);
break;
case "pitchbend":
input.sendRawMidiEvent(0xE0 + midiChannel, 0, toInteger(value));
break;
default:
throw new UnknownCommandException(command);
}
}
Aggregations