private void ChannelMessageReceived( int deviceIndex, object sender, ChannelMessageEventArgs e ) { MidiCommand command; if (e.Message.Command == ChannelCommand.Controller) { double value = (double)e.Message.Data2 / 127; command = new MidiCommand() { deviceIndex = deviceIndex, type = MidiCommandType.Knob, index = e.Message.Data1, value = value, }; this.config.midiLog.Append( "MIDI message on " + MidiInput.GetDeviceName(deviceIndex) + " channel " + e.Message.MidiChannel + " updating knob #" + e.Message.Data1 + " to value " + value ); } else if ( e.Message.Command == ChannelCommand.NoteOn || e.Message.Command == ChannelCommand.NoteOff ) { double value = (double)e.Message.Data2 / 127; command = new MidiCommand() { deviceIndex = deviceIndex, type = MidiCommandType.Note, index = e.Message.Data1, value = value, }; var onOrOff = e.Message.Command == ChannelCommand.NoteOn ? "ON" : "OFF"; this.config.midiLog.Append( "MIDI message on " + MidiInput.GetDeviceName(deviceIndex) + " channel " + e.Message.MidiChannel + " updating note #" + e.Message.Data1 + " to " + onOrOff + " with value " + value ); } else if (e.Message.Command == ChannelCommand.ProgramChange) { command = new MidiCommand() { deviceIndex = deviceIndex, type = MidiCommandType.Program, index = e.Message.Data1, }; this.config.midiLog.Append( "MIDI message on " + MidiInput.GetDeviceName(deviceIndex) + " channel " + e.Message.MidiChannel + " updating program to #" + e.Message.Data1 ); } else { return; } this.buffer.Enqueue(command); List <Binding> triggered = new List <Binding>(); var genericKey = new InnerBindingKey(deviceIndex, command.type, -1); if (this.bindings.ContainsKey(genericKey)) { triggered.AddRange(this.bindings[genericKey]); } var key = new InnerBindingKey(deviceIndex, command.type, command.index); if (this.bindings.ContainsKey(key)) { triggered.AddRange(this.bindings[key]); } foreach (Binding binding in triggered) { string message = binding.callback(command.index, command.value); if (message != null) { this.config.midiLog.Append( "Binding \"" + binding.config.BindingName + "\" triggered: " + message ); } } }
public Operator(Configuration config) { this.config = config; this.stopwatch = new Stopwatch(); this.stopwatch.Start(); this.inputs = new List<Input>(); var audio = new AudioInput(config); this.inputs.Add(audio); var midi = new MidiInput(config); this.inputs.Add(midi); this.outputs = new List<Output>(); var hue = new HueOutput(config); this.outputs.Add(hue); var board = new CartesianTeensyOutput(config); this.outputs.Add(board); var dome = new LEDDomeOutput(config); this.outputs.Add(dome); var whyFire = new WhyFireOutput(config); this.outputs.Add(whyFire); this.visualizers = new List<Visualizer>(); this.visualizers.Add(new HueAudioVisualizer( this.config, audio, hue )); this.visualizers.Add(new LEDPanelVolumeVisualizer( this.config, audio, board )); this.visualizers.Add(new HueSolidColorVisualizer( this.config, hue )); this.visualizers.Add(new HueSilentVisualizer( this.config, audio, hue )); this.visualizers.Add(new LEDPanelMidiVisualizer( this.config, midi, board )); this.visualizers.Add(new LEDDomeMidiTestVisualizer( this.config, midi, dome )); this.visualizers.Add(new LEDDomeStrandTestVisualizer( this.config, dome )); this.visualizers.Add(new LEDDomeVolumeVisualizer( this.config, audio, dome )); this.visualizers.Add(new LEDDomeFlashVisualizer( this.config, audio, midi, dome )); this.visualizers.Add(new WhyFireMidiVisualizer( this.config, midi, whyFire )); }