Пример #1
0
        static void Main(string[] args)
        {
            const int frequencty = 44100;

            MidiConnector connector;

            if (args.Any(s => !s.StartsWith("-")))
            {
                connector = new SmfConnector(frequencty);
                ((SmfConnector)connector).Load(args.First(s => !s.StartsWith("-")));
            }
            else
            {
                connector = new MidiInConnector(frequencty, 0);
            }

            foreach (var preset in args.Where(a => a.StartsWith("-p:")).Select(a => a.Substring(3)))
            {
                Console.Write("Preset: " + preset);
                connector.AddPreset(preset);
                Console.WriteLine(" ... [OK]");
            }

            Console.WriteLine("[q] Quit, [r] Reload Presets");

            Func <float[], int, int, int> process = (buffer, offset, count) => connector.Master.Read(buffer, offset, count);

            var setting = new PlayerSettings()
            {
                BufferSize = 512, BufferCount = 64, BitPerSample = 16, SamplingFrequency = frequencty
            };

            using (var l = new SinglePlayer(process, setting))
            {
                Console.WriteLine("Playing!");
                l.Play();
                connector.Play();

                var end = false;

                do
                {
                    switch (Console.ReadKey(true).Key)
                    {
                    case ConsoleKey.Q:
                        end = true;
                        break;

                    case ConsoleKey.R:
                        connector.ReloadPreset();
                        break;

                    default:
                        break;
                    }
                } while (!end);
            }

            connector.Stop();
        }
Пример #2
0
        private void hScrollBar_Scroll(object sender, ScrollEventArgs e)
        {
            if (this.mode_smf && this.playing)
            {
                SmfConnector smf = (SmfConnector)this.connector;

                if (smf.Sequencer != null)
                {
                    smf.Sequencer.Tick = this.hScrollBar.Value;
                    this.connector.Master.Silence();
                }
            }
        }
Пример #3
0
        private void slowTimer_Tick(object sender, EventArgs e)
        {
            if (this.mode_smf)
            {
                SmfConnector smf = (SmfConnector)this.connector;

                if (smf.Sequence != null && smf.Sequencer != null)
                {
                    if (smf.Sequencer.Tick >= 0 && this.hScrollBar.Maximum >= smf.Sequencer.Tick)
                    {
                        this.hScrollBar.Value = (int)smf.Sequencer.Tick;
                    }

                    this.label_tempo.Text = smf.Sequencer.Tempo.ToString("f1");
                }
            }
        }
Пример #4
0
        private void OpenSmfFile()
        {
            if (!this.mode_smf)
            {
                return;
            }

            if (this.smfFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (this.playing)
                {
                    this.connector.Stop();
                    this.connector.Reset();
                }

                SmfConnector smf = (SmfConnector)this.connector;
                smf.Load(this.smfFileDialog.FileName);
                smf.Sequencer.SequenceEnd  += (sender, e) => this.Stop(false);
                smf.Sequencer.OnTrackEvent += (sender, e) =>
                {
                    foreach (MetaEvent meta in e.Events.Where(m => m is MetaEvent && ((MetaEvent)m).MetaType == MetaType.Lyrics))
                    {
                        this.Invoke(new Action(() => this.label_title.Text = this.sjis.GetString(meta.Data).Trim()));
                    }
                };

                this.label_resolution.Text  = smf.Sequence.Resolution.ToString();
                this.label_tick_right.Text  = smf.Sequence.MaxTick.ToString();
                this.hScrollBar.SmallChange = smf.Sequence.Resolution;
                this.hScrollBar.LargeChange = smf.Sequence.Resolution * 4;

                MetaEvent title = (MetaEvent)smf.Sequence.Tracks.SelectMany(t => t.Events).Where(e => e is MetaEvent && ((MetaEvent)e).MetaType == MetaType.TrackName).FirstOrDefault();

                if (title != null)
                {
                    this.label_title.Text = this.sjis.GetString(title.Data).Trim();
                }

                this.hScrollBar.Maximum = (int)smf.Sequence.MaxTick;

                if (this.playing)
                {
                    this.connector.Play();
                }
            }
        }
Пример #5
0
        private void fastTimer_Tick(object sender, EventArgs e)
        {
            if (this.mode_smf)
            {
                SmfConnector smf = (SmfConnector)this.connector;

                if (smf.Sequence != null && smf.Sequencer != null)
                {
                    long tmp = smf.Sequencer.Tick;

                    if (tmp > smf.Sequence.MaxTick)
                    {
                        tmp = smf.Sequence.MaxTick;
                    }
                    else if (tmp < 0)
                    {
                        tmp = 0;
                    }

                    this.label_tick_left.Text = tmp.ToString();
                }
            }
        }