Skip to content

Commit b8df156

Browse files
committedAug 5, 2018
1. Add an update button to the menu for updating the MIDI device list (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
1 parent 419cd94 commit b8df156

File tree

3 files changed

+91
-36
lines changed

3 files changed

+91
-36
lines changed
 

‎MidiPlugin.Rules/DeviceInformation.cs

+68-34
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,75 @@ public void Stop()
4242
d.Stop();
4343
}
4444
}
45+
46+
private void DeviceAdd()
47+
{
48+
this.InputDevices = new BindingList<MidiInput>();
49+
this.OutputDevices = new BindingList<MidiOutput>();
50+
51+
for (int i = 0; i < MidiIn.NumberOfDevices; i++)
52+
{
53+
try
54+
{
55+
this.InputDevices.Add(new MidiInput(i));
56+
}
57+
catch (Exception e)
58+
{
59+
DeviceInformation.log.Warn("Error initializing Midi-In Device", e, new object[0]);
60+
}
61+
}
62+
for (int i = 0; i < MidiOut.NumberOfDevices; i++)
63+
{
64+
try
65+
{
66+
this.OutputDevices.Add(new MidiOutput(i));
67+
}
68+
catch (Exception e)
69+
{
70+
DeviceInformation.log.Warn("Error initializing Midi-Out Device", e, new object[0]);
71+
}
72+
}
73+
}
74+
75+
private void DeviceDispose()
76+
{
77+
foreach (MidiInput item in this.InputDevices)
78+
{
79+
try
80+
{
81+
item.Dispose();
82+
}
83+
catch (Exception e)
84+
{
85+
DeviceInformation.log.Warn("Midi-In Device could not be disposed", e, new object[0]);
86+
}
87+
}
88+
foreach (MidiOutput item2 in this.OutputDevices)
89+
{
90+
try
91+
{
92+
item2.OutputDevice.Dispose();
93+
}
94+
catch (Exception e)
95+
{
96+
DeviceInformation.log.Warn("Midi-Out Device could not be disposed", e, new object[0]);
97+
}
98+
}
99+
100+
this.InputDevices = null;
101+
this.OutputDevices = null;
102+
}
103+
104+
public void DeviceUpdate()
105+
{
106+
this.DeviceDispose();
107+
this.DeviceAdd();
108+
}
109+
45110
public DeviceInformation()
46111
{
47112
ContextManager.DeviceInformation = this;
48-
this.InputDevices = new BindingList<MidiInput>();
49-
this.OutputDevices = new BindingList<MidiOutput>();
50-
for (int i = 0; i < MidiIn.NumberOfDevices; i++)
51-
{
52-
try
53-
{
54-
this.InputDevices.Add(new MidiInput(i));
55-
}
56-
catch (Exception e)
57-
{
58-
DeviceInformation.log.Warn("Error initializing Midi-In Device", e, new object[0]);
59-
}
60-
}
61-
for (int i = 0; i < MidiOut.NumberOfDevices; i++)
62-
{
63-
try
64-
{
65-
this.OutputDevices.Add(new MidiOutput(i));
66-
}
67-
catch (Exception e)
68-
{
69-
DeviceInformation.log.Warn("Error initializing Midi-Out Device", e, new object[0]);
70-
}
71-
}
113+
this.DeviceAdd();
72114
}
73115
public void Dispose()
74116
{
@@ -78,16 +120,8 @@ public void Dispose()
78120
if (!this.disposed)
79121
{
80122
this.disposed = true;
81-
foreach (MidiInput item in this.InputDevices)
82-
{
83-
item.Dispose();
84-
}
85-
foreach (MidiOutput item2 in this.OutputDevices)
86-
{
87-
item2.OutputDevice.Dispose();
88-
}
89-
this.InputDevices = null;
90-
this.OutputDevices = null;
123+
124+
this.DeviceDispose();
91125
}
92126
}
93127
finally

‎MidiPlugin.Rules/MidiForm.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class MidiForm : ToolWindow, IDisposable
2222
private ToolStripMenuItem toolsToolStripMenuItem;
2323
private ToolStripMenuItem exportRuleSetsToolStripMenuItem;
2424
private ToolStripMenuItem importRuleSetsToolStripMenuItem;
25-
private ToolStripMenuItem infoToolStripMenuItem;
25+
private ToolStripMenuItem updateDevicesToolStripMenuItem;
26+
private ToolStripMenuItem infoToolStripMenuItem;
2627
public MidiForm()
2728
{
2829
this.InitializeComponent();
@@ -140,6 +141,7 @@ private void InitializeComponent()
140141
this.devicesGrid = new System.Windows.Forms.DataGridView();
141142
this.rulesGrp = new System.Windows.Forms.GroupBox();
142143
this.rulesGrid = new System.Windows.Forms.DataGridView();
144+
this.updateDevicesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
143145
this.menuStrip1.SuspendLayout();
144146
this.splitContainer.Panel1.SuspendLayout();
145147
this.splitContainer.Panel2.SuspendLayout();
@@ -155,6 +157,7 @@ private void InitializeComponent()
155157
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
156158
this.addRuleSetToolStripMenuItem,
157159
this.deleteRuleSetToolStripMenuItem,
160+
this.updateDevicesToolStripMenuItem,
158161
this.infoToolStripMenuItem,
159162
this.toolsToolStripMenuItem});
160163
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
@@ -204,6 +207,13 @@ private void InitializeComponent()
204207
this.importRuleSetsToolStripMenuItem.Text = "Import RuleSets";
205208
this.importRuleSetsToolStripMenuItem.Click += new System.EventHandler(this.importRuleSetsToolStripMenuItem_Click);
206209
//
210+
// updateDevicesToolStripMenuItem
211+
//
212+
this.updateDevicesToolStripMenuItem.Name = "updateDevicesToolStripMenuItem";
213+
this.updateDevicesToolStripMenuItem.Size = new System.Drawing.Size(100, 20);
214+
this.updateDevicesToolStripMenuItem.Text = "Update Devices";
215+
this.updateDevicesToolStripMenuItem.Click += new System.EventHandler(this.updateDevicesToolStripMenuItem_Click);
216+
//
207217
// splitContainer
208218
//
209219
this.splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -286,6 +296,7 @@ private void InitializeComponent()
286296
this.menuStrip1.PerformLayout();
287297
this.splitContainer.Panel1.ResumeLayout(false);
288298
this.splitContainer.Panel2.ResumeLayout(false);
299+
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
289300
this.splitContainer.ResumeLayout(false);
290301
this.devicesGrp.ResumeLayout(false);
291302
((System.ComponentModel.ISupportInitialize)(this.devicesGrid)).EndInit();
@@ -310,5 +321,12 @@ private void importRuleSetsToolStripMenuItem_Click(object sender, EventArgs e)
310321
if (Import != null) Import(null, null);
311322
}
312323

313-
}
324+
private void updateDevicesToolStripMenuItem_Click(object sender, EventArgs e)
325+
{
326+
ContextManager.DeviceInformation.DeviceUpdate();
327+
this.devicesGrid.DataSource = typeof(System.Collections.Generic.List<MidiDev>);
328+
this.devicesGrid.DataSource = ContextManager.DeviceInformation.Devices;
329+
this.UpdateUi();
330+
}
331+
}
314332
}

‎MidiPlugin/MidiPlugin.cs

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ public override void connectionEstablished()
167167
{
168168
log.Debug("Connection established in MidiPlugin...");
169169

170+
if (ConnectionManager.getInstance().Connected)
171+
Load();
172+
170173
ewHelper.Establish();
171174
base.connectionEstablished();
172175
}

0 commit comments

Comments
 (0)