MIDI に関する一連のイベントを格納したシーケンスを提供します。
Exemplo n.º 1
0
        /// <summary>
        /// SMF ファイルを指定してシーケンサを初期化します。
        /// </summary>
        /// <param name="filename">読み込まれる SMF ファイル。</param>
        public void Load(string filename)
        {
            if (this.sequencer != null)
                this.sequencer.Stop();

            this.sequence = new Sequence(filename);
            this.sequencer = new Sequencer.Sequencer(sequence);

            Console.WriteLine("Loaded: {0}", Path.GetFileName(filename));
            Encoding sjis = Encoding.GetEncoding(932);

            foreach (MetaEvent item in sequence.Tracks.Where(t => t.Number == 0).SelectMany(t => t.Events).Where(e => e is MetaEvent))
            {
                switch (item.MetaType)
                {
                    case MetaType.Text:
                        Console.WriteLine("\tText: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    case MetaType.Copyrights:
                        Console.WriteLine("\tCopyrights: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    case MetaType.TrackName:
                        Console.WriteLine("\tTitle: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    case MetaType.InstrumentName:
                        Console.WriteLine("\tInstrument: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    case MetaType.Lyrics:
                        Console.WriteLine("\tLyrics: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    case MetaType.ProgramName:
                        Console.WriteLine("\tProgram: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    case MetaType.DeviceName:
                        Console.WriteLine("\tDevice: {0}", sjis.GetString(item.Data).Trim());
                        break;
                    default:
                        break;
                }
            }

            Console.WriteLine("\tFormat: {0}, Resolution: {1}", sequence.Format, sequence.Resolution);
            Console.WriteLine("\tTracks: {0}, Events: {1}, MaxTick: {2}", sequence.Tracks.Count(), sequence.EventCount, sequence.MaxTick);
            Console.WriteLine("Frequency: {0:n0} Hz", Stopwatch.Frequency);

            sequencer.OnTrackEvent += (sender, e) =>
            {
                var events = e.Events.ToArray();
                this.EventCount += events.Length;
                this.ProcessMidiEvent(events);
            };
            sequencer.SequenceStarted += (sender, e) => Console.WriteLine("Sequencer Start");
            sequencer.SequenceEnd += (sender, e) => Console.WriteLine("Sequencer End");
            sequencer.SequenceStopped += (sender, e) => Console.WriteLine("Sequencer Stop");
            sequencer.TempoChanged += (sender, e) => Console.WriteLine("Tempo {0:f2} => {1:f2}", e.OldTempo, e.NewTempo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// シーケンスを指定して新しい Sequencer クラスのインスタンスを初期化します。
        /// </summary>
        /// <param name="sequence">一連のイベントが格納されたシーケンス。</param>
        public Sequencer(Sequence sequence)
        {
            if (sequence == null)
                throw new ArgumentNullException();

            this.Sequence = sequence;
            this.events = new List<Event>(sequence.Tracks.SelectMany(t => t.Events).OrderBy(e => e.Tick));
            this.endOfTick = sequence.MaxTick;

            this.tick = -(long)(sequence.Resolution * 1.0);

            this.RecalcTickTime();
        }