/// <summary> /// Opens the stream /// </summary> public void Open() { if (IntPtr.Zero != _handle) { throw new InvalidOperationException("The device is already open"); } _sendEventBuffer = Marshal.AllocHGlobal(64 * 1024); var di = _deviceIndex; var h = IntPtr.Zero; _CheckOutResult(midiStreamOpen(ref h, ref di, 1, _outCallback, 0, CALLBACK_FUNCTION)); Interlocked.Exchange(ref _handle, h); _state = MidiStreamState.Paused; }
/// <summary> /// Pauses the stream /// </summary> public void Pause() { if (IntPtr.Zero == _handle) { throw new InvalidOperationException("The stream is closed."); } switch (_state) { case MidiStreamState.Started: _CheckOutResult(midiStreamPause(_handle)); _state = MidiStreamState.Paused; Interlocked.Exchange(ref _tempoSyncMessagesSentCount, 0); break; } }
/// <summary> /// Closes the stream /// </summary> public void Close() { _DisposeTimer(); if (IntPtr.Zero != _handle) { Stop(); Reset(); _CheckOutResult(midiStreamClose(_handle)); Interlocked.Exchange(ref _handle, IntPtr.Zero); Marshal.FreeHGlobal(_sendEventBuffer); _sendEventBuffer = IntPtr.Zero; GC.SuppressFinalize(this); _state = MidiStreamState.Closed; } }
/// <summary> /// Closes the stream /// </summary> public override void Close() { _DisposeTimer(); if (IntPtr.Zero != Handle) { Stop(); Reset(); _CheckOutResult(midiStreamClose(Handle)); Handle = IntPtr.Zero; GC.SuppressFinalize(this); Interlocked.Exchange(ref _sendQueue, null); Interlocked.Exchange(ref _sendQueuePosition, 0); _state = MidiStreamState.Closed; } }
/// <summary> /// Opens the stream /// </summary> public override void Open() { if (IntPtr.Zero != Handle) { throw new InvalidOperationException("The device is already open"); } var di = Index; var h = IntPtr.Zero; Interlocked.Exchange(ref _sendQueue, null); Interlocked.Exchange(ref _sendQueuePosition, 0); _CheckOutResult(midiStreamOpen(ref h, ref di, 1, _outCallback, 0, CALLBACK_FUNCTION)); Handle = h; _state = MidiStreamState.Paused; }
/// <summary> /// Starts the stream /// </summary> public void Start() { if (IntPtr.Zero == _handle) { throw new InvalidOperationException("The stream is closed."); } switch (_state) { case MidiStreamState.Paused: case MidiStreamState.Stopped: var tmp = Tempo; var spb = 60 / tmp; var ms = unchecked ((int)(Math.Round((1000 * spb) / 24))); Interlocked.Exchange(ref _tempoSyncMessagesSentCount, 0); _RestartTimer(ms); _CheckOutResult(midiStreamRestart(_handle)); _state = MidiStreamState.Started; break; } }
/// <summary> /// Stops the stream /// </summary> public void Stop() { if (IntPtr.Zero == _handle) { throw new InvalidOperationException("The stream is closed."); } switch (_state) { case MidiStreamState.Paused: case MidiStreamState.Started: _DisposeTimer(); _CheckOutResult(midiStreamStop(_handle)); Interlocked.Exchange(ref _tempoSyncMessagesSentCount, 0); _state = MidiStreamState.Stopped; Interlocked.Exchange(ref _sendQueuePosition, 0); if (null != _sendQueue) { Interlocked.Exchange(ref _sendQueue, null); } break; } }