Esempio n. 1
0
 public Guess()
 {
     random = new Random();
     clock = new Clock(480);
     clock.Start();
     availableNotes = new List<Pitch>();
     availableNotes.Add(Pitch.C3);
     availableNotes.Add(Pitch.CSharp3);
     availableNotes.Add(Pitch.D3);
     availableNotes.Add(Pitch.DSharp3);
     availableNotes.Add(Pitch.E3);
     availableNotes.Add(Pitch.F3);
     availableNotes.Add(Pitch.FSharp3);
     availableNotes.Add(Pitch.G3);
     availableNotes.Add(Pitch.GSharp3);
     availableNotes.Add(Pitch.A3);
     availableNotes.Add(Pitch.ASharp3);
     availableNotes.Add(Pitch.B4);
     availableNotes.Add(Pitch.C4);
     availableNotes.Add(Pitch.CSharp4);
     availableNotes.Add(Pitch.D4);
     availableNotes.Add(Pitch.DSharp4);
     availableNotes.Add(Pitch.E4);
     availableNotes.Add(Pitch.F4);
     availableNotes.Add(Pitch.FSharp4);
     availableNotes.Add(Pitch.G4);
     availableNotes.Add(Pitch.GSharp4);
     availableNotes.Add(Pitch.A4);
     availableNotes.Add(Pitch.ASharp4);
     availableNotes.Add(Pitch.B4);
 }
Esempio n. 2
0
        public override void Run()
        {
            // Prompt user to choose an output device (or if there is only one, use that one).
            OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole();
            if(outputDevice==null) {
                Console.WriteLine("No output devices, so can't run this example.");
                ExampleUtil.PressAnyKeyToContinue();
                return;
            }
            outputDevice.Open();

            Console.WriteLine("Playing an arpeggiated C chord and then bending it down.");
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0);
            outputDevice.SendPitchBend(Channel.Channel1, 8192);

            // Play C, E, G in half second intervals.
            outputDevice.SendNoteOn(Channel.Channel1, Pitch.C4, 80);
            Thread.Sleep(500);
            outputDevice.SendNoteOn(Channel.Channel1, Pitch.E4, 80);
            Thread.Sleep(500);
            outputDevice.SendNoteOn(Channel.Channel1, Pitch.G4, 80);
            Thread.Sleep(500);

            // Now apply the sustain pedal.
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 127);

            // Now release the C chord notes, but they should keep ringing because of the sustain pedal.
            outputDevice.SendNoteOff(Channel.Channel1, Pitch.C4, 80);
            outputDevice.SendNoteOff(Channel.Channel1, Pitch.E4, 80);
            outputDevice.SendNoteOff(Channel.Channel1, Pitch.G4, 80);

            // Now bend the pitches down.
            for(int i=0; i<17; ++i) {
                outputDevice.SendPitchBend(Channel.Channel1, 8192 - i * 450);
                Thread.Sleep(200);
            }

            // Now release the sustain pedal, which should silence the notes, then center the pitch bend again.
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0);
            outputDevice.SendPitchBend(Channel.Channel1, 8192);

            Console.WriteLine("Playing the first two bars of Mary Had a Little Lamb...");
            Clock clock = new Clock(120);
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 0));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 1));
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.D4, 80, 1));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.D4, 80, 2));
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.C4, 80, 2));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.C4, 80, 3));
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.D4, 80, 3));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.D4, 80, 4));
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 4));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 5));
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 5));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 6));
            clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 6));
            clock.Schedule(new NoteOffMessage(outputDevice, Channel.Channel1, Pitch.E4, 80, 7));
            clock.Start();
            Thread.Sleep(5000);
            clock.Stop();

            Console.WriteLine("Playing sustained chord runs up the keyboard...");
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 127);
            PlayChordRun(outputDevice, new Chord("C"), 100);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 127);
            PlayChordRun(outputDevice, new Chord("F"), 100);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 127);
            PlayChordRun(outputDevice, new Chord("G"), 100);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 127);
            PlayChordRun(outputDevice, new Chord("C"), 100);
            Thread.Sleep(2000);
            outputDevice.SendControlChange(Channel.Channel1, Control.SustainPedal, 0);

            // Close the output device.
            outputDevice.Close();

            // All done.
            Console.WriteLine();
            ExampleUtil.PressAnyKeyToContinue();
        }
Esempio n. 3
0
        public override void Run()
        {
            // Create a clock running at the specified beats per minute.
            int beatsPerMinute = 180;
            Clock clock = new Clock(beatsPerMinute);
            
            // Utility function prompts user to choose an output device (or if there is only one,
            // returns that one).
            OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole();
            if (outputDevice == null)
            {
                Console.WriteLine("No output devices, so can't run this example.");
                ExampleUtil.PressAnyKeyToContinue();
                return;
            }
            outputDevice.Open();

            // Utility function prompts user to choose an input device (or if there is only one,
            // returns that one).
            InputDevice inputDevice = ExampleUtil.ChooseInputDeviceFromConsole();
            if (inputDevice != null)
            {
                inputDevice.Open();
            }

            Arpeggiator arpeggiator = new Arpeggiator(inputDevice, outputDevice, clock);

            Console.WriteLine("Press Escape when finished.");

            clock.Start();
            if (inputDevice != null)
            {
                inputDevice.StartReceiving(clock);
            }

            while (true)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey(true);
                if (keyInfo.Key == ConsoleKey.Escape)
                {
                    break;
                }
                Note note;
                if (ExampleUtil.IsMockNote(keyInfo.Key, out note))
                {
                    NoteOnMessage noteOn = new NoteOnMessage(outputDevice, 0, note, 100,
                        clock.BeatTime);
                    NoteOffMessage noteOff = new NoteOffMessage(outputDevice, 0, note, 100,
                        clock.BeatTime+1);
                    clock.Schedule(noteOn);
                    clock.Schedule(noteOff);
                    arpeggiator.NoteOn(noteOn);
                    arpeggiator.NoteOff(noteOff);
                }
            }

            clock.Stop();

            // Close the devices.
            outputDevice.Close();

            if (inputDevice != null)
            {
                inputDevice.StopReceiving();
                inputDevice.Close();
            }

            // All done.
        }
Esempio n. 4
0
        public override void Run()
        {
            // Create a clock running at the specified beats per minute.
            int beatsPerMinute = 180;
            Clock clock = new Clock(beatsPerMinute);

            // Prompt user to choose an output device (or if there is only one, use that one.
            OutputDevice outputDevice = ExampleUtil.ChooseOutputDeviceFromConsole();
            if (outputDevice == null)
            {
                Console.WriteLine("No output devices, so can't run this example.");
                ExampleUtil.PressAnyKeyToContinue();
                return;
            }
            outputDevice.Open();

            // Prompt user to choose an input device (or if there is only one, use that one).
            InputDevice inputDevice = ExampleUtil.ChooseInputDeviceFromConsole();
            if (inputDevice != null)
            {
                inputDevice.Open();
            }

            Arpeggiator arpeggiator = new Arpeggiator(inputDevice, outputDevice, clock);
            Drummer drummer = new Drummer(clock, outputDevice, 4);

            clock.Start();
            if (inputDevice != null)
            {
                inputDevice.StartReceiving(clock);
            }

            bool done = false;
            while (!done)
            {
                Console.Clear();
                Console.WriteLine("BPM = {0}, Playing = {1}, Arpeggiator Mode = {2}",
                    clock.BeatsPerMinute, clock.IsRunning, arpeggiator.Status);
                Console.WriteLine("Escape : Quit");
                Console.WriteLine("Down : Slower");
                Console.WriteLine("Up: Faster");
                Console.WriteLine("Left: Previous Chord or Scale");
                Console.WriteLine("Right: Next Chord or Scale");
                Console.WriteLine("Space = Toggle Play");
                Console.WriteLine("Enter = Toggle Scales/Chords");
                ConsoleKey key = Console.ReadKey(true).Key;
                Pitch pitch;
                if (key == ConsoleKey.Escape)
                {
                    done = true;
                }
                else if (key == ConsoleKey.DownArrow)
                {
                    clock.BeatsPerMinute -= 2;
                }
                else if (key == ConsoleKey.UpArrow)
                {
                    clock.BeatsPerMinute += 2;
                }
                else if (key == ConsoleKey.RightArrow)
                {
                    arpeggiator.Change(1);
                }
                else if (key == ConsoleKey.LeftArrow)
                {
                    arpeggiator.Change(-1);
                }
                else if (key == ConsoleKey.Spacebar)
                {
                    if (clock.IsRunning)
                    {
                        clock.Stop();
                        if (inputDevice != null)
                        {
                            inputDevice.StopReceiving();
                        }
                        outputDevice.SilenceAllNotes();
                    }
                    else
                    {
                        clock.Start();
                        if (inputDevice != null)
                        {
                            inputDevice.StartReceiving(clock);
                        }
                    }
                }
                else if (key == ConsoleKey.Enter)
                {
                    arpeggiator.ToggleMode();
                }
                else if (ExampleUtil.IsMockPitch(key, out pitch))
                {
                    // We've hit a QUERTY key which is meant to simulate a MIDI note, so
                    // send the Note On to the output device and tell the arpeggiator.
                    NoteOnMessage noteOn = new NoteOnMessage(outputDevice, 0, pitch, 100,
                        clock.Time);
                    clock.Schedule(noteOn);
                    arpeggiator.NoteOn(noteOn);
                    // We don't get key release events for the console, so schedule a
                    // simulated Note Off one beat from now.
                    NoteOffMessage noteOff = new NoteOffMessage(outputDevice, 0, pitch, 100,
                        clock.Time + 1);
                    CallbackMessage.CallbackType noteOffCallback = beatTime =>
                    {
                        arpeggiator.NoteOff(noteOff);
                    };
                    clock.Schedule(new CallbackMessage(beatTime => arpeggiator.NoteOff(noteOff),
                        noteOff.Time));
                }
            }

            if (clock.IsRunning)
            {
                clock.Stop();
                if (inputDevice != null)
                {
                    inputDevice.StopReceiving();
                }
                outputDevice.SilenceAllNotes();
            }

            outputDevice.Close();
            if (inputDevice != null)
            {
                inputDevice.Close();
                inputDevice.RemoveAllEventHandlers();
            }

            // All done.
        }
Esempio n. 5
0
        public override void Run()
        {            
            if (OutputDevice.InstalledDevices.Count == 0)
            {
                Console.WriteLine("Can't do anything with no output device.");
                return;
            }

            float beatsPerMinute = 180;
            Clock clock = new Clock(beatsPerMinute);

            OutputDevice outputDevice = OutputDevice.InstalledDevices[0];
            outputDevice.Open();

            Drummer drummer = new Drummer(clock, outputDevice, 4);

            InputDevice inputDevice = null;
            if (InputDevice.InstalledDevices.Count > 0)
            {
                // Just pick the first input device.  This will throw an exception if there isn't
                // one.
                inputDevice = InputDevice.InstalledDevices[0];
                inputDevice.Open();
            }
            Scaler scaler = new Scaler(clock, inputDevice, outputDevice);

            clock.Start();
            if (inputDevice != null)
            {
                inputDevice.StartReceiving(clock);
            }

            bool done = false;

            while (!done)
            {
                Console.Clear();
                Console.WriteLine("BPM = {0}, Playing = {1}, Scale = {2}", clock.BeatsPerMinute,
                    clock.IsRunning, scaler.GetScaletoUse());
                Console.WriteLine("Escape : Quit");
                Console.WriteLine("Down : Slower");
                Console.WriteLine("Up: Faster");
                Console.WriteLine("Left: Previous Scale");
                Console.WriteLine("Right: Next Scale");
                Console.WriteLine("Space = Toggle Play");
                ConsoleKey key = Console.ReadKey(true).Key;
                Note note;
                if (key == ConsoleKey.Escape)
                {
                    done = true;
                }
                else if (key == ConsoleKey.DownArrow)
                {
                    clock.BeatsPerMinute -= 2;
                }
                else if (key == ConsoleKey.UpArrow)
                {
                    clock.BeatsPerMinute += 2;
                }
                else if (key == ConsoleKey.RightArrow)
                {
                    scaler.NextScale();
                }
                else if (key == ConsoleKey.LeftArrow)
                {
                    scaler.PreviousScale();
                }
                else if (key == ConsoleKey.Spacebar)
                {
                    if (clock.IsRunning)
                    {
                        clock.Stop();
                        if (inputDevice != null)
                        {
                            inputDevice.StopReceiving();
                        }
                        outputDevice.SilenceAllNotes();
                    }
                    else
                    {
                        clock.Start();
                        if (inputDevice != null)
                        {
                            inputDevice.StartReceiving(clock);
                        }
                    }
                }
                else if (key == ConsoleKey.D1)
                {
                    NoteOnMessage msg = new NoteOnMessage(outputDevice, Channel.Channel1, Note.C4,
                        80, clock.BeatTime);
                    NoteOffMessage msg2 = new NoteOffMessage(outputDevice, Channel.Channel1,
                        Note.C4, 80, clock.BeatTime+0.99f);
                    clock.Schedule(msg);
                    clock.Schedule(msg2);
                    scaler.NoteOn(msg);
                }
                else if (ExampleUtil.IsMockNote(key, out note))
                {
                    NoteOnMessage noteOn = new NoteOnMessage(outputDevice, 0, note, 100,
                        clock.BeatTime);
                    NoteOffMessage noteOff = new NoteOffMessage(outputDevice, 0, note, 100,
                        clock.BeatTime + 1);
                    clock.Schedule(noteOn);
                    clock.Schedule(noteOff);
                    scaler.NoteOn(noteOn);
                }

            }

            if (clock.IsRunning)
            {
                clock.Stop();
                if (inputDevice != null)
                {
                    inputDevice.StopReceiving();
                }
                outputDevice.SilenceAllNotes();
            }

            outputDevice.Close();
            if (inputDevice != null)
            {
                inputDevice.Close();
            }
        }
Esempio n. 6
0
            void clock(LaunchpadDevice device)
            {
                Clock warten = new Clock(160);
                warten.Start();
                device[1, 1].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[2, 1].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[1, 2].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);

                device[6, 1].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[5, 1].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[6, 2].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);

                device[1, 5].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[1, 6].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[2, 6].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);

                device[6, 5].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[5, 6].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                device[6, 6].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);

                bool stop = false;
                while (stop == false)
                {
                    if (warten.Time == 1 || warten.Time == 5)
                    {
                        if (warten.Time >= 3)
                        {
                            stop = true;
                            warten.Stop();
                            device[3, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            device[4, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            device[4, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            device[3, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            System.Threading.Thread.Sleep(375);
                            device.Reset();
                            break;
                        }
                        else
                        {
                            device[3, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            device[4, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            device[4, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                            device[3, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                        }
                    }
                    else if (warten.Time == 2)
                    {
                        device[3, 4].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                        device[4, 3].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                        device[4, 4].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                        device[3, 3].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                    }
                    else if (warten.Time == 3)
                    {
                        device[3, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                        device[4, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                        device[4, 4].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                        device[3, 3].SetBrightness(ButtonBrightness.Full, ButtonBrightness.Full);
                    }
                    else if (warten.Time == 4)
                    {
                        device[3, 4].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                        device[4, 3].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                        device[4, 4].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                        device[3, 3].SetBrightness(ButtonBrightness.Off, ButtonBrightness.Off);
                    }
                }
            }