//actual work protected override IReadOnlyDictionary <string, object> GetEntries() { var devices = SanfordInputDevice.DeviceCount; var deviceMap = new Dictionary <string, object>(devices); var deviceCountPerName = new Dictionary <string, int>(); for (int i = 0; i < devices; i++) { var originalName = SanfordInputDevice.GetDeviceCapabilities(i).name; var deviceName = originalName; int nameCount; //if name was seen already, increase count and add number if (deviceCountPerName.TryGetValue(originalName, out nameCount)) { nameCount++; deviceName += " #" + nameCount; } else { nameCount = 1; } deviceCountPerName[originalName] = nameCount; deviceMap[deviceName] = i; } return(deviceMap); }
private void initMidi() { if (InputDevice.DeviceCount == 0) { MessageBox.Show("No MIDI input devices available.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); } else { try { logMe("Found " + InputDevice.DeviceCount.ToString() + " midi devices. Initializing MIDI interface... "); context = SynchronizationContext.Current; inDevice = new InputDevice(0); inDevice.ChannelMessageReceived += HandleChannelMessageReceived; inDevice.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); inDevice.StartRecording(); logMe("Done!\n"); } catch (Exception ex) { logMe("Error initializing MIDI interface: " + ex.Message); Close(); } } }
protected override void OnLoad(EventArgs e) { if(InputDevice.DeviceCount == 0) { MessageBox.Show("No MIDI input devices available.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); } else { try { context = SynchronizationContext.Current; inDevice = new InputDevice(0); inDevice.ChannelMessageReceived += HandleChannelMessageReceived; inDevice.SysCommonMessageReceived += HandleSysCommonMessageReceived; inDevice.SysExMessageReceived += HandleSysExMessageReceived; inDevice.SysRealtimeMessageReceived += HandleSysRealtimeMessageReceived; inDevice.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); } catch(Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); Close(); } } base.OnLoad(e); }
public MidiManager() { if (InputDevice.DeviceCount == 0) return; _inDevice = new InputDevice(0); _inDevice.ChannelMessageReceived += InDevice_ChannelMessageReceived; _inDevice.StartRecording(); }
public MainWindow() { InitializeComponent(); DataContext = this; InputDevice id = new InputDevice(10); //Mathis : 10 _apcMiniController = new APCMiniController(id, new OutputDevice(11), new OutputDevice(2)); //Mathis 11 - 1 ApcMiniControllerView.Bind(_apcMiniController); }
public MidiInput2(string deviceName = null, bool ignoreMissingDevice = false, [System.Runtime.CompilerServices.CallerMemberName] string name = "") { this.name = name; string midiDeviceName = deviceName; if (string.IsNullOrEmpty(deviceName)) midiDeviceName = Executor.Current.GetSetKey(this, name + ".DeviceName", string.Empty); this.messageMapper = new Dictionary<Tuple<int, ChannelCommand, int>, Action<ChannelMessage>>(); this.midiMessages = new Subject<ChannelMessage>(); int selectedDeviceId = -1; for (int i = 0; i < InputDevice.DeviceCount; i++) { var midiCap = InputDevice.GetDeviceCapabilities(i); if (midiCap.name == midiDeviceName) { selectedDeviceId = i; break; } } if (selectedDeviceId == -1) { if (!ignoreMissingDevice) throw new ArgumentException("Midi device not detected"); else log.Warn("Midi device not detected"); } else { this.inputDevice = new InputDevice(selectedDeviceId); this.inputDevice.ChannelMessageReceived += inputDevice_ChannelMessageReceived; if (string.IsNullOrEmpty(deviceName)) Executor.Current.SetKey(this, name + ".DeviceName", midiDeviceName); } Executor.Current.Register(this); }
public HUIKeyboardHandler(Home home, int inputDeviceID) { this.home = home; if (InputDevice.DeviceCount == 0) { MessageBox.Show("No MIDI input devices available."); } else { try { context = SynchronizationContext.Current; inDevice = new InputDevice(inputDeviceID); inDevice.ChannelMessageReceived += HandleChannelMessageReceived; inDevice.StartRecording(); } catch (Exception ex) { throw new ApplicationException("Error: " + ex); } } }
public void InitializeDevices() { lock (this) { if (!_initialized) { for (int i = 0; i < InputDevice.DeviceCount; i++) { var model = new InputDevice(i); // add to list MidiDeviceList.Add(model); // register event model.ChannelMessageReceived += HandleChannelMessageReceived; model.Enabled = true; } _initialized = true; } } }
public void Initialise() { _uiCtx = SynchronizationContext.Current; // Set up the midi device if (InputDevice.DeviceCount == 0) { //throw new Exception("No midi devices detected"); } else { try { // Set up device and link to handler _inputDevice = new InputDevice(0); _inputDevice.ChannelMessageReceived += HandleInputMessageReceived; IsInitialised = true; } catch (Exception ex) { Exceptions.ErrHandler(ex); } } }
private void TerminateMidi() { this.device.StopRecording(); this.device.Dispose(); this.device = null; }
private void InitializeMidi() { this.device = new InputDevice(this.config.midiDeviceIndex); this.device.ChannelMessageReceived += ChannelMessageReceived; this.device.StartRecording(); }
/// <summary> /// Create Midisignal with an input device which fires the events /// </summary> /// <param name="inDevice"></param> public InputDeviceMidiEvents(InputDevice inDevice) { FInDevice = inDevice; FInDevice.StartRecording(); }
internal InputDevice GetInputDevice() { if (_inputDevice == null && this.MIDIInputDeviceNumber.HasValue) { try { _inputDevice = new InputDevice(this.MIDIInputDeviceNumber.Value); } catch (InputDeviceException) // the input device is unavailable (in use or not attached.) { _inputDevice = null; } } return _inputDevice; }
public MainForm() { InitializeComponent(); panele[0, 0] = panel1; panele[1, 0] = panel2; panele[2, 0] = panel3; panele[3, 0] = panel4; panele[0, 1] = panel5; panele[1, 1] = panel6; panele[2, 1] = panel7; panele[3, 1] = panel8; foreach (GameType gameType in Enum.GetValues(typeof(GameType))) { lbxGames.Items.Add(gameType); } if (OutputDevice.DeviceCount < 2) { DeviceOK = false; MessageBox.Show("No LPD8 = No game", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { try { context = SynchronizationContext.Current; outDevice1 = new OutputDevice(1); outDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); } catch (Exception ex) { DeviceOK = false; MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } if (DeviceOK) if (InputDevice.DeviceCount < 1) { DeviceOK = false; MessageBox.Show("LPD8 = No game", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { try { context = SynchronizationContext.Current; inDevice1 = new InputDevice(0); inDevice1.ChannelMessageReceived += HandleChannelMessageReceived; inDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); AddLogDevice(0, InputDevice.GetDeviceCapabilities(0)); inDevice1.StartRecording(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); DeviceOK = false; } } if (DeviceOK) ResetSquares(); }
/// <summary> /// Create Midisignal with an input device which fires the events /// </summary> /// <param name="inDevice"></param> public InputDeviceMidiEvents(InputDevice inDevice) { FInDevice = inDevice; FInDevice.StartRecording(); }
public Form1() { InitializeComponent(); panele[0, 0] = panel1; panele[1, 0] = panel2; panele[2, 0] = panel3; panele[3, 0] = panel4; panele[0, 1] = panel5; panele[1, 1] = panel6; panele[2, 1] = panel7; panele[3, 1] = panel8; panele[0, 2] = panel9; panele[1, 2] = panel10; panele[2, 2] = panel11; panele[3, 2] = panel12; panele[0, 3] = panel13; panele[1, 3] = panel14; panele[2, 3] = panel15; panele[3, 3] = panel16; List<Point> droga = new List<Point>(); droga.Add(new Point(0, 0)); droga.Add(new Point(1, 0)); droga.Add(new Point(2, 0)); droga.Add(new Point(3, 0)); droga.Add(new Point(3, 1)); droga.Add(new Point(3, 2)); droga.Add(new Point(3, 3)); ListaDrog.Add(droga); List<Point> droga1 = new List<Point>(); droga1.Add(new Point(0, 0)); droga1.Add(new Point(1, 0)); droga1.Add(new Point(2, 0)); droga1.Add(new Point(2, 1)); droga1.Add(new Point(3, 1)); droga1.Add(new Point(3, 2)); droga1.Add(new Point(3, 3)); ListaDrog.Add(droga1); List<Point> droga2 = new List<Point>(); droga2.Add(new Point(0, 0)); droga2.Add(new Point(1, 0)); droga2.Add(new Point(1, 1)); droga2.Add(new Point(2, 1)); droga2.Add(new Point(3, 1)); droga2.Add(new Point(3, 2)); droga2.Add(new Point(3, 3)); ListaDrog.Add(droga2); List<Point> droga3 = new List<Point>(); droga3.Add(new Point(0, 0)); droga3.Add(new Point(0, 1)); droga3.Add(new Point(1, 1)); droga3.Add(new Point(2, 1)); droga3.Add(new Point(3, 1)); droga3.Add(new Point(3, 2)); droga3.Add(new Point(3, 3)); ListaDrog.Add(droga3); List<Point> droga4 = new List<Point>(); droga4.Add(new Point(0, 0)); droga4.Add(new Point(0, 1)); droga4.Add(new Point(1, 1)); droga4.Add(new Point(2, 1)); droga4.Add(new Point(2, 2)); droga4.Add(new Point(3, 2)); droga4.Add(new Point(3, 3)); ListaDrog.Add(droga4); List<Point> droga5 = new List<Point>(); droga5.Add(new Point(0, 0)); droga5.Add(new Point(0, 1)); droga5.Add(new Point(1, 1)); droga5.Add(new Point(1, 2)); droga5.Add(new Point(2, 2)); droga5.Add(new Point(3, 2)); droga5.Add(new Point(3, 3)); ListaDrog.Add(droga5); List<Point> droga6 = new List<Point>(); droga6.Add(new Point(0, 0)); droga6.Add(new Point(0, 1)); droga6.Add(new Point(0, 2)); droga6.Add(new Point(1, 2)); droga6.Add(new Point(2, 2)); droga6.Add(new Point(3, 2)); droga6.Add(new Point(3, 3)); ListaDrog.Add(droga6); List<Point> droga7 = new List<Point>(); droga7.Add(new Point(0, 0)); droga7.Add(new Point(0, 1)); droga7.Add(new Point(0, 2)); droga7.Add(new Point(1, 2)); droga7.Add(new Point(2, 2)); droga7.Add(new Point(2, 3)); droga7.Add(new Point(3, 3)); ListaDrog.Add(droga7); List<Point> droga8 = new List<Point>(); droga8.Add(new Point(0, 0)); droga8.Add(new Point(0, 1)); droga8.Add(new Point(0, 2)); droga8.Add(new Point(1, 2)); droga8.Add(new Point(1, 3)); droga8.Add(new Point(2, 3)); droga8.Add(new Point(3, 3)); ListaDrog.Add(droga8); List<Point> droga9 = new List<Point>(); droga9.Add(new Point(0, 0)); droga9.Add(new Point(0, 1)); droga9.Add(new Point(0, 2)); droga9.Add(new Point(0, 3)); droga9.Add(new Point(1, 3)); droga9.Add(new Point(2, 3)); droga9.Add(new Point(3, 3)); ListaDrog.Add(droga9); List<Point> droga10 = new List<Point>(); droga10.Add(new Point(0, 0)); droga10.Add(new Point(1, 0)); droga10.Add(new Point(2, 0)); droga10.Add(new Point(2, 1)); droga10.Add(new Point(2, 2)); droga10.Add(new Point(3, 2)); droga10.Add(new Point(3, 3)); ListaDrog.Add(droga10); List<Point> droga11 = new List<Point>(); droga11.Add(new Point(0, 0)); droga11.Add(new Point(1, 0)); droga11.Add(new Point(2, 0)); droga11.Add(new Point(2, 1)); droga11.Add(new Point(2, 2)); droga11.Add(new Point(2, 3)); droga11.Add(new Point(3, 3)); ListaDrog.Add(droga11); List<Point> droga12 = new List<Point>(); droga12.Add(new Point(0, 0)); droga12.Add(new Point(1, 0)); droga12.Add(new Point(1, 1)); droga12.Add(new Point(2, 1)); droga12.Add(new Point(2, 2)); droga12.Add(new Point(2, 3)); droga12.Add(new Point(3, 3)); ListaDrog.Add(droga12); List<Point> droga13 = new List<Point>(); droga13.Add(new Point(0, 0)); droga13.Add(new Point(1, 0)); droga13.Add(new Point(1, 1)); droga13.Add(new Point(1, 2)); droga13.Add(new Point(2, 2)); droga13.Add(new Point(2, 3)); droga13.Add(new Point(3, 3)); ListaDrog.Add(droga13); List<Point> droga14 = new List<Point>(); droga14.Add(new Point(0, 0)); droga14.Add(new Point(1, 0)); droga14.Add(new Point(1, 1)); droga14.Add(new Point(1, 2)); droga14.Add(new Point(1, 3)); droga14.Add(new Point(2, 3)); droga14.Add(new Point(3, 3)); ListaDrog.Add(droga14); List<Point> droga15 = new List<Point>(); droga15.Add(new Point(0, 0)); droga15.Add(new Point(0, 1)); droga15.Add(new Point(1, 1)); droga15.Add(new Point(1, 2)); droga15.Add(new Point(1, 3)); droga15.Add(new Point(2, 3)); droga15.Add(new Point(3, 3)); ListaDrog.Add(droga15); List<Point> droga16 = new List<Point>(); droga16.Add(new Point(0, 0)); droga16.Add(new Point(0, 1)); droga16.Add(new Point(0, 2)); droga16.Add(new Point(1, 2)); droga16.Add(new Point(1, 3)); droga16.Add(new Point(2, 3)); droga16.Add(new Point(3, 3)); ListaDrog.Add(droga16); droga = new List<Point>(); droga.Add(new Point(0, 0)); droga.Add(new Point(0, 1)); droga.Add(new Point(1, 1)); droga.Add(new Point(1, 2)); droga.Add(new Point(2, 2)); droga.Add(new Point(2, 3)); droga.Add(new Point(3, 3)); ListaDrog.Add(droga); droga = new List<Point>(); droga.Add(new Point(0, 0)); droga.Add(new Point(0, 1)); droga.Add(new Point(1, 1)); droga.Add(new Point(2, 1)); droga.Add(new Point(2, 2)); droga.Add(new Point(2, 3)); droga.Add(new Point(3, 3)); ListaDrog.Add(droga); droga = new List<Point>(); droga.Add(new Point(0, 0)); droga.Add(new Point(1, 0)); droga.Add(new Point(1, 1)); droga.Add(new Point(2, 1)); droga.Add(new Point(2, 2)); droga.Add(new Point(3, 2)); droga.Add(new Point(3, 3)); ListaDrog.Add(droga); droga = new List<Point>(); droga.Add(new Point(0, 0)); droga.Add(new Point(1, 0)); droga.Add(new Point(1, 1)); droga.Add(new Point(1, 2)); droga.Add(new Point(2, 2)); droga.Add(new Point(3, 2)); droga.Add(new Point(3, 3)); ListaDrog.Add(droga); if (OutputDevice.DeviceCount < 3) { DeviceOK = false; MessageBox.Show("No LPD8 x 2 = No game", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Stop); //Close(); } else { try { context = SynchronizationContext.Current; outDevice1 = new OutputDevice(1); outDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); context = SynchronizationContext.Current; outDevice2 = new OutputDevice(2); outDevice2.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); } catch (Exception ex) { DeviceOK = false; MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); //Close(); } } if (DeviceOK) if (InputDevice.DeviceCount < 2) { DeviceOK = false; MessageBox.Show("LPD8 x2 = No game", "Game Over", MessageBoxButtons.OK, MessageBoxIcon.Stop); //Close(); } else { try { context = SynchronizationContext.Current; inDevice1 = new InputDevice(0); inDevice1.ChannelMessageReceived += HandleChannelMessageReceived; inDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); AddLogDevice(0, InputDevice.GetDeviceCapabilities(0)); inDevice1.StartRecording(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); DeviceOK = false; //Close(); } try { context = SynchronizationContext.Current; inDevice2 = new InputDevice(1); inDevice2.ChannelMessageReceived += HandleChannelMessageReceived; inDevice2.Error += new EventHandler<ErrorEventArgs>(inDevice_Error); AddLogDevice(1, InputDevice.GetDeviceCapabilities(1)); inDevice2.StartRecording(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop); DeviceOK = false; //Close(); } } if (DeviceOK) Reset(); }
/// <summary> /// Create a new Game. /// </summary> /// <param name="flashcardSeconds">The maximum number of seconds that the player has to respond to a flashcard.</param> /// <param name="gameSeconds">The length of the game. At the end of this time, it's game over.</param> /// <param name="virtualKeyboards">If supplied, the game will take input from these as well as the configured MIDI input device (if any.)</param> public Game(params VirtualKeyboard[] virtualKeyboards) { var settings = UserSettings.Instance; var types = new List<FlashcardGenerator>(); if (settings.FlashcardTypes_Triad == true) { types.Add(new TriadFlashcardGenerator(new TradFlashcardGeneratorArgs() { TriadTypes = TriadType.All, TriadInversions = TriadInversion.All, Accidentals = settings.Accidentals, Staffs = settings.Staffs })); } if (settings.FlashcardTypes_Interval == true) { types.Add(new IntervalFlashcardGenerator(new IntervalFlashcardGeneratorArgs() { IntervalTypes = Interval.All, Staffs = settings.Staffs, Accidentals = settings.Accidentals })); } if (settings.FlashcardTypes_Single == true || !types.Any()) // if they set no flashcard types, give them single. { types.Add(new SingleNoteFlashcardGenerator(new StaffFlashcardGeneratorArgs() { Staffs = settings.Staffs, Accidentals = settings.Accidentals })); } _flashcardSource = new MultipleFlashcardGenerator(types.ToArray()); _currentResponse = new Dictionary<Note, bool>(); _flashcardResults = new List<FlashcardResult>(); // if the user changes MIDI devices mid-game, handle that. UserSettings.Instance.OutputDeviceChanged += new EventHandler(UserSettings_OutputDeviceChanged); UserSettings.Instance.InputDeviceChanged += new EventHandler(UserSettings_InputDeviceChanged); _outputDevice = UserSettings.Instance.GetOutputDevice(); _inputDevice = UserSettings.Instance.GetInputDevice(); if (_inputDevice != null) _inputDevice.ChannelMessageReceived += new EventHandler<ChannelMessageEventArgs>(ChannelMessageReceived); foreach(var vk in virtualKeyboards) vk.ChannelMessageReceived += new EventHandler<ChannelMessageEventArgs>(ChannelMessageReceived); _gameTimer = new Timer(GAME_DURATION * 1000); _flashcardTimer = new Timer(settings.MaxFlashcardTime * 1000); _nextFlashcardTimer = new Timer(500); _newGameCountdownTimer = new Timer(1000); _nextFlashcardTimer.AutoReset = false; _gameTimer.Elapsed += new ElapsedEventHandler(GameTimer_Elapsed); _flashcardTimer.Elapsed += new ElapsedEventHandler(FlashcardTimer_Elapsed); _nextFlashcardTimer.Elapsed += new ElapsedEventHandler(NextFlashcardTimer_Elapsed); GameMode = GameMode.NotStarted; }
private static void initMidiDevices() { try { if (InputDevice.DeviceCount > 0) { SynchronizationContext context = SynchronizationContext.Current; _devices = new List<InputDevice>(); for (int iDevice = 0; iDevice < InputDevice.DeviceCount; ++iDevice) { InputDevice inDevice = new InputDevice(0); inDevice.ChannelMessageReceived += HandleChannelMessageReceived; _devices.Add(inDevice); inDevice.StartRecording(); } } } catch (Exception ex) { try { foreach (InputDevice d in _devices) { d.Dispose(); } _devices.Clear(); } catch (Exception exc2) { Logger.Log(exc2.ToString()); } Logger.Log(ex.ToString()); } }
/// <summary> /// The MIDI input device has changed. Grab the new one. /// </summary> void UserSettings_InputDeviceChanged(object sender, EventArgs e) { _inputDevice = UserSettings.Instance.GetInputDevice(); if (_inputDevice != null) _inputDevice.ChannelMessageReceived += new EventHandler<ChannelMessageEventArgs>(ChannelMessageReceived); }
public void Dispose() { if (_inDevice == null) return; _inDevice.StopRecording(); _inDevice.Dispose(); _inDevice = null; }