private void midiEffectsIn(object sender, MidiInMessageEventArgs e) { //if (e.MidiEvent != null) // if (true) // Console.WriteLine("Inpute message from " + e.MidiEvent.Channel + " Comand" + e.MidiEvent.CommandCode); if (e.MidiEvent.Channel == 1 && e.MidiEvent.CommandCode != MidiCommandCode.AutoSensing) { if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOn) { NoteOnEvent noEvent = (NoteOnEvent)e.MidiEvent; if (noEvent.NoteNumber <= 107 && noEvent.NoteNumber >= 36) { int button = Launchpad.getButtonNo(noEvent.NoteNumber); int red = noEvent.Velocity & 0x3; int green = noEvent.Velocity & 0x30; green = green >> 4; if (red == 0 && green == 0) { buttons[button].LED = Color.FromArgb(170, 170, 170); } else { buttons[button].LED = Color.FromArgb(red * 85, green * 85, 0); } } } if (e.MidiEvent.CommandCode == MidiCommandCode.NoteOff) { NoteEvent nEvent = (NoteEvent)e.MidiEvent; if (nEvent.NoteNumber <= 107 && nEvent.NoteNumber >= 36) { int button = Launchpad.getButtonNo(nEvent.NoteNumber); buttons[button].LED = Color.FromArgb(170, 170, 170); } } } }
public PadForm() { this.AutoSize = true; errorState = false; showlables = false; hlButtons = false; preset = new Preset(pCount: 8, bCount: 72); for (int i = 0; i < MidiIn.NumberOfDevices; i++) { if (MidiIn.DeviceInfo(i).ProductName == "Launchpad Emulator") { midiin = new MidiIn(i); break; } } for (int i = 0; i < MidiOut.NumberOfDevices; i++) { if (MidiOut.DeviceInfo(i).ProductName == "Launchpad Emulator") { launchpad = new Launchpad(i); break; } } if (midiin != null && launchpad != null) { midiin.Start(); midiin.MessageReceived += new EventHandler <MidiInMessageEventArgs>(midiEffectsIn); InitializeComponent(); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); buttons = new PadButton[72]; for (int i = 0, x = 36, y = 105; i < 64; i++, x += 62) { if (x == 36 + (62 * 8)) { x = 36; y += 60; } this.buttons[i] = new PadButton(i, rounded: false); this.buttons[i].Location = new System.Drawing.Point(x, y); this.buttons[i].Name = "centerButtons"; this.buttons[i].Size = new System.Drawing.Size(52, 52); this.buttons[i].TabIndex = 1; this.buttons[i].TabStop = false; this.buttons[i].ButtonClick += new EventHandler(onButtonClick); this.buttons[i].ButtonRelease += new EventHandler(onButtonRelease); this.buttons[i].KeyChanged += new KeyChangeEvent(onKeyChanged); this.buttons[i].ID = i; this.alphaTheme.Controls.Add(this.buttons[i]); } for (int i = 64, y = 105; i < 72; i++, y += 60) { this.buttons[i] = new PadButton(i, rounded: true); this.buttons[i].Location = new System.Drawing.Point(532, y); this.buttons[i].Name = "rightButtons"; this.buttons[i].Size = new System.Drawing.Size(52, 52); this.buttons[i].TabIndex = 1; this.buttons[i].TabStop = false; this.buttons[i].ButtonClick += new EventHandler(onButtonClick); this.buttons[i].ButtonRelease += new EventHandler(onButtonRelease); this.buttons[i].KeyChanged += new KeyChangeEvent(onKeyChanged); this.buttons[i].ID = i; this.alphaTheme.Controls.Add(this.buttons[i]); } this.KeyPreview = true; this.KeyDown += new KeyEventHandler(onKeyDown); this.KeyUp += new KeyEventHandler(onKeyUp); this.BackColor = PadButton.backColor; alphaTheme.CanDrag = true; } }
public PadForm() { this.AutoSize = true; errorState = false; showlables = false; hlButtons = false; preset = new Preset(pCount: 8,bCount: 72); for (int i = 0; i < MidiIn.NumberOfDevices; i++) { if (MidiIn.DeviceInfo(i).ProductName == "Launchpad Emulator") { midiin = new MidiIn(i); break; } } for (int i = 0; i < MidiOut.NumberOfDevices; i++) { if (MidiOut.DeviceInfo(i).ProductName == "Launchpad Emulator") { launchpad = new Launchpad(i); break; } } if (midiin != null && launchpad != null) { midiin.Start(); midiin.MessageReceived += new EventHandler<MidiInMessageEventArgs>(midiEffectsIn); InitializeComponent(); this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); buttons = new PadButton[72]; for (int i = 0, x = 36, y = 105; i < 64; i++, x += 62) { if (x == 36 + (62 * 8)) { x = 36; y += 60; } this.buttons[i] = new PadButton(i, rounded: false); this.buttons[i].Location = new System.Drawing.Point(x, y); this.buttons[i].Name = "centerButtons"; this.buttons[i].Size = new System.Drawing.Size(52, 52); this.buttons[i].TabIndex = 1; this.buttons[i].TabStop = false; this.buttons[i].ButtonClick += new EventHandler(onButtonClick); this.buttons[i].ButtonRelease += new EventHandler(onButtonRelease); this.buttons[i].KeyChanged += new KeyChangeEvent(onKeyChanged); this.buttons[i].ID = i; this.alphaTheme.Controls.Add(this.buttons[i]); } for (int i = 64, y = 105; i < 72; i++, y += 60) { this.buttons[i] = new PadButton(i, rounded: true); this.buttons[i].Location = new System.Drawing.Point(532, y); this.buttons[i].Name = "rightButtons"; this.buttons[i].Size = new System.Drawing.Size(52, 52); this.buttons[i].TabIndex = 1; this.buttons[i].TabStop = false; this.buttons[i].ButtonClick += new EventHandler(onButtonClick); this.buttons[i].ButtonRelease += new EventHandler(onButtonRelease); this.buttons[i].KeyChanged += new KeyChangeEvent(onKeyChanged); this.buttons[i].ID = i; this.alphaTheme.Controls.Add(this.buttons[i]); } this.KeyPreview = true; this.KeyDown += new KeyEventHandler(onKeyDown); this.KeyUp += new KeyEventHandler(onKeyUp); this.BackColor = PadButton.backColor; alphaTheme.CanDrag = true; } }