private void Form2_Load(object sender, EventArgs e) { int deviceCount = InputDevice.GetDevicesCount(); string deviceCountString = deviceCount.ToString(); textBox1.Text = deviceCountString; //Console.WriteLine(deviceString); //seems to crash when highlight textbox using (var inputDevice = InputDevice.GetById(0)) { inputDevice.EventReceived += OnEventReceived; inputDevice.StartEventsListening(); textBox2.Text = inputDevice.Name; int midiIDINT = inputDevice.Id; string midiIDString = midiIDINT.ToString(); midiID.Text = midiIDString; } }
public void Setup(SyncObject syncObject) { if (syncObject.OriginalNodeId != syncObject.Node.NodeId) { Logger.Log("MidiInputTag", "midiInput tag only works on the original node"); return; } if (InputDevice.GetDevicesCount() == 0) { Logger.Error("MidiInputTag", "MIDI input device not found"); return; } device = InputDevice.GetById(0); // Open the first device device.StartEventsListening(); device.EventReceived += OnEventReceived; syncObject.BeforeSync += OnBeforeSync; // Add update function }
private void InitOrRefreshDevicesList() { this.SuspendLayout(); if (InputDevice.GetDevicesCount() != nbInputDevices) { nbInputDevices = InputDevice.GetDevicesCount(); InputDevicesComboBox.Items.Clear(); InputDevicesComboBox.Items.Add("Choose midi input source"); InputDevicesComboBox.Items.Add("Midi events from network"); InputDevice.GetAll().ToList().ForEach(inputDevice => InputDevicesComboBox.Items.Add(inputDevice.Name)); if (inputDeviceName != null && InputDevicesComboBox.Items.Contains(inputDeviceName)) { InputDevicesComboBox.SelectedItem = inputDeviceName; } else { InputDevicesComboBox.SelectedIndex = 0; } } if (OutputDevice.GetDevicesCount() != nbOutputDevices) { nbOutputDevices = OutputDevice.GetDevicesCount(); OutputDevicesComboBox.Items.Clear(); OutputDevicesComboBox.Items.Add("Choose midi output destination"); OutputDevicesComboBox.Items.Add("Midi events to network"); OutputDevice.GetAll().ToList().ForEach(outputDevice => OutputDevicesComboBox.Items.Add(outputDevice.Name)); if (outputDeviceName != null && OutputDevicesComboBox.Items.Contains(outputDeviceName)) { OutputDevicesComboBox.SelectedItem = outputDeviceName; } else { OutputDevicesComboBox.SelectedIndex = 0; } } this.ResumeLayout(); }
private static void DrawDebugWindow() { //ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(5, 0)); if (ImGui.Begin("MIDIBARD DEBUG", ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.AlwaysAutoResize)) { try { ImGui.TextUnformatted($"AgentModule: {AgentManager.AgentModule.ToInt64():X}"); ImGui.SameLine(); if (ImGui.SmallButton("C##AgentModule")) ImGui.SetClipboardText($"{AgentManager.AgentModule.ToInt64():X}"); ImGui.TextUnformatted($"UiModule: {AgentManager.UiModule.ToInt64():X}"); ImGui.SameLine(); if (ImGui.SmallButton("C##4")) ImGui.SetClipboardText($"{AgentManager.UiModule.ToInt64():X}"); ImGui.TextUnformatted($"AgentCount:{AgentManager.Agents.Count}"); } catch (Exception e) { ImGui.TextUnformatted(e.ToString()); } ImGui.Separator(); try { ImGui.TextUnformatted($"AgentPerformance: {PerformanceAgent.Pointer.ToInt64():X}"); ImGui.SameLine(); if (ImGui.SmallButton("C##AgentPerformance")) ImGui.SetClipboardText($"{PerformanceAgent.Pointer.ToInt64():X}"); ImGui.TextUnformatted($"AgentID: {PerformanceAgent.Id}"); ImGui.TextUnformatted($"notePressed: {notePressed}"); ImGui.TextUnformatted($"noteNumber: {noteNumber}"); ImGui.TextUnformatted($"InPerformanceMode: {InPerformanceMode}"); ImGui.TextUnformatted($"Timer1: {TimeSpan.FromMilliseconds(PerformanceTimer1)}"); ImGui.TextUnformatted($"Timer2: {TimeSpan.FromTicks(PerformanceTimer2 * 10)}"); } catch (Exception e) { ImGui.TextUnformatted(e.ToString()); } ImGui.Separator(); try { ImGui.TextUnformatted($"AgentMetronome: {MetronomeAgent.Pointer.ToInt64():X}"); ImGui.SameLine(); if (ImGui.SmallButton("C##AgentMetronome")) ImGui.SetClipboardText($"{MetronomeAgent.Pointer.ToInt64():X}"); ImGui.TextUnformatted($"AgentID: {MetronomeAgent.Id}"); ImGui.TextUnformatted($"Running: {MetronomeRunning}"); ImGui.TextUnformatted($"Ensemble: {EnsembleModeRunning}"); ImGui.TextUnformatted($"BeatsElapsed: {MetronomeBeatsElapsed}"); ImGui.TextUnformatted($"PPQN: {MetronomePPQN} ({60_000_000 / (double)MetronomePPQN:F3}bpm)"); ImGui.TextUnformatted($"BeatsPerBar: {MetronomeBeatsperBar}"); ImGui.TextUnformatted($"Timer1: {TimeSpan.FromMilliseconds(MetronomeTimer1)}"); ImGui.TextUnformatted($"Timer2: {TimeSpan.FromTicks(MetronomeTimer2 * 10)}"); } catch (Exception e) { ImGui.TextUnformatted(e.ToString()); } ImGui.Separator(); try { ImGui.TextUnformatted($"PerformInfos: {PerformInfos.ToInt64() + 3:X}"); ImGui.SameLine(); if (ImGui.SmallButton("C##PerformInfos")) ImGui.SetClipboardText($"{PerformInfos.ToInt64() + 3:X}"); ImGui.TextUnformatted($"CurrentInstrumentKey: {CurrentInstrument}"); ImGui.TextUnformatted($"Instrument: {InstrumentSheet.GetRow(CurrentInstrument).Instrument}"); ImGui.TextUnformatted($"Name: {InstrumentSheet.GetRow(CurrentInstrument).Name.RawString}"); ImGui.TextUnformatted($"Tone: {CurrentGroupTone}"); //ImGui.Text($"unkFloat: {UnkFloat}"); ////ImGui.Text($"unkByte: {UnkByte1}"); } catch (Exception e) { ImGui.TextUnformatted(e.ToString()); } ImGui.Separator(); ImGui.TextUnformatted($"currentPlaying: {PlaylistManager.CurrentPlaying}"); ImGui.TextUnformatted($"currentSelected: {PlaylistManager.CurrentSelected}"); ImGui.TextUnformatted($"FilelistCount: {PlaylistManager.Filelist.Count}"); ImGui.TextUnformatted($"currentUILanguage: {pluginInterface.UiLanguage}"); ImGui.Separator(); try { //var devicesList = DeviceManager.Devices.Select(i => i.ToDeviceString()).ToArray(); //var inputDevices = DeviceManager.Devices; ////ImGui.BeginListBox("##auofhiao", new Vector2(-1, ImGui.GetTextLineHeightWithSpacing()* (inputDevices.Length + 1))); //if (ImGui.BeginCombo("Input Device", DeviceManager.CurrentInputDevice.ToDeviceString())) //{ // if (ImGui.Selectable("None##device", DeviceManager.CurrentInputDevice is null)) // { // DeviceManager.DisposeDevice(); // } // for (int i = 0; i < inputDevices.Length; i++) // { // var device = inputDevices[i]; // if (ImGui.Selectable($"{device.Name}##{i}", device.Id == DeviceManager.CurrentInputDevice?.Id)) // { // DeviceManager.SetDevice(device); // } // } // ImGui.EndCombo(); //} //ImGui.EndListBox(); //if (ImGui.ListBox("##????", ref InputDeviceID, devicesList, devicesList.Length)) //{ // if (InputDeviceID == 0) // { // DeviceManager.DisposeDevice(); // } // else // { // DeviceManager.SetDevice(InputDevice.GetByName(devicesList[InputDeviceID])); // } //} if (ImGui.SmallButton("Start Event Listening")) { DeviceManager.CurrentInputDevice?.StartEventsListening(); } ImGui.SameLine(); if (ImGui.SmallButton("Stop Event Listening")) { DeviceManager.CurrentInputDevice?.StopEventsListening(); } ImGui.TextUnformatted($"InputDevices: {InputDevice.GetDevicesCount()}\n{string.Join("\n", InputDevice.GetAll().Select(i => $"[{i.Id}] {i.Name}"))}"); ImGui.TextUnformatted($"OutputDevices: {OutputDevice.GetDevicesCount()}\n{string.Join("\n", OutputDevice.GetAll().Select(i => $"[{i.Id}] {i.Name}({i.DeviceType})"))}"); ImGui.TextUnformatted($"CurrentInputDevice: \n{DeviceManager.CurrentInputDevice} Listening: {DeviceManager.CurrentInputDevice?.IsListeningForEvents}"); ImGui.TextUnformatted($"CurrentOutputDevice: \n{CurrentOutputDevice}"); } catch (Exception e) { PluginLog.Error(e.ToString()); } #region Generator //ImGui.Separator(); //if (ImGui.BeginChild("Generate", new Vector2(size - 5, 150), false, ImGuiWindowFlags.NoDecoration)) //{ // ImGui.DragInt("length##keyboard", ref config.testLength, 0.05f); // ImGui.DragInt("interval##keyboard", ref config.testInterval, 0.05f); // ImGui.DragInt("repeat##keyboard", ref config.testRepeat, 0.05f); // if (config.testLength < 0) // { // config.testLength = 0; // } // if (config.testInterval < 0) // { // config.testInterval = 0; // } // if (config.testRepeat < 0) // { // config.testRepeat = 0; // } // if (ImGui.Button("generate##keyboard")) // { // try // { // testplayback?.Dispose(); // } // catch (Exception e) // { // // // } // static Pattern GetSequence(int octave) // { // return new PatternBuilder() // .SetRootNote(Note.Get(NoteName.C, octave)) // .SetNoteLength(new MetricTimeSpan(0, 0, 0, config.testLength)) // .SetStep(new MetricTimeSpan(0, 0, 0, config.testInterval)) // .Note(Interval.Zero) // .StepForward() // .Note(Interval.One) // .StepForward() // .Note(Interval.Two) // .StepForward() // .Note(Interval.Three) // .StepForward() // .Note(Interval.Four) // .StepForward() // .Note(Interval.Five) // .StepForward() // .Note(Interval.Six) // .StepForward() // .Note(Interval.Seven) // .StepForward() // .Note(Interval.Eight) // .StepForward() // .Note(Interval.Nine) // .StepForward() // .Note(Interval.Ten) // .StepForward() // .Note(Interval.Eleven) // .StepForward().Build(); // } // static Pattern GetSequenceDown(int octave) // { // return new PatternBuilder() // .SetRootNote(Note.Get(NoteName.C, octave)) // .SetNoteLength(new MetricTimeSpan(0, 0, 0, config.testLength)) // .SetStep(new MetricTimeSpan(0, 0, 0, config.testInterval)) // .Note(Interval.Eleven) // .StepForward() // .Note(Interval.Ten) // .StepForward() // .Note(Interval.Nine) // .StepForward() // .Note(Interval.Eight) // .StepForward() // .Note(Interval.Seven) // .StepForward() // .Note(Interval.Six) // .StepForward() // .Note(Interval.Five) // .StepForward() // .Note(Interval.Four) // .StepForward() // .Note(Interval.Three) // .StepForward() // .Note(Interval.Two) // .StepForward() // .Note(Interval.One) // .StepForward() // .Note(Interval.Zero) // .StepForward() // .Build(); // } // Pattern pattern = new PatternBuilder() // .SetNoteLength(new MetricTimeSpan(0, 0, 0, config.testLength)) // .SetStep(new MetricTimeSpan(0, 0, 0, config.testInterval)) // .Pattern(GetSequence(3)) // .Pattern(GetSequence(4)) // .Pattern(GetSequence(5)) // .SetRootNote(Note.Get(NoteName.C, 5)) // .StepForward() // .Note(Interval.Twelve) // .Pattern(GetSequenceDown(5)) // .Pattern(GetSequenceDown(4)) // .Pattern(GetSequenceDown(3)) // // Get pattern // .Build(); // var repeat = new PatternBuilder().Pattern(pattern).Repeat(config.testRepeat).Build(); // testplayback = repeat.ToTrackChunk(TempoMap.Default).GetPlayback(TempoMap.Default, Plugin.CurrentOutputDevice, // new MidiClockSettings() { CreateTickGeneratorCallback = () => new HighPrecisionTickGenerator() }); // } // ImGui.SameLine(); // if (ImGui.Button("chord##keyboard")) // { // try // { // testplayback?.Dispose(); // } // catch (Exception e) // { // // // } // var pattern = new PatternBuilder() // //.SetRootNote(Note.Get(NoteName.C, 3)) // //C-G-Am-(G,Em,C/G)-F-(C,Em)-(F,Dm)-G // .SetOctave(Octave.Get(3)) // .SetStep(new MetricTimeSpan(0, 0, 0, config.testInterval)) // .Chord(Chord.GetByTriad(NoteName.C, ChordQuality.Major)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.G, ChordQuality.Major)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.A, ChordQuality.Minor)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.G, ChordQuality.Major)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.F, ChordQuality.Major)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.C, ChordQuality.Major)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.F, ChordQuality.Major)).Repeat(config.testRepeat) // .Chord(Chord.GetByTriad(NoteName.G, ChordQuality.Major)).Repeat(config.testRepeat) // .Build(); // testplayback = pattern.ToTrackChunk(TempoMap.Default).GetPlayback(TempoMap.Default, Plugin.CurrentOutputDevice, // new MidiClockSettings() { CreateTickGeneratorCallback = () => new HighPrecisionTickGenerator() }); // } // ImGui.Spacing(); // if (ImGui.Button("play##keyboard")) // { // try // { // testplayback?.MoveToStart(); // testplayback?.Start(); // } // catch (Exception e) // { // PluginLog.Error(e.ToString()); // } // } // ImGui.SameLine(); // if (ImGui.Button("dispose##keyboard")) // { // try // { // testplayback?.Dispose(); // } // catch (Exception e) // { // PluginLog.Error(e.ToString()); // } // } // try // { // ImGui.TextUnformatted($"{testplayback.GetDuration(TimeSpanType.Metric)}"); // } // catch (Exception e) // { // ImGui.TextUnformatted("null"); // } // //ImGui.SetNextItemWidth(120); // //UIcurrentInstrument = Plugin.CurrentInstrument; // //if (ImGui.ListBox("##instrumentSwitch", ref UIcurrentInstrument, InstrumentSheet.Select(i => i.Instrument.ToString()).ToArray(), (int)InstrumentSheet.RowCount, (int)InstrumentSheet.RowCount)) // //{ // // Task.Run(() => SwitchInstrument.SwitchTo((uint)UIcurrentInstrument)); // //} // //if (ImGui.Button("Quit")) // //{ // // Task.Run(() => SwitchInstrument.SwitchTo(0)); // //} // ImGui.EndChild(); //} #endregion ImGui.End(); } //ImGui.PopStyleVar(); }