void OnMouseUp() { OnNoteOff(midiIndex, 0); if (midiOut && channel != ChannelEnum.None) { MidiOut.NoteOff(midiIndex, (int)channel); } }
void Update() { for (int i = 0; i < dispatchedNotes.Count; i++) { MidiMessage m = dispatchedNotes [i]; if (!m.played) { m.delay -= Time.deltaTime; if (m.delay <= 0) { MidiOut.NoteOn(m.midiIndex, m.volume, m.channel); if (ShortMessageEvent != null) { ShortMessageEvent(m.channel + CommandEnum.NoteOn.ToInt(), m.midiIndex, m.volume); } m.played = true; if (m.started != null) { m.started(); } } } else { m.duration -= Time.deltaTime; } if (m.duration <= 0f) { MidiOut.NoteOff(m.midiIndex, m.channel); if (ShortMessageEvent != null) { ShortMessageEvent(m.channel + CommandEnum.NoteOff.ToInt(), m.midiIndex, 0); } if (m.finished != null) { m.finished(); } } } for (int i = dispatchedNotes.Count - 1; i >= 0; i--) { if (dispatchedNotes [i].duration <= 0f) { dispatchedNotes.RemoveAt(i); } } }
public void NoteStopMidi(int noteValue, int channel) { try { if (currentSceneIndex == 1) { noteValue = noteValue + Helpers.PlayTranspose; } MidiOut.NoteOff(noteValue + 20, channel); } catch (Exception e) { Debug.LogWarning("NoteStopMidi " + e); } }
private void OnTriggerExit2D(Collider2D other) { var noteName = other.name; var noteAnimation = other.GetComponent <NoteAnimation>(); if (noteAnimation != null) { var noteValue = noteAnimation.NoteIndex + Helpers.LearnTranspose; if (noteTrigger.dictChannel.ContainsKey(other.name)) { notePlayStop.NoteStopMidi(noteValue, noteTrigger.dictChannel[other.name]); //Debug.Log("stop " + noteValue + " on outputChannel " + dictChannel[other.name]); noteTrigger.dictChannel.Remove(other.name); } else { if (Helpers.PracticeMode == "Practice-Left-Hand" && noteName.Contains("L")) { return; } if (Helpers.PracticeMode == "Practice-Right-Hand" && noteName.Contains("R")) { return; } //MidiOut.AllSoundOff(); for (int i = 0; i < 16; i++) { if (MidiOut.channelCache[i].notes[noteValue + 20].on) { Debug.Log("Can not find any valid channel. Stop channel " + i + " for " + noteValue); MidiOut.NoteOff(noteValue + 20, i); } } } } }
void OnMouseUp() { MidiOut.NoteOff(midiIndex, 0); }
public void OnMouseUp() { MidiOut.NoteOff(midiIndex); }
public void Stop() { MidiOut.NoteOff(midiIndex); }
void PlayNoteSound(int noteValue, string touchPhase, int channel, float volume) { //Debug.Log("PlayNoteSound noteValue" + noteValue + " touchPhase " + touchPhase); noteValue = noteValue - 1; if (currentSceneIndex == 1) { noteValue = noteValue + Helpers.PlayTranspose; } noteValue = Mathf.Clamp(noteValue, 0, 87); //if (Helpers.NotesClip.Count < noteValue) //{ // Debug.Log(noteValue + " clips is not ready"); // return; //} //Debug.Log("noteValue " + noteValue); //var path = (noteValue + 20).ToString("D3"); //path = "BrightMp3/KEPSREC" + path + ".mp3"; //path = Helpers.StreamingAssetsPath(path); //Debug.Log("path " + path); if (touchPhase == "down") { //if (Helpers.KeysWhitesDict.ContainsKey(noteValue)) { MidiOut.NoteOn(noteValue + 20, 127, channel); //Debug.Log("MidiOut.NoteOn channel " + channel); return; } //else //{ // //Debug.Log("Create AudioSource"); // var audioSource = listAudioSource.FirstOrDefault(obj => // !listAudioSourceAboutToFade.Contains(obj) // && !listAudioSourceFading.Contains(obj)); // if (audioSource == null) // { // audioSource = gameObject.AddComponent<AudioSource>(); // audioSource.playOnAwake = false; // listAudioSource.Add(audioSource); // Debug.LogWarning("Create new AudioSource " + listAudioSource.Count); // } // else // { // //Debug.LogWarning("Use existing AudioSource " + listAudioSource.Count); // } // audioSource.clip = Helpers.NotesClip[noteValue]; // audioSource.volume = volume * Random.Range(.9f, 1.1f); // audioSource.Play(); // //Debug.Log("Play volume " + volume + " audioSource.volume " + audioSource.volume); // listAudioSourceAboutToFade.Add(audioSource); // //Debug.LogWarning("listAudioSourceAboutToFade.Add " + audioSource); //} } else { //if (Helpers.KeysWhitesDict.ContainsKey(noteValue)) { MidiOut.NoteOff(noteValue + 20, channel); //Debug.Log("MidiOut.NoteOff channel " + channel); return; } //else //{ // MidiOut.NoteOff(noteValue + 20); // var audioSource = listAudioSourceAboutToFade // .LastOrDefault(obj => // !listAudioSourceFading.Contains(obj) // && obj.clip == Helpers.NotesClip[noteValue]); // if (audioSource != null) // { // //Debug.Log("Found Source to Fade"); // listAudioSourceFading.Add(audioSource); // var coroutine = FadeSound(audioSource); // StartCoroutine(coroutine); // } // else // { // Debug.Log("No Source to Fade " + Helpers.NotesClip[noteValue]); // //foreach (var obj in listAudioSourceAboutToFade) // //{ // // Debug.LogWarning(obj.clip.ToString()); // //} // } //} } }
public void OnPointerUp(PointerEventData eventData) { MidiOut.NoteOff(note, accidental, octave, channel); }