Пример #1
0
 /// <summary>
 /// Writes content of a MIDI meta event.
 /// </summary>
 /// <param name="writer">Writer to write the content with.</param>
 /// <param name="settings">Settings according to which the event's content must be written.</param>
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     writer.WriteByte(Numerator);
     writer.WriteByte((byte)Math.Log(Denominator, 2));
     writer.WriteByte(ClocksPerClick);
     writer.WriteByte(NumberOf32ndNotesPerBeat);
 }
Пример #2
0
 // Token: 0x060032AC RID: 12972 RVA: 0x00147ACC File Offset: 0x00145CCC
 internal sealed override void Write(MidiWriter writer, WritingSettings settings)
 {
     foreach (SevenBitNumber number in this._parameters)
     {
         writer.WriteByte(number);
     }
 }
Пример #3
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            VerifyEvent(midiEvent);

            //

            if (writeStatusByte)
            {
                var eventType = midiEvent.GetType();

                byte statusByte;
                if (!StandardEventTypes.Channel.TryGetStatusByte(eventType, out statusByte))
                {
                    Debug.Fail($"Unable to write the {eventType} event.");
                }

                var channel = ((ChannelEvent)midiEvent).Channel;

                var totalStatusByte = DataTypesUtilities.Combine((FourBitNumber)statusByte, channel);
                writer.WriteByte(totalStatusByte);
            }

            //

            midiEvent.Write(writer, settings);
        }
 /// <summary>
 /// Writes content of a MIDI event.
 /// </summary>
 /// <param name="writer">Writer to write the content with.</param>
 /// <param name="settings">Settings according to which the event's content must be written.</param>
 internal sealed override void Write(MidiWriter writer, WritingSettings settings)
 {
     foreach (var parameter in _parameters)
     {
         writer.WriteByte(parameter);
     }
 }
Пример #5
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            VerifyEvent(midiEvent);

            //

            if (writeStatusByte)
            {
                var eventType = midiEvent.GetType();

                byte statusByte;
                if (!StandardEventTypes.SysEx.TryGetStatusByte(eventType, out statusByte))
                {
                    Debug.Fail($"Unable to write the {eventType} event.");
                }

                writer.WriteByte(statusByte);
            }

            //

            var contentSize = midiEvent.GetSize(settings);

            writer.WriteVlqNumber(contentSize);
            midiEvent.Write(writer, settings);
        }
Пример #6
0
        // Token: 0x060033BA RID: 13242 RVA: 0x001486D0 File Offset: 0x001468D0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (writeStatusByte)
            {
                writer.WriteByte(byte.MaxValue);
            }
            UnknownMetaEvent unknownMetaEvent = midiEvent as UnknownMetaEvent;
            byte             statusByte;

            if (unknownMetaEvent != null)
            {
                statusByte = unknownMetaEvent.StatusByte;
            }
            else
            {
                Type type = midiEvent.GetType();
                if (!StandardEventTypes.Meta.TryGetStatusByte(type, out statusByte))
                {
                    EventTypesCollection customMetaEventTypes = settings.CustomMetaEventTypes;
                    if (customMetaEventTypes != null)
                    {
                        bool flag = !customMetaEventTypes.TryGetStatusByte(type, out statusByte);
                    }
                }
            }
            writer.WriteByte(statusByte);
            int size = midiEvent.GetSize(settings);

            writer.WriteVlqNumber(size);
            midiEvent.Write(writer, settings);
        }
Пример #7
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (writeStatusByte)
            {
                writer.WriteByte(EventStatusBytes.Global.Meta);
            }

            //

            byte statusByte;

            var unknownMetaEvent = midiEvent as UnknownMetaEvent;

            if (unknownMetaEvent != null)
            {
                statusByte = unknownMetaEvent.StatusByte;
            }
            else
            {
                var eventType = midiEvent.GetType();
                if (!StandardEventTypes.Meta.TryGetStatusByte(eventType, out statusByte) && settings.CustomMetaEventTypes?.TryGetStatusByte(eventType, out statusByte) != true)
                {
                    Debug.Fail($"Unable to write the {eventType} event.");
                }
            }

            writer.WriteByte(statusByte);

            //

            var contentSize = midiEvent.GetSize(settings);

            writer.WriteVlqNumber(contentSize);
            midiEvent.Write(writer, settings);
        }
Пример #8
0
 // Token: 0x060032C4 RID: 12996 RVA: 0x00147BB0 File Offset: 0x00145DB0
 internal sealed override void Write(MidiWriter writer, WritingSettings settings)
 {
     byte[] data = this.Data;
     if (data != null)
     {
         writer.WriteBytes(data);
     }
 }
Пример #9
0
 // Token: 0x06003355 RID: 13141 RVA: 0x00147EB0 File Offset: 0x001460B0
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     byte[] data = this.Data;
     if (data != null)
     {
         writer.WriteBytes(data);
     }
 }
Пример #10
0
 // Token: 0x06003379 RID: 13177 RVA: 0x00017522 File Offset: 0x00015722
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     writer.WriteByte(this.GetFormatAndHours());
     writer.WriteByte(this.Minutes);
     writer.WriteByte(this.Seconds);
     writer.WriteByte(this.Frames);
     writer.WriteByte(this.SubFrames);
 }
Пример #11
0
 // Token: 0x06003231 RID: 12849 RVA: 0x00146E38 File Offset: 0x00145038
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     this.ProcessEvents(settings, delegate(IEventWriter eventWriter, MidiEvent midiEvent, bool writeStatusByte)
     {
         writer.WriteVlqNumber(midiEvent.DeltaTime);
         eventWriter.Write(midiEvent, writer, settings, writeStatusByte);
     });
 }
Пример #12
0
 /// <summary>
 /// Writes content of a <see cref="TrackChunk"/>.
 /// </summary>
 /// <remarks>
 /// Content of a <see cref="TrackChunk"/> is collection of MIDI events.
 /// </remarks>
 /// <param name="writer">Writer to write the chunk's content with.</param>
 /// <param name="settings">Settings according to which the chunk's content must be written.</param>
 /// <exception cref="ObjectDisposedException">Method was called after the writer's underlying stream was disposed.</exception>
 /// <exception cref="IOException">An I/O error occurred on the writer's underlying stream.</exception>
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     ProcessEvents(settings, (eventWriter, midiEvent, writeStatusByte) =>
     {
         writer.WriteVlqNumber(midiEvent.DeltaTime);
         eventWriter.Write(midiEvent, writer, settings, writeStatusByte);
     });
 }
Пример #13
0
        // Token: 0x06003228 RID: 12840 RVA: 0x00146D90 File Offset: 0x00144F90
        internal void Write(MidiWriter writer, WritingSettings settings)
        {
            writer.WriteString(this.ChunkId);
            uint contentSize = this.GetContentSize(settings);

            writer.WriteDword(contentSize);
            this.WriteContent(writer, settings);
        }
Пример #14
0
        /// <summary>
        /// Writes current <see cref="MidiFile"/> to the stream.
        /// </summary>
        /// <param name="stream">Stream to write file's data to.</param>
        /// <param name="format">Format of the file to be written.</param>
        /// <param name="settings">Settings according to which the file must be written.</param>
        /// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="stream"/> does not support writing,
        /// or is already closed.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="format"/> specified an invalid value.</exception>
        /// <exception cref="InvalidOperationException">Time division is null.</exception>
        /// <exception cref="TooManyTrackChunksException">Count of track chunks presented in the file
        /// exceeds maximum value allowed for MIDI file.</exception>
        private void Write(Stream stream, MidiFileFormat format = MidiFileFormat.MultiTrack, WritingSettings settings = null)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!Enum.IsDefined(typeof(MidiFileFormat), format))
            {
                throw new InvalidEnumArgumentException(nameof(format), (int)format, typeof(MidiFileFormat));
            }

            if (TimeDivision == null)
            {
                throw new InvalidOperationException("Time division is null.");
            }

            //

            if (settings == null)
            {
                settings = new WritingSettings();
            }

            using (var writer = new MidiWriter(stream))
            {
                var chunksConverter = ChunksConverterFactory.GetConverter(format);
                var chunks          = chunksConverter.Convert(Chunks);

                var trackChunksCount = chunks.Count(c => c is TrackChunk);
                if (trackChunksCount > ushort.MaxValue)
                {
                    throw new TooManyTrackChunksException(
                              $"Count of track chunks to be written ({trackChunksCount}) is greater than the valid maximum ({ushort.MaxValue}).",
                              trackChunksCount);
                }

                var headerChunk = new HeaderChunk
                {
                    FileFormat   = (ushort)format,
                    TimeDivision = TimeDivision,
                    TracksNumber = (ushort)trackChunksCount
                };
                headerChunk.Write(writer, settings);

                foreach (var chunk in chunks)
                {
                    if (settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteUnknownChunks) && chunk is UnknownChunk)
                    {
                        continue;
                    }

                    chunk.Write(writer, settings);
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Writes chunk to the <see cref="MidiWriter"/>'s underlying stream according to
        /// specified <see cref="WritingSettings"/>.
        /// </summary>
        /// <param name="writer">Writer to write the chunk's data with.</param>
        /// <param name="settings">Settings according to which the chunk's data must be written.</param>
        /// <exception cref="ObjectDisposedException">
        /// Method was called after <paramref name="writer"/> was disposed.
        /// </exception>
        /// <exception cref="IOException">
        /// An I/O error occurred on the <paramref name="writer"/>'s underlying stream.
        /// </exception>
        internal void Write(MidiWriter writer, WritingSettings settings)
        {
            writer.WriteString(ChunkId);

            var size = GetContentSize(settings);

            writer.WriteDword(size);

            WriteContent(writer, settings);
        }
Пример #16
0
        // Token: 0x06003305 RID: 13061 RVA: 0x00147E28 File Offset: 0x00146028
        protected sealed override void WriteContent(MidiWriter writer, WritingSettings settings)
        {
            string text = this.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }
            byte[] bytes = (settings.TextEncoding ?? SmfUtilities.DefaultEncoding).GetBytes(text);
            writer.WriteBytes(bytes);
        }
        internal override void Write(MidiWriter writer, WritingSettings settings)
        {
            var component = Component;

            var componentValueMask = ComponentValueMasks[component];
            var componentValue     = ComponentValue & componentValueMask;

            var data = DataTypesUtilities.Combine((FourBitNumber)(byte)component,
                                                  (FourBitNumber)(byte)componentValue);

            writer.WriteByte(data);
        }
Пример #18
0
 // Token: 0x060033B0 RID: 13232 RVA: 0x00148648 File Offset: 0x00146848
 public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
 {
     if (writeStatusByte)
     {
         Type type = midiEvent.GetType();
         byte number;
         StandardEventTypes.Channel.TryGetStatusByte(type, out number);
         FourBitNumber channel = ((ChannelEvent)midiEvent).Channel;
         byte          value   = DataTypesUtilities.Combine((FourBitNumber)number, channel);
         writer.WriteByte(value);
     }
     midiEvent.Write(writer, settings);
 }
        /// <summary>
        /// Writes content of a MIDI meta event.
        /// </summary>
        /// <param name="writer">Writer to write the content with.</param>
        /// <param name="settings">Settings according to which the event's content must be written.</param>
        protected sealed override void WriteContent(MidiWriter writer, WritingSettings settings)
        {
            var text = Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            var encoding = settings.TextEncoding ?? SmfConstants.DefaultTextEncoding;
            var bytes    = encoding.GetBytes(text);

            writer.WriteBytes(bytes);
        }
Пример #20
0
        // Token: 0x060033BF RID: 13247 RVA: 0x00148774 File Offset: 0x00146974
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (writeStatusByte)
            {
                Type type = midiEvent.GetType();
                byte value;
                StandardEventTypes.SysEx.TryGetStatusByte(type, out value);
                writer.WriteByte(value);
            }
            int size = midiEvent.GetSize(settings);

            writer.WriteVlqNumber(size);
            midiEvent.Write(writer, settings);
        }
Пример #21
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (midiEvent == null)
            {
                throw new ArgumentNullException(nameof(midiEvent));
            }

            if (!(midiEvent is MetaEvent))
            {
                throw new ArgumentException("Event is not Meta event.", nameof(midiEvent));
            }

            //

            if (writeStatusByte)
            {
                writer.WriteByte(EventStatusBytes.Global.Meta);
            }

            //

            byte statusByte;

            var unknownMetaEvent = midiEvent as UnknownMetaEvent;

            if (unknownMetaEvent != null)
            {
                statusByte = unknownMetaEvent.StatusByte;
            }
            else
            {
                var eventType = midiEvent.GetType();
                if (!StandardEventTypes.Meta.TryGetStatusByte(eventType, out statusByte) && settings.CustomMetaEventTypes?.TryGetStatusByte(eventType, out statusByte) != true)
                {
                    throw new InvalidOperationException($"Unable to write the {eventType} event.");
                }
            }

            writer.WriteByte(statusByte);

            //

            var contentSize = midiEvent.GetSize();

            writer.WriteVlqNumber(contentSize);
            midiEvent.Write(writer, settings);
        }
Пример #22
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (writeStatusByte)
            {
                var eventType = midiEvent.GetType();

                byte statusByte;
                if (!StandardEventTypes.SystemRealTime.TryGetStatusByte(eventType, out statusByte))
                {
                    Debug.Fail($"Unable to write the {eventType} event.");
                }

                writer.WriteByte(statusByte);
            }

            midiEvent.Write(writer, settings);
        }
Пример #23
0
 // Token: 0x0600340F RID: 13327 RVA: 0x00148AE4 File Offset: 0x00146CE4
 public void Write(Stream stream, MidiFileFormat format = MidiFileFormat.MultiTrack, WritingSettings settings = null)
 {
     if (this.TimeDivision == null)
     {
         throw new InvalidOperationException("Time division is null.");
     }
     if (!stream.CanWrite)
     {
         throw new ArgumentException("Stream doesn't support writing.", "stream");
     }
     if (settings == null)
     {
         settings = new WritingSettings();
     }
     using (MidiWriter midiWriter = new MidiWriter(stream))
     {
         IEnumerable <MidiChunk> enumerable = ChunksConverterFactory.GetConverter(format).Convert(this.Chunks);
         int num = enumerable.Count((MidiChunk c) => c is TrackChunk);
         if (num > 65535)
         {
             throw new TooManyTrackChunksException(string.Format("Count of track chunks to be written ({0}) is greater than the valid maximum ({1}).", num, ushort.MaxValue), num);
         }
         new HeaderChunk
         {
             FileFormat   = (ushort)format,
             TimeDivision = this.TimeDivision,
             TracksNumber = (ushort)num
         }.Write(midiWriter, settings);
         foreach (MidiChunk midiChunk in enumerable)
         {
             if (!settings.CompressionPolicy.HasFlag(CompressionPolicy.DeleteUnknownChunks) || !(midiChunk is UnknownChunk))
             {
                 midiChunk.Write(midiWriter, settings);
             }
         }
     }
 }
Пример #24
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (midiEvent == null)
            {
                throw new ArgumentNullException(nameof(midiEvent));
            }

            var sysExEvent = midiEvent as SysExEvent;

            if (sysExEvent == null)
            {
                throw new ArgumentException("Event is not SysEx event.", nameof(midiEvent));
            }

            //

            if (writeStatusByte)
            {
                var eventType = midiEvent.GetType();

                byte statusByte;
                if (!StandardEventTypes.SysEx.TryGetStatusByte(eventType, out statusByte))
                {
                    throw new InvalidOperationException($"Unable to write the {eventType} event.");
                }

                writer.WriteByte(statusByte);
            }

            //

            var contentSize = midiEvent.GetSize();

            writer.WriteVlqNumber(contentSize);
            midiEvent.Write(writer, settings);
        }
Пример #25
0
        public void Write(MidiEvent midiEvent, MidiWriter writer, WritingSettings settings, bool writeStatusByte)
        {
            if (midiEvent == null)
            {
                throw new ArgumentNullException(nameof(midiEvent));
            }

            var channelEvent = midiEvent as ChannelEvent;

            if (channelEvent == null)
            {
                throw new ArgumentException("Event is not Channel event.", nameof(midiEvent));
            }

            //

            if (writeStatusByte)
            {
                var eventType = midiEvent.GetType();

                byte statusByte;
                if (!StandardEventTypes.Channel.TryGetStatusByte(eventType, out statusByte))
                {
                    throw new InvalidOperationException($"Unable to write the {eventType} event.");
                }

                var channel = channelEvent.Channel;

                var totalStatusByte = DataTypesUtilities.Combine((FourBitNumber)statusByte, channel);
                writer.WriteByte(totalStatusByte);
            }

            //

            midiEvent.Write(writer, settings);
        }
 /// <summary>
 /// Writes content of a <see cref="HeaderChunk"/>.
 /// </summary>
 /// <remarks>
 /// Content of a <see cref="HeaderChunk"/> is format of the file, number of track chunks and time division.
 /// Six bytes required to write all of this information.
 /// </remarks>
 /// <param name="writer">Writer to write the chunk's content with.</param>
 /// <param name="settings">Settings according to which the chunk's content must be written.</param>
 /// <exception cref="ObjectDisposedException">Method was called after the writer's underlying stream was disposed.</exception>
 /// <exception cref="IOException">An I/O error occurred on the writer's underlying stream.</exception>
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     writer.WriteWord(FileFormat);
     writer.WriteWord(TracksNumber);
     writer.WriteInt16(TimeDivision.ToInt16());
 }
Пример #27
0
 // Token: 0x0600334C RID: 13132 RVA: 0x000172F7 File Offset: 0x000154F7
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     writer.WriteWord(this.Number);
 }
Пример #28
0
 // Token: 0x0600330C RID: 13068 RVA: 0x0001704D File Offset: 0x0001524D
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     writer.WriteByte(this.Channel);
 }
 /// <summary>
 /// Writes content of a MIDI meta event.
 /// </summary>
 /// <param name="writer">Writer to write the content with.</param>
 /// <param name="settings">Settings according to which the event's content must be written.</param>
 protected override void WriteContent(MidiWriter writer, WritingSettings settings)
 {
     _smpteData.Write(writer.WriteByte);
 }
Пример #30
0
 /// <summary>
 /// Writes content of a chunk. Content is a part of chunk's data without its header (ID and size).
 /// </summary>
 /// <param name="writer">Writer to write the chunk's content with.</param>
 /// <param name="settings">Settings according to which the chunk's content must be written.</param>
 protected abstract void WriteContent(MidiWriter writer, WritingSettings settings);