public void onLoad(object sender, System.EventArgs e) { //window loaded, set window back to a normal state this.WindowState = FormWindowState.Normal; this.Visible = false; this.ShowInTaskbar = true; pthrough.Start(); CreateMIDIDevList(); if (inDevs.Count > 0) { int def = getInDev(); if (def < -1 || def > inDevs.Count) { def = -1; setInDev(-1); } else if (def == -1) { devInBox.SelectedIndex = inDevs.Count; } else { lock (inLock) { inPort.Open(def); inPort.Start(); } devInBox.SelectedIndex = def; } } if (outDevs.Count > 0) { int def = getOutDev(); if (def < -1 || def > outDevs.Count) { def = -1; setOutDev(-1); } else if (def == -1) { devOutBox.SelectedIndex = outDevs.Count; } else { lock (outLock) { outPort.Open(def); } devOutBox.SelectedIndex = def; } } devInBox.SelectedIndexChanged += devInBox_SelectedIndexChanged; devOutBox.SelectedIndexChanged += devOutBox_SelectedIndexChanged; SetThreadStatus(); }
public void Start() { InPort = new MidiInPort(); InPort.Successor = new FloppyReceiver(); InPort.Open(0); InPort.Start(); }
public void Start(int portId) { _appData.Events.Clear(); _inPort.Open(portId); _inPort.Start(); }
public MidiGlobalHolder(int index) { Global = new MidiGlobal(this); port = new MidiInPort(); port.Successor = this; var count = new MidiInPortCapsCollection().Count; if (index >= count) { throw new Exception(string.Format("MIDI device with port index {0} not found", index)); } port.Open(index); port.Start(); }
public void Start(int inPortId, int outPortId, MidiNoteMapIndex index) { _index = index; try { byte channel = (byte)((InChannel - 1) & 0x0F); _inNoteOn = (byte)(NoteOn | channel); _inNoteOff = (byte)(NoteOff | channel); channel = (byte)((OutChannel - 1) & 0x0F); _outNoteOn = (byte)(NoteOn | channel); _outNoteOff = (byte)(NoteOff | channel); _diagnosticsReceiver.Reset(); _outPort.Open(outPortId); _inPort.Open(inPortId); _inPort.Start(); } catch { if (_outPort.HasStatus(MidiPortStatus.Open)) { _outPort.Close(); } if (_inPort.HasStatus(MidiPortStatus.Open)) { _inPort.Close(); } throw; } sendTest(); }
public void Start(int portId) { _inPort.Open(portId); _inPort.Start(); }
public RecordResult StartRecording(RecordOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } int[] inputIds = options.MidiInputs.SelectMany(GetMidiInputId).Distinct().ToArray(); if (inputIds.Length == 0) { return(new RecordResult($"No MIDI inputs for '{string.Join(", ", options.MidiInputs)}' could be located")); } _logger.LogInformation($"Working dir: {Environment.CurrentDirectory}"); var delayToSave = TimeSpan.FromMilliseconds(options.DelayToSave); _logger.LogInformation($"Delay to save: {delayToSave}"); var pathFormatString = options.PathFormatString; _logger.LogInformation($"Output Path: {pathFormatString}"); var midiResolution = options.MidiResolution; _logger.LogInformation($"MIDI resolution: {midiResolution}"); var receiverFactory = new ObservableReceiverFactory(_logger); var savingPoints = receiverFactory .Throttle(delayToSave) .Select(x => x.AbsoluteTime); _ = receiverFactory .Window(savingPoints) .Select(x => x .Aggregate(ImmutableList <MidiFileEvent> .Empty, (l, i) => l.Add(i))) .ForEachAsync(midiFile => midiFile .ForEachAsync(SaveMidiFile)); var midiIns = new List <MidiInPort>(); foreach (var inputId in inputIds) { var midiIn = new MidiInPort { Successor = receiverFactory.Build(inputId) }; midiIn.Open(inputId); midiIn.Start(); midiIns.Add(midiIn); } return(new RecordResult(() => { foreach (var midiIn in midiIns) { midiIn.Stop(); midiIn.Dispose(); } })); void SaveMidiFile(ImmutableList <MidiFileEvent> eventList) { var context = new MidiFileContext(eventList, DateTime.Now, Guid.NewGuid()); string filePath = context.BuildFilePath(pathFormatString); _logger.LogInformation($"Saving {eventList.Count} events to file {filePath}..."); try { MidiFileSerializer.Serialize(eventList, filePath, midiResolution); } catch (Exception ex) { _logger.LogError(ex, "There was an error when saving the file"); } } }