Skip to content

Commit

Permalink
1. Add an update button to the menu for updating the MIDI device list…
Browse files Browse the repository at this point in the history
… (Known issues: MIDI devices connected after the start of DMXControl 3 can not be found)

2. Fixed rule sets were not loaded, when connecting a GUI to an already running kernel
  • Loading branch information
jpk6789 committed Aug 5, 2018
1 parent 419cd94 commit b8df156
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 36 deletions.
102 changes: 68 additions & 34 deletions MidiPlugin.Rules/DeviceInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,75 @@ public void Stop()
d.Stop();
}
}

private void DeviceAdd()
{
this.InputDevices = new BindingList<MidiInput>();
this.OutputDevices = new BindingList<MidiOutput>();

for (int i = 0; i < MidiIn.NumberOfDevices; i++)
{
try
{
this.InputDevices.Add(new MidiInput(i));
}
catch (Exception e)
{
DeviceInformation.log.Warn("Error initializing Midi-In Device", e, new object[0]);
}
}
for (int i = 0; i < MidiOut.NumberOfDevices; i++)
{
try
{
this.OutputDevices.Add(new MidiOutput(i));
}
catch (Exception e)
{
DeviceInformation.log.Warn("Error initializing Midi-Out Device", e, new object[0]);
}
}
}

private void DeviceDispose()
{
foreach (MidiInput item in this.InputDevices)
{
try
{
item.Dispose();
}
catch (Exception e)
{
DeviceInformation.log.Warn("Midi-In Device could not be disposed", e, new object[0]);
}
}
foreach (MidiOutput item2 in this.OutputDevices)
{
try
{
item2.OutputDevice.Dispose();
}
catch (Exception e)
{
DeviceInformation.log.Warn("Midi-Out Device could not be disposed", e, new object[0]);
}
}

this.InputDevices = null;
this.OutputDevices = null;
}

public void DeviceUpdate()
{
this.DeviceDispose();
this.DeviceAdd();
}

public DeviceInformation()
{
ContextManager.DeviceInformation = this;
this.InputDevices = new BindingList<MidiInput>();
this.OutputDevices = new BindingList<MidiOutput>();
for (int i = 0; i < MidiIn.NumberOfDevices; i++)
{
try
{
this.InputDevices.Add(new MidiInput(i));
}
catch (Exception e)
{
DeviceInformation.log.Warn("Error initializing Midi-In Device", e, new object[0]);
}
}
for (int i = 0; i < MidiOut.NumberOfDevices; i++)
{
try
{
this.OutputDevices.Add(new MidiOutput(i));
}
catch (Exception e)
{
DeviceInformation.log.Warn("Error initializing Midi-Out Device", e, new object[0]);
}
}
this.DeviceAdd();
}
public void Dispose()
{
Expand All @@ -78,16 +120,8 @@ public void Dispose()
if (!this.disposed)
{
this.disposed = true;
foreach (MidiInput item in this.InputDevices)
{
item.Dispose();
}
foreach (MidiOutput item2 in this.OutputDevices)
{
item2.OutputDevice.Dispose();
}
this.InputDevices = null;
this.OutputDevices = null;

this.DeviceDispose();
}
}
finally
Expand Down
22 changes: 20 additions & 2 deletions MidiPlugin.Rules/MidiForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class MidiForm : ToolWindow, IDisposable
private ToolStripMenuItem toolsToolStripMenuItem;
private ToolStripMenuItem exportRuleSetsToolStripMenuItem;
private ToolStripMenuItem importRuleSetsToolStripMenuItem;
private ToolStripMenuItem infoToolStripMenuItem;
private ToolStripMenuItem updateDevicesToolStripMenuItem;
private ToolStripMenuItem infoToolStripMenuItem;
public MidiForm()
{
this.InitializeComponent();
Expand Down Expand Up @@ -140,6 +141,7 @@ private void InitializeComponent()
this.devicesGrid = new System.Windows.Forms.DataGridView();
this.rulesGrp = new System.Windows.Forms.GroupBox();
this.rulesGrid = new System.Windows.Forms.DataGridView();
this.updateDevicesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
this.splitContainer.Panel1.SuspendLayout();
this.splitContainer.Panel2.SuspendLayout();
Expand All @@ -155,6 +157,7 @@ private void InitializeComponent()
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.addRuleSetToolStripMenuItem,
this.deleteRuleSetToolStripMenuItem,
this.updateDevicesToolStripMenuItem,
this.infoToolStripMenuItem,
this.toolsToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
Expand Down Expand Up @@ -204,6 +207,13 @@ private void InitializeComponent()
this.importRuleSetsToolStripMenuItem.Text = "Import RuleSets";
this.importRuleSetsToolStripMenuItem.Click += new System.EventHandler(this.importRuleSetsToolStripMenuItem_Click);
//
// updateDevicesToolStripMenuItem
//
this.updateDevicesToolStripMenuItem.Name = "updateDevicesToolStripMenuItem";
this.updateDevicesToolStripMenuItem.Size = new System.Drawing.Size(100, 20);
this.updateDevicesToolStripMenuItem.Text = "Update Devices";
this.updateDevicesToolStripMenuItem.Click += new System.EventHandler(this.updateDevicesToolStripMenuItem_Click);
//
// splitContainer
//
this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
Expand Down Expand Up @@ -286,6 +296,7 @@ private void InitializeComponent()
this.menuStrip1.PerformLayout();
this.splitContainer.Panel1.ResumeLayout(false);
this.splitContainer.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
this.splitContainer.ResumeLayout(false);
this.devicesGrp.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.devicesGrid)).EndInit();
Expand All @@ -310,5 +321,12 @@ private void importRuleSetsToolStripMenuItem_Click(object sender, EventArgs e)
if (Import != null) Import(null, null);
}

}
private void updateDevicesToolStripMenuItem_Click(object sender, EventArgs e)
{
ContextManager.DeviceInformation.DeviceUpdate();
this.devicesGrid.DataSource = typeof(System.Collections.Generic.List<MidiDev>);
this.devicesGrid.DataSource = ContextManager.DeviceInformation.Devices;
this.UpdateUi();
}
}
}
3 changes: 3 additions & 0 deletions MidiPlugin/MidiPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public override void connectionEstablished()
{
log.Debug("Connection established in MidiPlugin...");

if (ConnectionManager.getInstance().Connected)
Load();

ewHelper.Establish();
base.connectionEstablished();
}
Expand Down

0 comments on commit b8df156

Please sign in to comment.