Beispiel #1
0
        /// <summary>
        /// Convert a sequence to an MIDI.
        /// </summary>
        /// <param name="d">Sequence data.</param>
        /// <returns>An midi file.</returns>
        public static MidiFile Sequence2Midi(SequenceData d)
        {
            //New midi file.
            MidiFile m = new MidiFile();

            m.Chunks.Add(new TrackChunk());

            //Read each command.
            int nextWaitAmount = 0;

            foreach (SequenceCommand c in d.Commands)
            {
                TrackChunk currTrack = (TrackChunk)m.Chunks[m.Chunks.Count - 1];
                SequenceCommand2MidiCommand(c, m, currTrack, ref nextWaitAmount);
            }

            //Return the file.
            return(m);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            /*
             * MemoryStream src = new MemoryStream(File.ReadAllBytes("tmp.bin"));
             * BinaryDataReader br = new BinaryDataReader(src);
             * br.ByteOrder = ByteOrder.BigEndian;
             * SequenceCommand s = SequenceCommand.Read(br);
             * MemoryStream o = new MemoryStream();
             * BinaryDataWriter bw = new BinaryDataWriter(o);
             * bw.ByteOrder = ByteOrder.BigEndian;
             * s.Write(bw);
             * File.WriteAllBytes("tmp2.bin", o.ToArray());*/

            SequenceData d = new SequenceData();

            d.Read(File.ReadAllBytes("tmp.bin"), ByteOrder.LittleEndian);
            File.WriteAllBytes("tmp2.bin", d.ToBytes(ByteOrder.LittleEndian));
            File.WriteAllLines("out.fseq", d.ToSeqFile("Lancer"));
            //SequenceData d2 = new SequenceData();
            //d2.FromSeqFile(File.ReadAllLines("out.fseq"));

            MidiFile m = MidiGenerator.Sequence2Midi(d);

            m.Write("out.mid", true);

            MidiFile m2 = MidiFile.Read("Lancer.mid",
                                        new ReadingSettings
            {
                NoHeaderChunkPolicy = NoHeaderChunkPolicy.Abort,
            });

            MidiFile m3 = MidiFile.Read("out.mid",
                                        new ReadingSettings
            {
                NoHeaderChunkPolicy = NoHeaderChunkPolicy.Abort,
            });
        }
Beispiel #3
0
        /// <summary>
        /// Write the command.
        /// </summary>
        /// <param name="bw">The writer.</param>
        public void Write(BinaryDataWriter bw, List <SequenceCommand> commands)
        {
            //Write the identifier.
            bw.Write(Identifier);

            //Write each parameter.
            int count = 0;

            foreach (var t in SequenceParameterTypes)
            {
                //Write the item.
                switch (t)
                {
                //U8.
                case SequenceParameterType.u8:
                    bw.Write((byte)Parameters[count]);
                    break;

                //U16.
                case SequenceParameterType.u16:
                    bw.Write((UInt16)Parameters[count]);
                    break;

                //U24.
                case SequenceParameterType.u24:

                    //Uses an offset.
                    if ((CommandType)Identifier == CommandType.Call || (CommandType)Identifier == CommandType.Jump || (CommandType)Identifier == CommandType.OpenTrack)
                    {
                        new UInt24((uint)SequenceData.CommandIndexToOffset(commands, (int)((UInt24)Parameters[count]).Value)).Write(bw);
                    }

                    //Normal.
                    else
                    {
                        ((UInt24)Parameters[count]).Write(bw);
                    }
                    break;

                //U32.
                case SequenceParameterType.u32:
                    bw.Write((UInt32)Parameters[count]);
                    break;

                //U32.
                case SequenceParameterType.u64:
                    bw.Write((UInt64)Parameters[count]);
                    break;

                //S8.
                case SequenceParameterType.s8:
                    bw.Write((sbyte)Parameters[count]);
                    break;

                //S16.
                case SequenceParameterType.s16:
                    bw.Write((Int16)Parameters[count]);
                    break;

                //S32.
                case SequenceParameterType.s32:
                    bw.Write((Int32)Parameters[count]);
                    break;

                //S32.
                case SequenceParameterType.s64:
                    bw.Write((Int64)Parameters[count]);
                    break;

                //Boolean.
                case SequenceParameterType.boolean:
                    bw.Write((bool)Parameters[count]);
                    break;

                //Variable length.
                case SequenceParameterType.VariableLength:
                    VariableLength.WriteVariableLength(bw, (uint)Parameters[count]);
                    break;

                //Sequence command.
                case SequenceParameterType.SeqCommand:
                    ((SequenceCommand)Parameters[count]).Write(bw, commands);
                    break;
                }

                //Increment count.
                count++;
            }
        }