示例#1
0
        public List <Note> MakeScore(string FilePath)
        {
            List <Note> Score = new List <Note>();

            MidiToolKit.Sequence sq = new MidiToolKit.Sequence();
            sq.Load(FilePath);

            Score = NoteMake(sq);

            return(Score);
        }
示例#2
0
        public void Load(Sequence seq)
        {
            // grab the first MIDI device
            if (_MIDIOutDevice == null)
            {
                _MIDIOutDevice = new Midi.OutputDevice(0);
            }

            // load the MIDI file
            _MIDISequence.Load(seq.MusicFile);
            _MIDISequencer.Sequence = _MIDISequence;
        }
示例#3
0
        public void SetFilename(string Filename)
        {
            try
            {
                if ((!FLoading) && (System.IO.File.Exists(Filename)) && (System.IO.Path.GetExtension(Filename) == ".mid"))
                {
                    FSequence.Load(Filename);
                    FFilename = Filename;

                    ParseSequence();
                    OnNotesParsed();

                    FLoading = true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            };
        }
        public static Sequence FromStream(MemoryStream ms)
        {
            Sequence ret = null;

            try
            {
                var seq = new Sequence(FileType.Unknown, 480);
                seq.Load(ms);
                ret = seq;

                if (ret.Any(x => x.Name != null && x.Name.EndsWith("_22")))
                {
                    ret.FileType = FileType.Pro;
                }
                else if (ret.Any(x => x.Name != null && (x.Name.ToLower() == "part guitar" || x.Name.ToLower() == "part bass")))
                {
                    ret.FileType = FileType.Guitar5;
                }
            }
            catch (Exception ex) { Debug.WriteLine(ex.Message); }
            return(ret);
        }
示例#5
0
    public void load()
    {
        if (!SourceAsset)
        {
            Debug.LogError("SourceAsset is null.");
            return;
        }

        MemoryStream stream = new MemoryStream();

        stream.Write(SourceAsset.bytes, 0, SourceAsset.bytes.Length);
        stream.Position = 0;

        MidiSeq = new Midi.Sequence();
        MidiSeq.Load(stream);

        if (TrackHandIndices == null || TrackHandIndices.Length != MidiSeq.Count)
        {
            TrackHandIndices = Enumerable.Repeat(-1, MidiSeq.Count).ToArray();
        }

        Notation = NotationUtils.parseMidiFile(MidiSeq);
    }
示例#6
0
        private void ProcessMIDI()
        {
            Midi.Sequence _MIDISequence;

            // default MIDI tempos/milliseconds per tick
            int   tempo     = 500000;
            float msPerTick = (tempo / 48) / 1000.0f;

            _MIDISequence = new Midi.Sequence();
            _MIDISequence.Load(_sequence.MusicFile);

            if (_MIDISequence.SequenceType != Sanford.Multimedia.Midi.SequenceType.Ppqn)
            {
                MessageBox.Show("Unsupported MIDI type...sorry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            foreach (Midi.Track t in _MIDISequence)
            {
                IEnumerator <Midi.MidiEvent> en = t.Iterator().GetEnumerator();

                while (en.MoveNext())
                {
                    Midi.MidiEvent e = en.Current;
                    switch (e.MidiMessage.MessageType)
                    {
                    // starta  new channel
                    case Sanford.Multimedia.Midi.MessageType.Channel:
                        Midi.ChannelMessage channel = (Midi.ChannelMessage)e.MidiMessage;

                        // if it's a note on command and it's in our mapping list
                        if (channel.Command == Sanford.Multimedia.Midi.ChannelCommand.NoteOn &&
                            _midiMap.ContainsKey(channel.MidiChannel) &&
                            (int)((e.AbsoluteTicks * msPerTick) / 50) < _sequence.Channels[_midiMap[channel.MidiChannel]].Data.Length)
                        {
                            // this means the note is on
                            if (channel.Data2 > 0)
                            {
                                _sequence.Channels[_midiMap[channel.MidiChannel]].Data[(int)((e.AbsoluteTicks * msPerTick) / 50)] = true;
                            }
                            else
                            {
                                // the note is off
                                _sequence.Channels[_midiMap[channel.MidiChannel]].Data[(int)((e.AbsoluteTicks * msPerTick) / 50)] = false;
                                if (chkHold.Checked)
                                {
                                    // backfill the grid
                                    for (int i = (int)((e.AbsoluteTicks * msPerTick) / 50); i > 0 && !_sequence.Channels[_midiMap[channel.MidiChannel]].Data[i]; i--)
                                    {
                                        _sequence.Channels[_midiMap[channel.MidiChannel]].Data[i] = true;
                                    }
                                }
                            }
                        }
                        // true note off...don't see this used much
                        if (channel.Command == Sanford.Multimedia.Midi.ChannelCommand.NoteOff &&
                            _midiMap.ContainsKey(channel.MidiChannel))
                        {
                            _sequence.Channels[_midiMap[channel.MidiChannel]].Data[(int)((e.AbsoluteTicks * msPerTick) / 50)] = false;
                            if (chkHold.Checked)
                            {
                                for (int i = (int)((e.AbsoluteTicks * msPerTick) / 50); i > 0 && !_sequence.Channels[_midiMap[channel.MidiChannel]].Data[i]; i--)
                                {
                                    _sequence.Channels[_midiMap[channel.MidiChannel]].Data[i] = true;
                                }
                            }
                        }
                        break;

                    case Sanford.Multimedia.Midi.MessageType.Meta:
                        Midi.MetaMessage meta = (Midi.MetaMessage)e.MidiMessage;
                        switch (meta.MetaType)
                        {
                        // again, get the tempo value
                        case Sanford.Multimedia.Midi.MetaType.Tempo:
                            tempo     = meta.GetBytes()[0] << 16 | meta.GetBytes()[1] << 8 | meta.GetBytes()[2];
                            msPerTick = (tempo / _MIDISequence.Division) / 1000.0f;
                            break;
                        }
                        break;
                    }
                }
            }
        }
示例#7
0
        private void GetMIDIInfo(string file, bool fillTime)
        {
            Midi.Sequence MIDISequence;

            int    tempo     = 500000;
            int    maxtick   = 0;
            float  msPerTick = (tempo / 48) / 1000.0f;
            string title     = string.Empty;

            _MIDIChannels = new BindingList <MIDIChannel>();

            // load the MIDI file
            MIDISequence = new Midi.Sequence();
            MIDISequence.Load(file);

            // we don't handle non-PPQN MIDI files
            if (MIDISequence.SequenceType != Sanford.Multimedia.Midi.SequenceType.Ppqn)
            {
                MessageBox.Show("Unsupported MIDI type...sorry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            foreach (Midi.Track t in MIDISequence)
            {
                // get the command enumerator
                IEnumerator <Midi.MidiEvent> en = t.Iterator().GetEnumerator();
                bool channelAdded = false;
                while (en.MoveNext())
                {
                    Midi.MidiEvent e = en.Current;
                    switch (e.MidiMessage.MessageType)
                    {
                    case Sanford.Multimedia.Midi.MessageType.Channel:                                   // track the # of channels
                        Midi.ChannelMessage channel = (Midi.ChannelMessage)e.MidiMessage;
                        if (!channelAdded)
                        {
                            _MIDIChannels.Add(new MIDIChannel(channel.MidiChannel, title));
                            channelAdded = true;
                        }
                        break;

                    case Sanford.Multimedia.Midi.MessageType.Meta:
                        Midi.MetaMessage meta = (Midi.MetaMessage)e.MidiMessage;
                        switch (meta.MetaType)
                        {
                        // cache away the track name for the grid
                        case Sanford.Multimedia.Midi.MetaType.TrackName:
                            title = Encoding.ASCII.GetString(meta.GetBytes());
                            break;

                        // get the tempo and convert to a time value we can use
                        case Sanford.Multimedia.Midi.MetaType.Tempo:
                            tempo     = meta.GetBytes()[0] << 16 | meta.GetBytes()[1] << 8 | meta.GetBytes()[2];
                            msPerTick = (tempo / MIDISequence.Division) / 1000.0f;
                            break;
                        }
                        break;
                    }

                    // find the highest time value
                    if (e.AbsoluteTicks > maxtick)
                    {
                        maxtick = e.AbsoluteTicks;
                    }
                }
            }
            // and use that value to fill in the minutes/seconds
            if (fillTime)
            {
                txtMinutes.Text = (((int)(msPerTick * maxtick) / 1000) / 60).ToString();
                txtSeconds.Text = (((int)(msPerTick * maxtick) / 1000) % 60 + 1).ToString();
            }
        }