/// <summary>
 /// Receives a long midi error message.
 /// </summary>
 /// <param name="buffer">The buffer containing the long midi message error.</param>
 /// <param name="timestamp">Not used. A new timestamp is generated.</param>
 public override void LongError(MidiBufferStream buffer, long timestamp)
 {
     if (NextErrorReceiver != null)
     {
         NextErrorReceiver.LongError(buffer, GetCurrentTimestamp());
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Pushes a long midi message into the queue, marked as error.
        /// </summary>
        /// <param name="buffer">A long midi message. Must not be null.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        public void PushLongError(MidiBufferStream buffer, long timestamp)
        {
            MidiPortEvent rec = new MidiPortEvent(
                MidiPortEventType.LongError, buffer, timestamp);

            this.Push(rec);
        }
        /// <summary>
        /// Sends the long midi message to the next sender chain component.
        /// </summary>
        /// <param name="buffer">The long midi message.</param>
        /// <remarks>Long midi messages will reset the running status.</remarks>
        public void LongData(MidiBufferStream buffer)
        {
            Check.IfArgumentNull(buffer, nameof(buffer));

            RunningStatus = 0;
            NextSenderLongData(buffer);
        }
        /// <summary>
        /// Sends the long midi message to the next sender chain component.
        /// </summary>
        /// <param name="buffer">The long midi message.</param>
        /// <remarks>Long midi messages will reset the running status.</remarks>
        public void LongData(MidiBufferStream buffer)
        {
            Check.IfArgumentNull(buffer, "buffer");

            this.RunningStatus = 0;
            NextSenderLongData(buffer);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Pushes a long midi message into the queue.
        /// </summary>
        /// <param name="buffer">A long midi message. Must not be null.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        public void PushLongData(MidiBufferStream buffer, long timestamp)
        {
            MidiPortEvent rec = new MidiPortEvent(
                MidiPortEventType.LongData, buffer, timestamp);

            Push(rec);
        }
Exemplo n.º 6
0
 public void LongData(MidiBufferStream buffer, long timeIndex)
 {
     if (MidiThru)
     {
         _outPort.LongData(buffer);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Constructs a new instance on the <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">Must not be null.</param>
        public MidiMessageOutStreamWriter(MidiBufferStream stream)
        {
            Check.IfArgumentNull(stream, nameof(stream));

            BaseStream   = stream;
            StreamWriter = new MidiStreamEventWriter(stream);
        }
Exemplo n.º 8
0
        public void LongData(MidiBufferStream buffer, long timestamp)
        {
            Trace.WriteLine("Receiving buffer: " + buffer.BytesRecorded);

            var sysExBuffer = MidiSysExBuffer.From(buffer);

            ScheduleAddBuffer(sysExBuffer);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Constructs a new instance on the <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">Must not be null.</param>
        public MidiMessageOutStreamWriter(MidiBufferStream stream)
        {
            Contract.Requires(stream != null);
            Check.IfArgumentNull(stream, "stream");

            this.BaseStream   = stream;
            this.StreamWriter = new MidiStreamEventWriter(stream);
        }
Exemplo n.º 10
0
        /// <inheritdocs/>
        public void LongData(MidiBufferStream buffer, long timestamp)
        {
            Check.IfArgumentNull(buffer, "buffer");

            using (new ScopedStopWatch(LongPerformanceData))
            {
                NextReceiverLongData(buffer, timestamp);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Call to relay the long midi message data to the next sender component in the chain.
        /// </summary>
        /// <param name="buffer">The long midi message data.</param>
        /// <remarks>The method will fail graciously if the <see cref="Successor"/> property is not set.</remarks>
        protected void NextSenderLongData(MidiBufferStream buffer)
        {
            Check.IfArgumentNull(buffer, nameof(buffer));

            if (Successor != null)
            {
                Successor.LongData(buffer);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Call to relay the long midi message data to the next receiver component in the chain.
        /// </summary>
        /// <param name="buffer">The long midi message data.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        /// <remarks>The method will fail graciously if the <see cref="Successor"/> property is not set.</remarks>
        protected void NextReceiverLongData(MidiBufferStream buffer, long timestamp)
        {
            Check.IfArgumentNull(buffer, nameof(buffer));

            if (Successor != null)
            {
                Successor.LongData(buffer, timestamp);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Constructs a new instance for a long midi message.
        /// </summary>
        /// <param name="recordType">A value appropriate for long midi messages.</param>
        /// <param name="buffer">The long midi message. Must not be null.</param>
        /// <param name="deltaTime">A time indication of the midi message.</param>
        public MidiPortEvent(MidiPortEventType recordType, MidiBufferStream buffer, long deltaTime)
        {
            Check.IfArgumentOutOfRange <int>((int)recordType, (int)MidiPortEventType.LongData, (int)MidiPortEventType.LongError, "recordType");

            this.RecordType = recordType;
            this.Data       = 0;
            this.Buffer     = buffer;
            this.Timestamp  = deltaTime;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Constructs a new instance for a long midi message.
        /// </summary>
        /// <param name="recordType">A value appropriate for long midi messages.</param>
        /// <param name="buffer">The long midi message. Must not be null.</param>
        /// <param name="deltaTime">A time indication of the midi message.</param>
        public MidiPortEvent(MidiPortEventType recordType, MidiBufferStream buffer, long deltaTime)
        {
            Check.IfArgumentOutOfRange <int>((int)recordType, (int)MidiPortEventType.LongData, (int)MidiPortEventType.LongError, nameof(recordType));

            RecordType = recordType;
            Data       = 0;
            Buffer     = buffer;
            Timestamp  = deltaTime;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Called to prepare <paramref name="buffer"/> for the port.
        /// </summary>
        /// <param name="buffer">Must not be null.</param>
        /// <remarks>Buffers are also marked as streams.</remarks>
        protected override void OnPrepareBuffer(MidiBufferStream buffer)
        {
            Check.IfArgumentNull(buffer, nameof(buffer));

            base.OnPrepareBuffer(buffer);

            // mark buffers as streams
            buffer.HeaderFlags |= NativeMethods.MHDR_ISSTRM;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Call to relay the long midi message data to the next receiver component in the chain.
        /// </summary>
        /// <param name="buffer">The long midi message data.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        /// <remarks>The method will fail graciously if the <see cref="Successor"/> property is not set.</remarks>
        protected void NextReceiverLongData(MidiBufferStream buffer, long timestamp)
        {
            Contract.Requires(buffer != null);
            Check.IfArgumentNull(buffer, "buffer");

            if (this.Successor != null)
            {
                this.Successor.LongData(buffer, timestamp);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Call to relay the long midi message data to the next sender component in the chain.
        /// </summary>
        /// <param name="buffer">The long midi message data.</param>
        /// <remarks>The method will fail graciously if the <see cref="Successor"/> property is not set.</remarks>
        protected void NextSenderLongData(MidiBufferStream buffer)
        {
            Contract.Requires(buffer != null);
            Check.IfArgumentNull(buffer, "buffer");

            if (this.Successor != null)
            {
                this.Successor.LongData(buffer);
            }
        }
Exemplo n.º 18
0
        public static MidiSysExBuffer From(MidiBufferStream buffer)
        {
            int length      = (int)buffer.BytesRecorded;
            var sysExBuffer = new MidiSysExBuffer(length);

            buffer.Position = 0;

            buffer.Read(sysExBuffer._buffer, 0, length);

            return(sysExBuffer);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Constructs a new instance on the specified <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">A stream provided by a <see cref="MidiOutStreamPort"/>. Must not be null.</param>
        public MidiStreamEventWriter(MidiBufferStream stream)
        {
            Check.IfArgumentNull(stream, "stream");
            if (!stream.CanWrite)
            {
                throw new ArgumentException(
                          Properties.Resources.MidiStreamWriter_StreamNotWritable, "stream");
            }

            BaseStream  = stream;
            InnerWriter = new BinaryWriter(stream);
        }
Exemplo n.º 20
0
        public MidiStreamEventWriter(MidiBufferStream stream)
        {
            Contract.Requires(stream != null);
            Contract.Requires(stream.CanRead);
            Check.IfArgumentNull(stream, "stream");
            if (!stream.CanWrite)
            {
                throw new ArgumentException(
                          Properties.Resources.MidiStreamWriter_StreamNotWritable, "stream");
            }

            this.BaseStream  = stream;
            this.InnerWriter = new BinaryWriter(stream);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Puts a long midi error in the queue.
        /// </summary>
        /// <param name="buffer">Error buffer. Must not be null.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        public override void LongError(MidiBufferStream buffer, long timestamp)
        {
            Check.IfArgumentNull(buffer, "buffer");

            this.queue.PushLongError(buffer, timestamp);
        }
Exemplo n.º 22
0
 public void LongData(MidiBufferStream buffer, long timestamp)
 {
     //not implemented
 }
        /// <summary>
        /// Passes the long midi message to the next receiver component. No filtering is applied.
        /// </summary>
        /// <param name="buffer">The long midi message data.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        public void LongData(MidiBufferStream buffer, long timestamp)
        {
            Check.IfArgumentNull(buffer, "buffer");

            NextReceiverLongData(buffer, timestamp);
        }
Exemplo n.º 24
0
 public void LongData(MidiBufferStream buffer, long timestamp)
 {
     //not implemented
 }
Exemplo n.º 25
0
 public void LongError(MidiBufferStream buffer, long timestamp)
 {
     _appData.ReceiveErrorCount++;
 }
Exemplo n.º 26
0
 /// <inheritdocs/>
 public abstract void LongError(MidiBufferStream buffer, long timestamp);
Exemplo n.º 27
0
        /// <summary>
        /// Puts a long midi error in the queue.
        /// </summary>
        /// <param name="buffer">Error buffer. Must not be null.</param>
        /// <param name="timestamp">A time indication of the midi message.</param>
        public override void LongError(MidiBufferStream buffer, long timestamp)
        {
            Check.IfArgumentNull(buffer, nameof(buffer));

            _queue.PushLongError(buffer, timestamp);
        }
Exemplo n.º 28
0
        private static MidiOutPortBase ProcessStreaming(int outPortId, MidiFileData fileData,
                                                        IEnumerable <MidiFileEvent> notes, MidiOutPortCaps caps)
        {
            var outPort = new MidiOutStreamPort();

            outPort.Open(outPortId);
            outPort.BufferManager.Initialize(10, 1024);
            outPort.TimeDivision = fileData.Header.TimeDivision;

            // TODO: extract Tempo from meta messages from the file.
            // 120 bpm (uSec/QuarterNote).
            outPort.Tempo = 500000;

            Console.WriteLine(String.Format("Midi Out Stream Port '{0}' is now open.", caps.Name));

            MidiMessageOutStreamWriter writer = null;
            MidiBufferStream           buffer = null;
            MidiFileEvent lastNote            = null;

            foreach (var note in notes)
            {
                if (writer == null)
                {
                    // brute force buffer aqcuirement.
                    // when callbacks are implemented this will be more elegant.
                    do
                    {
                        buffer = outPort.BufferManager.RetrieveBuffer();

                        if (buffer != null)
                        {
                            break;
                        }

                        Thread.Sleep(50);
                    } while (buffer == null);

                    writer = new MidiMessageOutStreamWriter(buffer);
                }

                if (writer.CanWrite(note.Message))
                {
                    if (lastNote != null)
                    {
                        // fixup delta time artifically...
                        writer.Write(note.Message, (int)(note.AbsoluteTime - lastNote.AbsoluteTime));
                    }
                    else
                    {
                        writer.Write(note.Message, (int)note.DeltaTime);
                    }
                }
                else
                {
                    outPort.LongData(buffer);
                    writer = null;

                    Console.WriteLine("Buffer sent...");

                    if (!outPort.HasStatus(MidiPortStatus.Started))
                    {
                        outPort.Restart();
                    }
                }

                lastNote = note;
            }

            return(outPort);
        }
Exemplo n.º 29
0
 public void LongData(MidiBufferStream buffer, long timestamp)
 {
 }
Exemplo n.º 30
0
 public void LongData(MidiBufferStream buffer, long timestamp)
 {
     // we're not doing sys-ex.
 }