Example #1
0
File: Program.cs Project: nanase/ux
        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();
        }
Example #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.monitorBuffer = new float[2048];
            this.monitor = new WaveformMonitor(Color.FromArgb(139, 229, 139), this.monitorBox.Size);
            this.monitorBox.Image = this.monitor.Bitmap;

            this.volumeMonitor = new VolumeMonitor(Color.FromArgb(139, 229, 139), this.volumeMonitorBox.Size);
            this.volumeMonitorBox.Image = this.volumeMonitor.Bitmap;

            this.SwitchConnection();

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

                if (this.monitorBuffer.Length != buffer.Length)
                    this.monitorBuffer = new float[buffer.Length];

                buffer.CopyTo(this.monitorBuffer, 0);

                return k;
            };
            var setting = new PlayerSettings() { BufferSize = 1024, BufferCount = 32, BitPerSample = 16, SamplingFrequency = frequencty };
            this.player = new SinglePlayer(process, setting);

            this.playing = true;
            this.Stop();
        }