void BindMIDIKey(MidiJack.MidiChannel chan, int note, float velocity) { var newNote = new MIDINote(chan, note); noteToValue[newNote] = velocity; // Create ports here }
MIDINote ParseNoteOffEvent(FileStream inFile, MIDIEvent midi_event) { MIDINote note; if (inFile != null) { note = new MIDINote(midi_event); note.note = (UInt32)inFile.ReadByte(); note.velocity = (UInt32)inFile.ReadByte(); } else { note = (MIDINote)midi_event; } if (this.currentNotes.ContainsKey(note.note)) { this.currentNotes[note.note].duration = CurrentTime() - note.absoluteStartTime; this.currentNotes.Remove(note.note); } else { Debug.LogWarning("try to access not existing note: " + note.note); } return(note); }
static Audio() { Events.Audio.CustomMusicChanged.Subscribe(data => { CustomMusicChanged?.Invoke(default(object), new CustomMusicChangedEventArgs(data.newTrackName_)); }); Events.Audio.MIDIEvent.Subscribe(data => { MIDINote?.Invoke(default(object), new MIDINoteEventArgs(data.note_, data.velocity_)); }); Events.Audio.MusicBeatEvent.Subscribe(data => { MusicBeat?.Invoke(default(object), System.EventArgs.Empty); }); Events.Audio.MusicGridEvent.Subscribe(data => { MusicGridProgress?.Invoke(default(object), new MusicGridEventArgs(data.barCount_, data.beatCount_)); }); Events.Audio.MusicSegmentEnd.Subscribe(data => { MusicSegmentEnded?.Invoke(default(object), System.EventArgs.Empty); }); }
public void NoteOn(MIDINote n) { this.n = n; eg.GateOpen(); eg2.GateOpen(); processing = true; oldT = t; }
private void ReceiveKeyUp(MidiChannel channel, int note) { var midiNote = new MIDINote(channel, note); if (noteToValue.ContainsKey(midiNote)) { noteToValue[midiNote] = 0; } }
private void ReceiveKeyDown(MidiChannel channel, int note, float velocity) { var midiNote = new MIDINote(channel, note); if (noteToValue.ContainsKey(midiNote)) { noteToValue[midiNote] = velocity; } }
public void NoteOff(MIDINote n) { if (n.voice != null) { n.voice.NoteOff(); } else { Debug.LogError("Trying to turn off a note that was never assigned a voice - note with pitch index: " + n.pitchLetterIndex); } }
public void NoteOn(MIDINote n) { Voice v = GetNextVoice(); v.NoteOn(n); n.voice = v; if (currentActiveVoices < voiceCount) { currentActiveVoices++; } }
// Use this for initialization void Start() { midi = GetComponent <MIDI>(); midi.ReadMIDIFile(midiFilePath); int trackCount = midi.tracks.Count; if (generateOnlyFromFirstTrack) { trackCount = 1; } for (int i = 0; i < trackCount; i++) { MIDITrack track = midi.tracks[i]; foreach (MIDIEvent e in track.events) { Debug.Log("type of event" + e.GetType().ToString()); if (e.GetType() != typeof(MIDINote)) { continue; } MIDINote note = (MIDINote)e; GameObject platform; if (this.platforms.Length > 0) { int idx = Random.Range(0, this.platforms.Length); platform = GameObject.Instantiate(this.platforms[idx]) as GameObject; } else { platform = GameObject.CreatePrimitive(PrimitiveType.Cube); } Vector3 pos = new Vector3(note.absoluteStartTime, (float)note.note, 0.0f); platform.transform.position = pos; } } }
/// <summary> /// Add a note to the matrix at a specific location /// </summary> /// <param name="beat">location to store the note</param> /// <param name="n">the note to store</param> public void AddNote(byte positionIndex, MIDINote n) { int pitchIndex = n.pitchLetterIndex; //The first slot the note occupies must be set to active matrix[positionIndex, pitchIndex].Note = n; matrix[positionIndex, pitchIndex].active = true; //ensure all the slots that this note occupies are set to locked for (int i = positionIndex + 1; i < positionIndex + n.duration; i++) { if (i >= notesPerMeasure) { break; } matrix[i, pitchIndex].locked = true; matrix[i, pitchIndex].NoteGeo = matrix[positionIndex, pitchIndex].NoteGeo; matrix[i, pitchIndex].Note = n; } }
void OnGUI() { if (GUI.Button(new Rect(10, 70, 120, 30), "Play")) { AudioSource audioSrc = GetComponent <AudioSource>(); MIDITrack track = midi.tracks[0]; foreach (MIDIEvent e in track.events) { Debug.Log("type of event" + e.GetType().ToString()); if (e.GetType() != typeof(MIDINote)) { continue; } MIDINote note = (MIDINote)e; Debug.Log("note:" + note.note); audioSrc.clip = sampler.samples[note.note]; audioSrc.PlayScheduled((double)note.absoluteStartTime); } } }
MIDINote ParseNoteOnEvent(FileStream inFile, MIDIEvent midi_event) { MIDINote note = new MIDINote(midi_event); note.note = (UInt32)inFile.ReadByte(); note.velocity = (UInt32)inFile.ReadByte(); note.absoluteStartTime = CurrentTime(); Debug.Log(midi_event); if (note.velocity == 0) // note off { ParseNoteOffEvent(null, note); } else { if (!currentNotes.ContainsKey(note.note)) { currentNotes.Add(note.note, note); } } return(note); }
private void method_3(int instrumentType, int int_1, MIDINote midiNote, int int_2) { NoteEventInterpreter noteEvenInterpreter = null; switch (midiNote.getDifficulty()) { case Difficulty.Easy: switch (instrumentType) { case 0: noteEvenInterpreter = this.easySingle; break; case 1: noteEvenInterpreter = this.easyDoubleGuitar; break; case 3: noteEvenInterpreter = this.easyDoubleBass; break; } break; case Difficulty.Medium: switch (instrumentType) { case 0: noteEvenInterpreter = this.mediumSingle; break; case 1: noteEvenInterpreter = this.mediumDoubleGuitar; break; case 3: noteEvenInterpreter = this.mediumDoubleBass; break; } break; case Difficulty.Hard: switch (instrumentType) { case 0: noteEvenInterpreter = this.hardSingle; break; case 1: noteEvenInterpreter = this.hardDoubleGuitar; break; case 3: noteEvenInterpreter = this.hardDoubleBass; break; } break; case Difficulty.Expert: switch (instrumentType) { case 0: noteEvenInterpreter = this.expertSingle; break; case 1: noteEvenInterpreter = this.expertDoubleGuitar; break; case 3: noteEvenInterpreter = this.expertDoubleBass; break; } break; default: if (!this.bool_3 && midiNote.method_2() == MIDINoteMask.StarPower) { this.bool_3 = true; this.expertSingle.class228_1.Clear(); this.hardSingle.class228_1.Clear(); this.mediumSingle.class228_1.Clear(); this.easySingle.class228_1.Clear(); } else if (!this.bool_3) { return; } break; } if (midiNote.method_3() != Fret.Invalid) { if (noteEvenInterpreter.noteList.method_4(int_1)) { noteEvenInterpreter.noteList[int_1].noteValues[(int)midiNote.method_3()] = true; return; } bool[] array = new bool[32]; array[(int)midiNote.method_3()] = true; noteEvenInterpreter.noteList.Add(int_1, new NotesAtOffset(array, int_2)); return; } else { if (midiNote.method_2() == MIDINoteMask.StarPower && !this.expertSingle.class228_1.ContainsKey(int_1)) { this.expertSingle.class228_1.Add(int_1, int_2); this.hardSingle.class228_1.Add(int_1, int_2); this.mediumSingle.class228_1.Add(int_1, int_2); this.easySingle.class228_1.Add(int_1, int_2); return; } if (midiNote.method_2() == MIDINoteMask.Unk7 && !noteEvenInterpreter.class228_1.ContainsKey(int_1) && !this.bool_3) { noteEvenInterpreter.class228_1.Add(int_1, int_2); return; } if (midiNote.method_2() == MIDINoteMask.Unk9 && !noteEvenInterpreter.class228_2.ContainsKey(int_1)) { noteEvenInterpreter.class228_2.Add(int_1, int_2); return; } if (midiNote.method_2() == MIDINoteMask.Unk10 && !noteEvenInterpreter.class228_3.ContainsKey(int_1)) { noteEvenInterpreter.class228_3.Add(int_1, int_2); } return; } }
public void NoteOn(MIDINote n) { fm.NoteOn(n); }
public void NoteOff(MIDINote n) { fm.NoteOff(n); }
MIDINote ParseNoteOnEvent(FileStream inFile, MIDIEvent midi_event) { MIDINote note = new MIDINote(midi_event); note.note = (UInt32)inFile.ReadByte(); note.velocity = (UInt32)inFile.ReadByte(); note.absoluteStartTime = CurrentTime(); Debug.Log(midi_event); if(note.velocity == 0){ // note off ParseNoteOffEvent(null, note); }else{ if(!currentNotes.ContainsKey(note.note)){ currentNotes.Add(note.note, note); } } return note; }
MIDINote ParseNoteOffEvent(FileStream inFile, MIDIEvent midi_event) { MIDINote note; if(inFile != null){ note = new MIDINote(midi_event); note.note = (UInt32)inFile.ReadByte(); note.velocity = (UInt32)inFile.ReadByte(); }else{ note = (MIDINote)midi_event; } if(this.currentNotes.ContainsKey(note.note) ){ this.currentNotes[note.note].duration = CurrentTime() - note.absoluteStartTime; this.currentNotes.Remove(note.note); }else{ Debug.LogWarning("try to access not existing note: " + note.note); } return note; }
public override void NoteOff(MIDINote n) { //Debug.Log("Off: " + n.midi); voiceManager.NoteOff(n); }
public abstract void NoteOff(MIDINote n);
private void method_3(Stream midiStream) { BinaryReader midiFile = new BinaryReader(midiStream); ByteFiddler.smethod_3("MIDI", midiFile, "MThd"); ByteFiddler.RotateLeft(midiFile.ReadUInt32()); ByteFiddler.RotateRight(midiFile.ReadUInt16()); int num = (int)ByteFiddler.RotateRight(midiFile.ReadUInt16()); this.method_1((int)ByteFiddler.RotateRight(midiFile.ReadUInt16())); this.midiLineList.Clear(); for (int i = 0; i < num; i++) { MIDILine midiLine = new MIDILine(this.method_0()); this.midiLineList.Add(midiLine); List <AbstractNoteClass> list = new List <AbstractNoteClass>(); ByteFiddler.smethod_3("MIDI", midiFile, "MTrk"); uint num2 = ByteFiddler.RotateLeft(midiFile.ReadUInt32()); long position = midiFile.BaseStream.Position; int num3 = 0; byte b = 0; while (midiFile.BaseStream.Position < position + (long)((ulong)num2)) { int num4 = (int)this.method_4(midiFile); AbstractNoteClass midiNote = null; num3 += num4; byte b2 = midiFile.ReadByte(); if (b2 != 255) { byte int_; if ((b2 & 128) == 128) { int_ = midiFile.ReadByte(); b = b2; } else { int_ = b2; b2 = b; } byte b3 = (byte)(b2 >> 4); switch (b3) { case 8: midiNote = new MIDINote(num3, (int)int_, midiFile.ReadByte(), false); goto IL_298; case 9: midiNote = new MIDINote(num3, (int)int_, midiFile.ReadByte(), true); goto IL_298; case 11: case 12: case 14: goto IL_298; } throw new NotImplementedException(string.Format("Unhandled MIDI command: {0} at position {1}", b3.ToString("X"), midiFile.BaseStream.Position)); } byte b4 = midiFile.ReadByte(); long num5 = this.method_4(midiFile); byte[] array = midiFile.ReadBytes((int)num5); byte b5 = b4; if (b5 <= 47) { switch (b5) { case 1: midiNote = new zzNote1(num3, zzNote1.Enum37.const_0, Encoding.ASCII.GetString(array)); break; case 2: break; case 3: { string text = Encoding.ASCII.GetString(array).ToUpper(); if (!string.IsNullOrEmpty(text)) { midiLine.method_3(text); } break; } default: if (b5 != 47) { } break; } } else if (b5 != 81) { if (b5 == 88) { if (num5 != 4L) { Class355.interface15_0.imethod_1(string.Format("Expected time signature event to have data length of 4, but found instead {0}", num5)); } midiNote = new zzNote338(num3, (int)array[0], (int)array[1], (int)array[2], (int)array[3]); } } else { if (num5 != 3L) { Class355.interface15_0.imethod_1(string.Format("Expected tempo event to have data length of 3, but found instead {0}", num5)); } int num6 = (int)array[0] << 16; num6 |= (int)array[1] << 8; num6 |= (int)array[2]; midiNote = new BpmNote1(num3, num6); } IL_298: if (midiNote != null) { list.Add(midiNote); } } list.Sort(new Comparison <AbstractNoteClass>(AbstractNoteClass.smethod_0)); midiLine.method_1(list); midiFile.BaseStream.Seek(position + (long)((ulong)num2), SeekOrigin.Begin); } }
/// <summary> /// Send a NoteOff MIDI message with a given velocity /// Valid velocity: 0-127 /// </summary> public void SendNoteOff(MIDINote note, int velocity) { SendNoteOff((int)note, velocity); }
/// <summary> /// Send a NoteOff MIDI message /// </summary> public void SendNoteOff(MIDINote note) { SendNoteOff((int)note); }
private void getNotes(MIDILine midiLine, int difficulty) { bool[] array = new bool[midiLine.method_0().Count]; List <AbstractNoteClass> list = midiLine.method_0(); for (int i = 0; i < list.Count; i++) { if (!array[i]) { int num = Convert.ToInt32((double)list[i].method_0() * this.resolution); if (list[i] is MIDINote) { MIDINote midiNote = (MIDINote)list[i]; if (midiNote.method_5()) { int j = -1; int num2 = i + 1; while (j < 0) { if (num2 == midiLine.method_0().Count) { break; } if (list[num2] is MIDINote && ((MIDINote)list[num2]).method_4() == midiNote.method_4()) { if (((MIDINote)list[num2]).method_5()) { j = Convert.ToInt32((double)list[num2].method_0() * this.resolution); array[num2] = true; } else { j = Convert.ToInt32((double)list[num2].method_0() * this.resolution); } } num2++; } int num3 = Convert.ToInt32(j - num); if (num3 <= 160) { num3 = 0; } this.method_3(difficulty, num, midiNote, num3); } } else if (list[i] is zzNote1) { zzNote1 class2 = (zzNote1)list[i]; List <string> list2 = this.method_5(difficulty - 4); string text = class2.method_1(); if (text.StartsWith("[")) { text = text.Substring(1, text.Length - 2); } if (list2.Contains(text) || text.Contains("section ")) { this.method_4(difficulty, num, text); } } } } }