// Start is called before the first frame update void Start() { MidiLoader.MPTK_LogEvents = true; MidiLoader.MPTK_Load(); Debug.Log(MidiLoader.MPTK_MidiName); List <MPTKEvent> events = MidiLoader.MPTK_ReadMidiEvents(); foreach (MPTKEvent evt in events) { Debug.Log(evt); } }
// Start is called before the first frame update void Start() { instance = this; AudioListener.pause = true; //TODO - create public variable to load song in MidiLoader.MPTK_Load(); midiEvents = MidiLoader.MPTK_ReadMidiEvents(); getMidiEvent(midiEvents); secondPerBeat = 60f / bpm; //record the time of the song when it starts dspTimeSong = (float)AudioSettings.dspTime; foreach (MidiNotes note in midiNotes) { // Debug.Log(note.NoteValue); } }
// Update is called once per frame void Update() { if (once && midiFilePlayer.MPTK_MidiEvents != null && midiFileLoader.MPTK_ReadMidiEvents() != null) { once = false; Debug.LogError(midiFilePlayer.MPTK_MidiEvents.Count); // foreach(TrackMidiEvent note in midiFilePlayer.MPTK_MidiEvents){ // channelArray[note.Event.Channel]++; // } List <MPTKEvent> events = midiFileLoader.MPTK_ReadMidiEvents(); int[] vals = new int[140]; Debug.LogError(events); int[] channelCount = new int[16]; foreach (MPTKEvent evt in events) { if (evt.Command == MPTKCommand.NoteOn) { channelArray[evt.Channel] += evt.Value; channelCount[evt.Channel]++; } } for (int i = 0; i < channelArray.Length; i++) { if (channelCount[i] != 0) { channelArray[i] /= channelCount[i]; } } //System.Array.Sort(channelArray); //System.Array.Reverse(channelArray); string channels = ""; for (int i = 0; i < channelArray.Length; i++) { channels += $"channel {i}: {channelArray[i]}\n"; } Debug.LogError(channels); // for (int i = 0; i < vals.Length; i++) // { // if(vals[i] > 0) // Debug.LogError(vals[i]); // } int m = channelArray.Max(); PrimaryChannel = System.Array.IndexOf(channelArray, m); foreach (MPTKEvent evt in events) { if (evt.Command == MPTKCommand.NoteOn && evt.Channel == PrimaryChannel) { vals[evt.Value]++; } } string values = ""; for (int i = 0; i < vals.Length; i++) { values += $"value {i}: {vals[i]}\n"; } Debug.LogError(values); int minVal = 0; int maxVal = 140; for (int i = 0; i < vals.Length; i++) { if (vals[i] != 0) { minVal = i; break; } } for (int i = vals.Length - 1; i >= 0; i--) { if (vals[i] != 0) { maxVal = i; break; } } int range = maxVal - minVal; int count = 0; for (int i = minVal; i <= maxVal; i++) { count += vals[i]; } int rangePerButton = range / 4; int countPerButton = count / 4; Debug.LogError($"Count per Button {countPerButton}"); int CrossCount = 0; int TriangleCount = 0; int CircleCount = 0; int SquareCount = 0; CrossLower = minVal; for (int i = CrossLower; i < maxVal; i++) { CrossCount += vals[i]; if (CrossCount >= countPerButton) { CrossUpper = i; break; } } TriangleLower = CrossUpper + 1; for (int i = TriangleLower; i < maxVal; i++) { TriangleCount += vals[i]; if (TriangleCount >= countPerButton) { TriangleUpper = i; break; } } CircleLower = TriangleUpper + 1; for (int i = CircleLower; i < maxVal; i++) { CircleCount += vals[i]; if (CircleCount >= countPerButton) { CircleUpper = i; break; } } SquareLower = CircleUpper + 1; SquareUpper = 140; for (int i = SquareLower; i < maxVal; i++) { SquareCount += vals[i]; if (SquareCount >= countPerButton) { SquareUpper = i; break; } } // CrossUpper = minVal + rangePerButton; // TriangleLower = minVal + rangePerButton; // TriangleUpper = TriangleLower + rangePerButton; // CircleLower = TriangleUpper; // CircleUpper = CircleLower + rangePerButton; // SquareLower = CircleUpper; // SquareUpper = SquareLower + rangePerButton; // m = vals.Max(); // CrossValue = System.Array.IndexOf(vals, m); // vals[CrossValue] = 0; // m = vals.Max(); // CircleValue = System.Array.IndexOf(vals, m); // vals[CircleValue] = 0; // m = vals.Max(); // TriangleValue = System.Array.IndexOf(vals, m); // vals[TriangleValue] = 0; // m = vals.Max(); // SquareValue = System.Array.IndexOf(vals, m); // vals[SquareValue] = 0; Debug.LogError($"Primary channel: {PrimaryChannel}"); Debug.LogError($"CrossUpper : {CrossUpper}, CrossLower : {CrossLower}"); Debug.LogError($"TriangleUpper : {TriangleUpper}, TriangleLower : {TriangleLower}"); Debug.LogError($"SquareUpper : {SquareUpper}, SquareLower : {SquareLower}"); Debug.LogError($"CircleUpper : {CircleUpper}, CircleLower : {CircleLower}"); } }