void KeyUp(int aMidiIdx) { if (aMidiIdx >= 0 && aMidiIdx < byte.MaxValue / 2) { SendShortMessage(CommandEnum.NoteOff, aMidiIdx, MidiConversion.GetMidiVolume(MIDISettings.instance.keyboardSettings.customVolume)); } }
void Awake() { rb = GetComponent <Rigidbody2D> (); MidiOut.ShortMessageEvent += (aCommnad, aData1, aData2) => { if (aCommnad.ToMidiCommand() == 144 && aData1 == midiIndex) { rb.AddRelativeForce(new Vector2(0f, aData2 * yForceMultp)); if (!particlesObject) { particlesObject = Instantiate(PREFAB_Particles, transform.position, Quaternion.identity) as GameObject; particlesObject.transform.SetParent(transform); particlesObjectPS = particlesObject.GetComponent <ParticleSystem> (); mainModule = particlesObjectPS.main; mainModule.startColor = aData1.ToMidiColor(); } else { var emission = particlesObjectPS.emission; emission.enabled = true; } if (!textObject) { textObject = Instantiate(PREFAB_Text, new Vector3(transform.position.x, 0, 0), Quaternion.identity) as GameObject; textObjectTM = textObject.GetComponent <TextMesh> (); textObjectTM.text = MidiConversion.GetToneNameFromMidiIndex(midiIndex); textObjectTM.color = aData1.ToMidiColor(); } else { textObject.SetActive(true); } //Debug.Log (MidiConversion.GetToneNameFromMidiIndex (midiIndex)); } if ((aCommnad.ToMidiCommand() == 128 && aData1 == midiIndex) || (aCommnad.ToMidiCommand() == 144 && aData1 == midiIndex && aData2 == 0)) { if (particlesObjectPS) { var emission = particlesObjectPS.emission; emission.enabled = false; } if (textObject) { textObject.SetActive(false); } } }; }
public void ProcessMidiMessage(MidiMessage midiMessage) { if (midiMessage.dataSize == 3 && midiMessage.command != 0xF0) { if (midiMessage.command.ToMidiCommand() == 0x90 && midiMessage.data2 == 0) { midiMessage.command = (byte)(midiMessage.command.ToMidiChannel() + 0x80); } volume = 0; if (MIDISettings.instance.inputSettings.useCustomVolume) { volume = MidiConversion.GetMidiVolume(MIDISettings.instance.inputSettings.customVolume); } else { volume = (int)Mathf.Clamp(MIDISettings.instance.inputSettings.multiplyVolume * midiMessage.data2, 0, 127); } command = 0; if (MIDISettings.instance.inputSettings.midiChannel == ChannelEnum.None) { command = midiMessage.command; } else { command = (int)MIDISettings.instance.inputSettings.midiChannel + midiMessage.command.ToMidiCommand(); } if (MIDISettings.instance.inputSettings.midiOut) { MidiOut.SendShortMessage(command, midiMessage.data1, volume, MIDISettings.instance.inputSettings.midiThrough); } if (ShortMessageEvent != null) { ShortMessageEvent(command, midiMessage.data1, volume); } } else { // SYS EX MESSAGE // if (midiMessage.command == 0xF0) { if (SysExMessageEvent != null) { SysExMessageEvent(midiMessage); } } } }
public void MuteTones() { int startIndex = MIDISettings.instance.keyboardSettings.keyboardOctave * 12; MidiOut.fireMidiOutEvents = false; for (int i = startIndex; i < startIndex + 13; i++) { if (i >= 0 && i < byte.MaxValue / 2) { SendShortMessage(CommandEnum.NoteOff, i, MidiConversion.GetMidiVolume(MIDISettings.instance.keyboardSettings.customVolume)); } } MidiOut.fireMidiOutEvents = true; }
public void SendShortMessage(int aCommand, int aData1, int aData2) { if (ShortMessageEvent != null) { ShortMessageEvent( MIDISettings.instance.playmakerSettings.midiChannel == ChannelEnum.None ? aCommand : (aCommand | (int)MIDISettings.instance.playmakerSettings.midiChannel), aData1, MIDISettings.instance.playmakerSettings.useCustomVolume ? MidiConversion.GetByteVolume(MIDISettings.instance.playmakerSettings.customVolume, aData2) : aData2 ); } if (MIDISettings.instance.playmakerSettings.midiOut) { MidiOut.SendShortMessage( MIDISettings.instance.playmakerSettings.midiChannel == ChannelEnum.None ? aCommand : (aCommand | (int)MIDISettings.instance.playmakerSettings.midiChannel), aData1, MIDISettings.instance.playmakerSettings.useCustomVolume ? MidiConversion.GetByteVolume(MIDISettings.instance.playmakerSettings.customVolume, aData2) : aData2 ); } }
public static Color ToMidiColor(this int i) { return(MidiConversion.GetToneColorFromMidiIndex(i)); }
public static byte BaseMidiIndex(this byte i) { return((byte)MidiConversion.BaseMidiIndex(i)); }
public static int BaseMidiIndex(this int i) { return(MidiConversion.BaseMidiIndex(i)); }