-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstrumentDialog.cs
86 lines (72 loc) · 2.17 KB
/
InstrumentDialog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using MidiChord;
using System;
using System.Threading;
using System.Windows.Forms;
namespace Sanford.Multimedia.Midi.UI
{
public partial class InstrumentDialog : Form
{
private ChordLivePlayer _midiPlayer;
public InstrumentDialog(ChordLivePlayer midiPlayer)
{
InitializeComponent();
FillInstrumentComboBox();
instrumentComboBox.SelectedIndex = 0;
_midiPlayer = midiPlayer;
}
private void FillInstrumentComboBox()
{
instrumentComboBox.Items.Clear();
foreach (GeneralMidiInstrument instrument in Enum.GetValues(typeof(GeneralMidiInstrument)))
{
instrumentComboBox.Items.Add(instrument.ToString());
}
}
public GeneralMidiInstrument Instrument
{
get
{
#region Require
if (instrumentComboBox.SelectedIndex < 0)
{
throw new InvalidOperationException();
}
#endregion
return (GeneralMidiInstrument)instrumentComboBox.SelectedIndex;
}
set
{
instrumentComboBox.SelectedIndex = (int)value;
}
}
private void buttonPreviewSound_Click(object sender, EventArgs e)
{
PreviewInstrument();
}
private void PreviewInstrument()
{
if (_midiPlayer != null)
{
_midiPlayer.Mute();
}
var i = instrumentComboBox.Text;
foreach (GeneralMidiInstrument instrument in Enum.GetValues(typeof(GeneralMidiInstrument)))
{
if (instrument.ToString() == i)
{
if (_midiPlayer != null)
{
_midiPlayer.PlayNote(instrument);
}
}
}
}
private void InstrumentDialog_FormClosing(object sender, FormClosingEventArgs e)
{
if (_midiPlayer != null)
{
_midiPlayer.Mute();
}
}
}
}