public static void Play(MidiEvent ev)
 {
     lock (_midiLock)
     {
         if (ev is VoiceMidiEvent)
         {
             MidiInterop.SendMidiMessage(_handle, ((VoiceMidiEvent) ev).Message);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>Creates an object creation expression for an event.</summary>
        /// <param name="ev">The event to create.</param>
        /// <returns>The object creation expression for the event.</returns>
        private static CodeObjectCreateExpression CreateEvent(MidiEvent ev)
        {
            CodeObjectCreateExpression newEvent = null;

            // Generate correct event object
            if (ev is SystemExclusiveMidiEvent) newEvent = CreateSystemEvent(ev);
            else if (ev is MetaMidiEvent) newEvent = CreateMetaEvent(ev);
            else if (ev is VoiceMidiEvent) newEvent = CreateVoiceEvent(ev);

            // Return the event
            return newEvent;
        }
 public MidiEventCollection(MidiEvent[] events)
 {
     if (events == null)
     {
         throw new ArgumentNullException("events");
     }
     this._events = new ArrayList(events.Length);
     foreach (MidiEvent event2 in events)
     {
         this._events.Add(event2);
     }
 }
 private static CodeObjectCreateExpression CreateEvent(MidiEvent ev)
 {
     CodeObjectCreateExpression expression = null;
     if (ev is SystemExclusiveMidiEvent)
     {
         return CreateSystemEvent(ev);
     }
     if (ev is MetaMidiEvent)
     {
         return CreateMetaEvent(ev);
     }
     if (ev is VoiceMidiEvent)
     {
         expression = CreateVoiceEvent(ev);
     }
     return expression;
 }
 public virtual void Remove(MidiEvent message)
 {
     this._events.Remove(message);
 }
 public virtual void Insert(int index, MidiEvent message)
 {
     this._events.Insert(index, message);
 }
 public virtual void CopyTo(MidiEvent[] array, int index)
 {
     ((ICollection) this).CopyTo(array, index);
 }
 public virtual bool Contains(MidiEvent message)
 {
     return this._events.Contains(message);
 }
Exemplo n.º 9
0
        /// <summary>Creates an object creation expression for an event.</summary>
        /// <param name="ev">The event to create.</param>
        /// <returns>The object creation expression for the event.</returns>
        private static CodeObjectCreateExpression CreateMetaEvent(MidiEvent ev)
        {
            CodeObjectCreateExpression newEvent = null;
            CodeExpression delta = new CodePrimitiveExpression(ev.DeltaTime);

            // SEQUENCE NUMBER
            if (ev is SequenceNumber)
            {
                SequenceNumber midiEvent = (SequenceNumber)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(SequenceNumber),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Number)
                                        });
            }

            // TEXT
            else if (ev is Text)
            {
                Text midiEvent = (Text)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Text),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // Copyright
            else if (ev is Copyright)
            {
                Copyright midiEvent = (Copyright)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Copyright),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // SEQUENCE TRACK NAME
            else if (ev is SequenceTrackName)
            {
                SequenceTrackName midiEvent = (SequenceTrackName)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(SequenceTrackName),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // INSTRUMENT
            else if (ev is Instrument)
            {
                Instrument midiEvent = (Instrument)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Instrument),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // Lyric
            else if (ev is Lyric)
            {
                Lyric midiEvent = (Lyric)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Lyric),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // Marker
            else if (ev is Marker)
            {
                Marker midiEvent = (Marker)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Marker),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // CuePoint
            else if (ev is CuePoint)
            {
                CuePoint midiEvent = (CuePoint)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(CuePoint),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // ProgramName
            else if (ev is ProgramName)
            {
                ProgramName midiEvent = (ProgramName)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(ProgramName),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // ProgramName
            else if (ev is DeviceName)
            {
                DeviceName midiEvent = (DeviceName)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(DeviceName),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Text)
                                        });
            }

                // ChannelPrefix
            else if (ev is ChannelPrefix)
            {
                ChannelPrefix midiEvent = (ChannelPrefix)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(ChannelPrefix),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Prefix)
                                        });
            }

                // MidiPort
            else if (ev is MidiPort)
            {
                MidiPort midiEvent = (MidiPort)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(MidiPort),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Port)
                                        });
            }

                // EndOfTrack
            else if (ev is EndOfTrack)
            {
                EndOfTrack midiEvent = (EndOfTrack)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(EndOfTrack),
                    new CodeExpression[]{
                                            delta
                                        });
            }

                // Tempo
            else if (ev is Tempo)
            {
                Tempo midiEvent = (Tempo)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Tempo),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Value)
                                        });
            }

                // SMPTEOffset
            else if (ev is SMPTEOffset)
            {
                SMPTEOffset midiEvent = (SMPTEOffset)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(SMPTEOffset),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Hours),
                                            new CodePrimitiveExpression(midiEvent.Minutes),
                                            new CodePrimitiveExpression(midiEvent.Seconds),
                                            new CodePrimitiveExpression(midiEvent.Frames),
                                            new CodePrimitiveExpression(midiEvent.FractionalFrames)
                                        });
            }

                // TimeSignature
            else if (ev is TimeSignature)
            {
                TimeSignature midiEvent = (TimeSignature)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(TimeSignature),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Numerator),
                                            new CodePrimitiveExpression(midiEvent.Denominator),
                                            new CodePrimitiveExpression(midiEvent.MidiClocksPerClick),
                                            new CodePrimitiveExpression(midiEvent.NumberOfNotated32nds)
                                        });
            }

                // KeySignature
            else if (ev is KeySignature)
            {
                KeySignature midiEvent = (KeySignature)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(KeySignature),
                    new CodeExpression[]{
                                            delta,
                                            new CodeCastExpression(typeof(Key), new CodePrimitiveExpression((byte)midiEvent.Key)),
                                            new CodeCastExpression(typeof(Tonality), new CodePrimitiveExpression((byte)midiEvent.Tonality))
                                        });
            }

                // Proprietary
            else if (ev is Proprietary)
            {
                Proprietary midiEvent = (Proprietary)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Proprietary),
                    new CodeExpression[]{
                                            delta,
                                            CreateDataArray(midiEvent.Data)
                                        });
            }

                // UnknownMetaMidiEvent
            else if (ev is UnknownMetaMidiEvent)
            {
                UnknownMetaMidiEvent midiEvent = (UnknownMetaMidiEvent)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(UnknownMetaMidiEvent),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.MetaEventID),
                                            CreateDataArray(midiEvent.Data)
                                        });
            }

            // Return the event
            return newEvent;
        }
 private static CodeObjectCreateExpression CreateVoiceEvent(MidiEvent ev)
 {
     CodeObjectCreateExpression expression = null;
     CodeExpression expression2 = new CodePrimitiveExpression(ev.DeltaTime);
     if (ev is NoteOn)
     {
         NoteOn on = (NoteOn) ev;
         return new CodeObjectCreateExpression(typeof(NoteOn), new CodeExpression[] { expression2, new CodePrimitiveExpression(on.Channel), new CodePrimitiveExpression(MidiEvent.GetNoteName(on.Note)), new CodePrimitiveExpression(on.Velocity) });
     }
     if (ev is NoteOff)
     {
         NoteOff off = (NoteOff) ev;
         return new CodeObjectCreateExpression(typeof(NoteOff), new CodeExpression[] { expression2, new CodePrimitiveExpression(off.Channel), new CodePrimitiveExpression(MidiEvent.GetNoteName(off.Note)), new CodePrimitiveExpression(off.Velocity) });
     }
     if (ev is Aftertouch)
     {
         Aftertouch aftertouch = (Aftertouch) ev;
         return new CodeObjectCreateExpression(typeof(Aftertouch), new CodeExpression[] { expression2, new CodePrimitiveExpression(aftertouch.Channel), new CodePrimitiveExpression(MidiEvent.GetNoteName(aftertouch.Note)), new CodePrimitiveExpression(aftertouch.Pressure) });
     }
     if (ev is ProgramChange)
     {
         ProgramChange change = (ProgramChange) ev;
         return new CodeObjectCreateExpression(typeof(ProgramChange), new CodeExpression[] { expression2, new CodePrimitiveExpression(change.Channel), new CodeCastExpression(typeof(GeneralMidiInstruments), new CodePrimitiveExpression(change.Number)) });
     }
     if (ev is Controller)
     {
         Controller controller = (Controller) ev;
         return new CodeObjectCreateExpression(typeof(Controller), new CodeExpression[] { expression2, new CodePrimitiveExpression(controller.Channel), new CodeCastExpression(typeof(Controllers), new CodePrimitiveExpression(controller.Number)), new CodePrimitiveExpression(controller.Value) });
     }
     if (ev is ChannelPressure)
     {
         ChannelPressure pressure = (ChannelPressure) ev;
         return new CodeObjectCreateExpression(typeof(ChannelPressure), new CodeExpression[] { expression2, new CodePrimitiveExpression(pressure.Channel), new CodePrimitiveExpression(pressure.Pressure) });
     }
     if (ev is PitchWheel)
     {
         PitchWheel wheel = (PitchWheel) ev;
         expression = new CodeObjectCreateExpression(typeof(PitchWheel), new CodeExpression[] { expression2, new CodePrimitiveExpression(wheel.Channel), new CodePrimitiveExpression(wheel.UpperBits), new CodePrimitiveExpression(wheel.LowerBits) });
     }
     return expression;
 }
Exemplo n.º 11
0
        /// <summary>Creates an object creation expression for an event.</summary>
        /// <param name="ev">The event to create.</param>
        /// <returns>The object creation expression for the event.</returns>
        private static CodeObjectCreateExpression CreateSystemEvent(MidiEvent ev)
        {
            CodeObjectCreateExpression newEvent = null;
            CodeExpression delta = new CodePrimitiveExpression(ev.DeltaTime);

            // SYSTEM EXCLUSIVE
            if (ev is SystemExclusiveMidiEvent)
            {
                SystemExclusiveMidiEvent midiEvent = (SystemExclusiveMidiEvent)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(SystemExclusiveMidiEvent),
                    new CodeExpression[]{
                                            delta,
                                            CreateDataArray(midiEvent.Data)
                                        });
            }

            // Return the event
            return newEvent;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a notechart from the specified midi path and the actual charttype
        /// (i.e. ExpertSingle from notes.mid).  Due to the overhead necessary to
        /// parse a midi file.  I am going to cram all midi->chart operations into
        /// one function call.
        /// This function uses the Toub midi parser which is much faster than Sanford,
        /// but will throw an exception on certian midi files.
        /// </summary>
        /// <param name="chartSelection">
        /// The information on which particular notechart to use.
        /// </param>
        /// <param name="chartInfo">The metadata on the chart.</param>
        /// <param name="BPMChanges">The list of BPM changes for this chart.</param>
        /// <returns>
        /// A filled out Notechart containing the needed information from the *.mid file.
        /// </returns>
        public static Notes ParseMidiInformationToub(ChartSelection chartSelection,
                                                     Info chartInfo,
                                                     List <BPMChange> BPMChanges)
        {
            Notes notechartToReturn = new Notes();

            notechartToReturn.instrument = chartSelection.instrument;
            notechartToReturn.difficulty = chartSelection.difficulty;

            // The following two switch's are used to get the proper midi terminology for
            // the selected track and difficulty.
            string instrumentPart = null;
            string greenKey       = null;
            string redKey         = null;
            string yellowKey      = null;
            string blueKey        = null;
            string orangeKey      = null;

            switch (chartSelection.instrument)
            {
            case "Single":
                instrumentPart = "PART GUITAR";
                break;

            case "DoubleGuitar":
                instrumentPart = "PART GUITAR COOP";
                break;

            case "DoubleBass":
                instrumentPart = "PART BASS";
                break;

            case "Drums":
                instrumentPart = "PART DRUMS";
                break;

            default:
                instrumentPart = "PART GUITAR";
                break;
            }

            switch (chartSelection.difficulty)
            {
            case "Expert":
                greenKey  = "C8";
                redKey    = "C#8";
                yellowKey = "D8";
                blueKey   = "D#8";
                orangeKey = "E8";
                break;

            case "Hard":
                greenKey  = "C7";
                redKey    = "C#7";
                yellowKey = "D7";
                blueKey   = "D#7";
                orangeKey = "E7";
                break;

            case "Medium":
                greenKey  = "C6";
                redKey    = "C#6";
                yellowKey = "D6";
                blueKey   = "D#6";
                orangeKey = "E6";
                break;

            case "Easy":
                greenKey  = "C5";
                redKey    = "C#5";
                yellowKey = "D5";
                blueKey   = "D#5";
                orangeKey = "E5";
                break;

            default:
                greenKey  = "C8";
                redKey    = "C#8";
                yellowKey = "D8";
                blueKey   = "D#8";
                orangeKey = "E8";
                break;
            }

            MidiSequence mySequence = MidiSequence.Import(chartSelection.directory + "\\notes.mid");

            MidiTrack[] myTracks = mySequence.GetTracks();
            chartInfo.resolution = mySequence.Division;

            MidiTrack trackToUse     = new MidiTrack();
            uint      totalTickValue = 0;

            // Go through each event in the first track (which contains the BPM changes)
            // and parse the resulting string.
            for (int i = 0; i < myTracks[0].Events.Count; i++)
            {
                Toub.Sound.Midi.MidiEvent currEvent = myTracks[0].Events[i];
                string   eventString      = currEvent.ToString();
                string[] splitEventString = eventString.Split('\t');

                // Since ticks are stored relative to each other (e.g. 300 ticks
                // until next note), we must maintain the total tick amout.
                totalTickValue += Convert.ToUInt32(splitEventString[1]);
                if (splitEventString[0] == "Tempo")
                {
                    // In midi files, bpm chages are stored as "microseconds per quarter note"
                    // and must be converted to BPM, and then into the non decimal format the game
                    // uses.
                    double currBPMDouble = 60000000 / Convert.ToDouble(splitEventString[3]);
                    uint   BPMToAdd      = (uint)(currBPMDouble * 1000);
                    BPMChanges.Add(new BPMChange(totalTickValue, BPMToAdd));
                }
            }

            trackToUse = new MidiTrack();
            // Find the specified instrument's track
            foreach (MidiTrack currTrack in myTracks)
            {
                string   trackHeader = currTrack.Events[0].ToString();
                string[] splitHeader = trackHeader.Split('\t');

                // -If we come across a "T1 GEMS" track, we're in GH1 territory.
                // -GH2/FoF has both PART BASS and PART RHYTHM (one or the other depending
                //  on the chart).
                if (((splitHeader[3] == instrumentPart) || (splitHeader[3] == "T1 GEMS")) ||
                    ((splitHeader[3] == "PART RHYTHM") && (instrumentPart == "PART BASS")))
                {
                    trackToUse = currTrack;
                }
            }

            totalTickValue = 0;
            uint currTickValue = 0;
            Note currNote      = new Note();
            bool blankNote     = true;

            // Scan through and record every note specific to the selected difficulty
            for (int i = 0; i < trackToUse.Events.Count; i++)
            {
                string   currEvent  = trackToUse.Events[i].ToString();
                string[] splitEvent = currEvent.Split('\t');
                currTickValue   = Convert.ToUInt32(splitEvent[1]);
                totalTickValue += currTickValue;

                // We need to specify wether a note is blank or not so we don't add
                // blank notes from other difficulties into the chart, but if we have
                // a filled out note, any nonzero tick value means we are moving to a
                // new note, so we must cut our ties and add this note to the chart.
                if ((currTickValue != 0) && !blankNote)
                {
                    notechartToReturn.notes.Add(currNote);
                    currNote  = new Note();
                    blankNote = true;
                }

                // The "0x64" I think means "not was hit."  There is another
                // set of notes that use "0x00" that all appear slightly after
                // the "0x64" notes.
                if ((splitEvent[0] == "NoteOn") && (splitEvent[4] != "0x00"))
                {
                    // Only consider notes within the octave our difficulty is in.
                    if ((splitEvent[3] == greenKey) || (splitEvent[3] == redKey) ||
                        (splitEvent[3] == yellowKey) || (splitEvent[3] == blueKey) ||
                        (splitEvent[3] == orangeKey))
                    {
                        // If it's a new note, we need to setup the tick value of it.
                        if (blankNote)
                        {
                            currNote.tickValue = totalTickValue;
                            blankNote          = false;
                        }
                        if (splitEvent[3] == greenKey)
                        {
                            currNote.addNote(0);
                        }
                        else if (splitEvent[3] == redKey)
                        {
                            currNote.addNote(1);
                        }
                        else if (splitEvent[3] == yellowKey)
                        {
                            currNote.addNote(2);
                        }
                        else if (splitEvent[3] == blueKey)
                        {
                            currNote.addNote(3);
                        }
                        else if (splitEvent[3] == orangeKey)
                        {
                            currNote.addNote(4);
                        }
                    }
                }
            }

            return(notechartToReturn);
        }
Exemplo n.º 13
0
        /// <summary>Intializes the collection.</summary>
        /// <param name="events">The MIDI events with which to initialize the collection.</param>
        public MidiEventCollection(MidiEvent [] events)
        {
            // Validate the input
            if (events == null) throw new ArgumentNullException("events");

            // Initialize the list with the given array of events
            _events = new ArrayList(events.Length);
            foreach(MidiEvent ev in events) _events.Add(ev);
        }
Exemplo n.º 14
0
 /// <summary>Plays an individual MIDI event.</summary>
 /// <param name="ev">The event to be played.</param>
 /// <remarks>
 /// Only VoiceMidiEvent's are actually sent to the MIDI device.
 /// Delta-times are ignored.
 /// OpenMidi must be called before calling Play.  CloseMidi should
 /// be called once all events have been played to free up the device.
 /// </remarks>
 public static void Play(MidiEvent ev)
 {
     lock(_midiLock)
     {
         // Only send voice messages
         if (ev is VoiceMidiEvent)
         {
             // Send the MIDI event to the MIDI device
             MidiInterop.SendMidiMessage(_handle, ((VoiceMidiEvent)ev).Message);
         }
     }
 }
 private static CodeObjectCreateExpression CreateMetaEvent(MidiEvent ev)
 {
     CodeObjectCreateExpression expression = null;
     CodeExpression expression2 = new CodePrimitiveExpression(ev.DeltaTime);
     if (ev is SequenceNumber)
     {
         SequenceNumber number = (SequenceNumber) ev;
         return new CodeObjectCreateExpression(typeof(SequenceNumber), new CodeExpression[] { expression2, new CodePrimitiveExpression(number.Number) });
     }
     if (ev is Text)
     {
         Text text = (Text) ev;
         return new CodeObjectCreateExpression(typeof(Text), new CodeExpression[] { expression2, new CodePrimitiveExpression(text.Text) });
     }
     if (ev is Copyright)
     {
         Copyright copyright = (Copyright) ev;
         return new CodeObjectCreateExpression(typeof(Copyright), new CodeExpression[] { expression2, new CodePrimitiveExpression(copyright.Text) });
     }
     if (ev is SequenceTrackName)
     {
         SequenceTrackName name = (SequenceTrackName) ev;
         return new CodeObjectCreateExpression(typeof(SequenceTrackName), new CodeExpression[] { expression2, new CodePrimitiveExpression(name.Text) });
     }
     if (ev is Instrument)
     {
         Instrument instrument = (Instrument) ev;
         return new CodeObjectCreateExpression(typeof(Instrument), new CodeExpression[] { expression2, new CodePrimitiveExpression(instrument.Text) });
     }
     if (ev is Lyric)
     {
         Lyric lyric = (Lyric) ev;
         return new CodeObjectCreateExpression(typeof(Lyric), new CodeExpression[] { expression2, new CodePrimitiveExpression(lyric.Text) });
     }
     if (ev is Marker)
     {
         Marker marker = (Marker) ev;
         return new CodeObjectCreateExpression(typeof(Marker), new CodeExpression[] { expression2, new CodePrimitiveExpression(marker.Text) });
     }
     if (ev is CuePoint)
     {
         CuePoint point = (CuePoint) ev;
         return new CodeObjectCreateExpression(typeof(CuePoint), new CodeExpression[] { expression2, new CodePrimitiveExpression(point.Text) });
     }
     if (ev is ProgramName)
     {
         ProgramName name2 = (ProgramName) ev;
         return new CodeObjectCreateExpression(typeof(ProgramName), new CodeExpression[] { expression2, new CodePrimitiveExpression(name2.Text) });
     }
     if (ev is DeviceName)
     {
         DeviceName name3 = (DeviceName) ev;
         return new CodeObjectCreateExpression(typeof(DeviceName), new CodeExpression[] { expression2, new CodePrimitiveExpression(name3.Text) });
     }
     if (ev is ChannelPrefix)
     {
         ChannelPrefix prefix = (ChannelPrefix) ev;
         return new CodeObjectCreateExpression(typeof(ChannelPrefix), new CodeExpression[] { expression2, new CodePrimitiveExpression(prefix.Prefix) });
     }
     if (ev is MidiPort)
     {
         MidiPort port = (MidiPort) ev;
         return new CodeObjectCreateExpression(typeof(MidiPort), new CodeExpression[] { expression2, new CodePrimitiveExpression(port.Port) });
     }
     if (ev is EndOfTrack)
     {
         EndOfTrack track1 = (EndOfTrack) ev;
         return new CodeObjectCreateExpression(typeof(EndOfTrack), new CodeExpression[] { expression2 });
     }
     if (ev is Tempo)
     {
         Tempo tempo = (Tempo) ev;
         return new CodeObjectCreateExpression(typeof(Tempo), new CodeExpression[] { expression2, new CodePrimitiveExpression(tempo.Value) });
     }
     if (ev is SMPTEOffset)
     {
         SMPTEOffset offset = (SMPTEOffset) ev;
         return new CodeObjectCreateExpression(typeof(SMPTEOffset), new CodeExpression[] { expression2, new CodePrimitiveExpression(offset.Hours), new CodePrimitiveExpression(offset.Minutes), new CodePrimitiveExpression(offset.Seconds), new CodePrimitiveExpression(offset.Frames), new CodePrimitiveExpression(offset.FractionalFrames) });
     }
     if (ev is TimeSignature)
     {
         TimeSignature signature = (TimeSignature) ev;
         return new CodeObjectCreateExpression(typeof(TimeSignature), new CodeExpression[] { expression2, new CodePrimitiveExpression(signature.Numerator), new CodePrimitiveExpression(signature.Denominator), new CodePrimitiveExpression(signature.MidiClocksPerClick), new CodePrimitiveExpression(signature.NumberOfNotated32nds) });
     }
     if (ev is KeySignature)
     {
         KeySignature signature2 = (KeySignature) ev;
         return new CodeObjectCreateExpression(typeof(KeySignature), new CodeExpression[] { expression2, new CodeCastExpression(typeof(Key), new CodePrimitiveExpression((byte) signature2.Key)), new CodeCastExpression(typeof(Tonality), new CodePrimitiveExpression((byte) signature2.Tonality)) });
     }
     if (ev is Proprietary)
     {
         Proprietary proprietary = (Proprietary) ev;
         return new CodeObjectCreateExpression(typeof(Proprietary), new CodeExpression[] { expression2, CreateDataArray(proprietary.Data) });
     }
     if (ev is UnknownMetaMidiEvent)
     {
         UnknownMetaMidiEvent event2 = (UnknownMetaMidiEvent) ev;
         expression = new CodeObjectCreateExpression(typeof(UnknownMetaMidiEvent), new CodeExpression[] { expression2, new CodePrimitiveExpression(event2.MetaEventID), CreateDataArray(event2.Data) });
     }
     return expression;
 }
Exemplo n.º 16
0
        /// <summary>Creates an object creation expression for an event.</summary>
        /// <param name="ev">The event to create.</param>
        /// <returns>The object creation expression for the event.</returns>
        private static CodeObjectCreateExpression CreateVoiceEvent(MidiEvent ev)
        {
            CodeObjectCreateExpression newEvent = null;
            CodeExpression delta = new CodePrimitiveExpression(ev.DeltaTime);

                // NOTE ON
            if (ev is NoteOn)
            {
                NoteOn midiEvent = (NoteOn)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(NoteOn),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodePrimitiveExpression(MidiEvent.GetNoteName(midiEvent.Note)),
                                            new CodePrimitiveExpression(midiEvent.Velocity)
                                        });
            }

                // NOTE OFF
            else if (ev is NoteOff)
            {
                NoteOff midiEvent = (NoteOff)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(NoteOff),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodePrimitiveExpression(MidiEvent.GetNoteName(midiEvent.Note)),
                                            new CodePrimitiveExpression(midiEvent.Velocity)
                                        });
            }

                // AFTERTOUCH
            else if (ev is Aftertouch)
            {
                Aftertouch midiEvent = (Aftertouch)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Aftertouch),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodePrimitiveExpression(MidiEvent.GetNoteName(midiEvent.Note)),
                                            new CodePrimitiveExpression(midiEvent.Pressure)
                                        });
            }

                // PROGRAM CHANGE
            else if (ev is ProgramChange)
            {
                ProgramChange midiEvent = (ProgramChange)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(ProgramChange),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodeCastExpression(typeof(GeneralMidiInstruments), new CodePrimitiveExpression(midiEvent.Number))
                                        });
            }

                // CONTROLLER
            else if (ev is Controller)
            {
                Controller midiEvent = (Controller)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(Controller),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodeCastExpression(typeof(Controllers), new CodePrimitiveExpression(midiEvent.Number)),
                                            new CodePrimitiveExpression(midiEvent.Value),
                                        });
            }

                // CHANNEL PRESSURE
            else if (ev is ChannelPressure)
            {
                ChannelPressure midiEvent = (ChannelPressure)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(ChannelPressure),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodePrimitiveExpression(midiEvent.Pressure)
                });
            }

                // PITCH WHEEL
            else if (ev is PitchWheel)
            {
                PitchWheel midiEvent = (PitchWheel)ev;
                newEvent = new CodeObjectCreateExpression(
                    typeof(PitchWheel),
                    new CodeExpression[]{
                                            delta,
                                            new CodePrimitiveExpression(midiEvent.Channel),
                                            new CodePrimitiveExpression(midiEvent.UpperBits),
                                            new CodePrimitiveExpression(midiEvent.LowerBits)
                                        });
            }

            // Return the event
            return newEvent;
        }
 public virtual int Add(MidiEvent message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     return this._events.Add(message);
 }
 private static CodeObjectCreateExpression CreateSystemEvent(MidiEvent ev)
 {
     CodeObjectCreateExpression expression = null;
     CodeExpression expression2 = new CodePrimitiveExpression(ev.DeltaTime);
     if (ev is SystemExclusiveMidiEvent)
     {
         SystemExclusiveMidiEvent event2 = (SystemExclusiveMidiEvent) ev;
         expression = new CodeObjectCreateExpression(typeof(SystemExclusiveMidiEvent), new CodeExpression[] { expression2, CreateDataArray(event2.Data) });
     }
     return expression;
 }