public static void DispatchNote(int midiIndex, int volume, int channel, float duration, float delay = 0f, Action started = null, Action finished = null) { SetupDispatcher(); if (delay <= 0f) { MidiOut.NoteOn(midiIndex, volume, channel); if (singleton.ShortMessageEvent != null) { singleton.ShortMessageEvent(channel + CommandEnum.NoteOn.ToInt(), midiIndex, volume); } if (started != null) { started(); } } dispatchedNotes.Add( new MidiMessage() { midiIndex = midiIndex, channel = channel, volume = volume, duration = duration, delay = delay, played = delay <= 0f ? true : false, started = started, finished = finished } ); }
void OnMouseDown() { OnNoteOn(midiIndex, volume); if (midiOut && channel != ChannelEnum.None) { MidiOut.NoteOn(midiIndex, volume, (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 static void PlayBeat(int aBeat) { MidiOut.fireMidiOutEvents = false; if (aBeat == 1) { MidiOut.NoteOn((int)PercussionEnum.OpenHiHat, downBeatVolume, 9); } else { MidiOut.NoteOn((int)PercussionEnum.SideStick, upBeatVolume, 9); } MidiOut.fireMidiOutEvents = true; }
public void NotePlayMidi(int noteValue, int volume, int channel) { try { var random = Random.Range(.9f, 1.1f); if (currentSceneIndex == 1) { noteValue = noteValue + Helpers.PlayTranspose; } MidiOut.NoteOn(noteValue + 20, (int)(volume * random), channel); } catch (Exception e) { Debug.LogWarning("NotePlayMidi " + e); } }
void OnMouseDown() { MidiOut.NoteOn(midiIndex, 100, 0); }
public void OnMouseDown() { GetComponent <Rigidbody>().AddForce(new Vector3(0, impulseForce, 0), ForceMode.Impulse); Debug.Log("OnMouseDown midiIndex " + midiIndex); MidiOut.NoteOn(midiIndex, 127, 0); }
public void Play() { GetComponent <Rigidbody> ().AddForce(new Vector3(0, impulseForce, 0), ForceMode.Impulse); MidiOut.NoteOn(midiIndex, 127, 0); }
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 OnPointerDown(PointerEventData eventData) { MidiOut.NoteOn(note, accidental, octave, value, channel); }