Пример #1
0
        public static void PlayPiano()
        {
            Sequencer a = new Sequencer();
            using (OutputDevice outDevice = new OutputDevice(0))
            {
                for (int i = 60; i < 100; i++)
                {
                    ChannelMessageBuilder builder = new ChannelMessageBuilder();

                    builder.Command = ChannelCommand.NoteOn;
                    builder.MidiChannel = 14;
                    builder.Data1 = i;
                    builder.Data2 = i - 20;
                    builder.Build();

                    outDevice.Send(builder.Result);

                    Thread.Sleep(500);

                    builder.Command = ChannelCommand.NoteOff;
                    builder.Data2 = 0;
                    builder.Build();

                    outDevice.Send(builder.Result);
                }
            }
        }
Пример #2
0
        protected override void OnLoad(EventArgs e)
        {
            if(OutputDevice.DeviceCount == 0)
            {
                MessageBox.Show("No MIDI output devices available.", "Error!",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);

                Close();
            }
            else
            {
                try
                {
                    outDevice = new OutputDevice(outDeviceID);

                    sequence1.LoadProgressChanged += HandleLoadProgressChanged;
                    sequence1.LoadCompleted += HandleLoadCompleted;
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);

                    Close();
                }
            }

            base.OnLoad(e);
        }
Пример #3
0
    void Start()
    {
        Player = transform;

        FileList = Player.Find("FileList").GetComponent <Dropdown>();
        FileList.ClearOptions();

        MediaFolder = Player.Find("MediaFolder").GetComponent <InputField>();

        string path = PlayerPrefs.GetString("MediaFolder");

        if (path != null && path.Length > 0)
        {
            MediaFolder.text = path;
        }

        Timer = Player.Find("Timer").GetComponent <Text>();

        sequence.Format = 1;

        sequencer.Position = 0;
        sequencer.Sequence = sequence;

        //sequence.LoadCompleted += HandleLoadCompleted;
        sequencer.ChannelMessagePlayed += onChannelMessagePlayed;
        sequencer.Stopped += onStopped;

        if (OutputToDevice)
        {
            outDevice = new Midi.OutputDevice(0);
        }
    }
Пример #4
0
 public MIDIPlayer()
 {
     OutputDevice = new OutputDevice(outputDeviceID);
     timerStopper = new Forms.Timer();
     timerStopper.Interval = PLAY_NOTE_DURATION;
     timerStopper.Tick += new EventHandler(timerStopper_Tick);
 }
Пример #5
0
        public PlayerABC(Sanford.Multimedia.Midi.OutputDevice outputDevice)
            : base(false)
        {
            otpdev = outputDevice;

            midi = new MidiDevice(outputDevice);
            midi.SetInstrument(default(MyMidi.Instrument));
        }
Пример #6
0
 /// <summary>
 /// Warning: always do this in another thread
 /// </summary>
 public void play(int tempo=120)
 {
     low = song[0].Item1.note+57;
     ChannelMessageBuilder builder = new ChannelMessageBuilder();
     if (outDevice.IsDisposed) { outDevice = new OutputDevice(0); }
     foreach (Tuple<Keys, byte> line in song)
     {
         play_chord(line.Item1, (60000 / tempo) * line.Item2);
     }
     outDevice.Close();
 }
Пример #7
0
        public MidiThread()
        {
            Retrig = new int[8];

            Patt = new int[64 * 16];

            for (int k = 0; k < 8; k++)
                Retrig[k] = 1;

            Device = null;
            BuildTrack();
        }
Пример #8
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;
        }
Пример #9
0
 public void Initialise()
 {
     try
     {
         _outputDevice = new OutputDevice(0);
         IsInitialised = true;
     }
     catch (Exception e)
     {
         Exceptions.ErrHandler("Failed to initialise output device: ", e);
     }
 }
Пример #10
0
 public MidiDeviceWrapper(int id)
 {
     Console.WriteLine("Creating a midi device wrapper for device #" + id);
     queue = new Queue<IMidiMessage>();
     try
     {
         device = new OutputDevice(id);
     }
     catch (Exception x)
     {
         Console.WriteLine(x.ToString());
     }
 }
Пример #11
0
        public MidiChord(int channel, MidiChordDef midiChordDef, OutputDevice midiOutputDevice)
            : base(channel, 0, midiChordDef.MsDuration)
        {
            _midiOutputDevice = midiOutputDevice;

            List<BasicMidiChordDef> basicMidiChordDefs = midiChordDef.BasicMidiChordDefs;
            Debug.Assert(basicMidiChordDefs.Count > 0);
            List<int> realBasicMidiChordDurations = M.IntDivisionSizes(MsDuration, midiChordDef.BasicChordDurations);

            var notesToStop = new SortedSet<byte>();
            int i = 0;
            foreach(BasicMidiChordDef basicMidiChordDef in midiChordDef.BasicMidiChordDefs)
            {
                this._basicMidiChords.Add(new BasicMidiChord(channel, this, basicMidiChordDef, realBasicMidiChordDurations[i++]));
                if(basicMidiChordDef.HasChordOff)
                {
                    foreach(byte note in basicMidiChordDef.Pitches)
                    {
                        if(!notesToStop.Contains(note))
                            notesToStop.Add(note);
                    }
                }
            }

            if(midiChordDef.Bank != null)
            {
                _bank = new BankControl(channel, (byte)midiChordDef.Bank);
            }
            if(midiChordDef.Patch != null)
            {
                _patch = new PatchControl(channel, (byte)midiChordDef.Patch);
            }

            // Moritz currently never repeats MidiChords, so the _repeat field is unnecessary.
            // However: the value of midiChordDef.Repeat is saved in SVG-MIDI files,
            // and may be used by the web AssistantPerformer.
            //_repeat = midiChordDef.Repeat;

            if(midiChordDef.PitchWheelDeviation != null)
            {
                _pitchWheelDeviation = new PitchWheelDeviation(channel, (byte)midiChordDef.PitchWheelDeviation);
            }
            if(midiChordDef.MidiChordSliderDefs != null)
                CreateSliders(channel, midiChordDef.MidiChordSliderDefs, MsDuration);

            SetMessagesDict();
        }
Пример #12
0
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBoxMode.SelectedIndex = 0;
            listBoxTone.SelectedIndex = 0;
            try
            {
               outDevice  = new OutputDevice(0);
            }
            catch
            {
                MessageBox.Show("Can't find MIDI output device");
                Application.Exit();
            }
            sequence = new List<NoteL>();
            notes = new List<int>();

        }
Пример #13
0
 public static void PlayPartOfTrack()
 {
     Sequence seq = new Sequence(@"C:\Users\armen_000\Documents\Visual Studio 2013\Projects\Improvisation\Improvisation\bin\Debug\loseyourself.mid");
     using (var device = new OutputDevice(0))
     {
         var track = seq[1];
         foreach (var item in track.Iterator())
         {
             var k = item.MidiMessage as ChannelMessage;
             if (k != null)
             {
                 device.Send(k);
                 Thread.Sleep(item.DeltaTicks);
             }
         }
     }
 }
Пример #14
0
            public Player(Game game)
                : base(game)
            {
                sequencer1 = new Sanford.Multimedia.Midi.Sequencer();
                sequencer1.clock.Tick += onTick;

                outDevice = new OutputDevice(outDeviceID);

                
                this.sequencer1.PlayingCompleted += new System.EventHandler(this.HandlePlayingCompleted);
                this.sequencer1.ChannelMessagePlayed += new System.EventHandler<Sanford.Multimedia.Midi.ChannelMessageEventArgs>(this.HandleChannelMessagePlayed);
                this.sequencer1.SysExMessagePlayed += new System.EventHandler<Sanford.Multimedia.Midi.SysExMessageEventArgs>(this.HandleSysExMessagePlayed);
                this.sequencer1.Chased += new System.EventHandler<Sanford.Multimedia.Midi.ChasedEventArgs>(this.HandleChased);
                this.sequencer1.Stopped += new System.EventHandler<Sanford.Multimedia.Midi.StoppedEventArgs>(this.HandleStopped);
                

            }
Пример #15
0
        public MidiDevice(Sanford.Multimedia.Midi.OutputDevice outputdev)
        {
            try
            {
                timeOuts = new List <NoteTimeOut>();
                //outputDevice = Midi.OutputDevice.InstalledDevices[1];
                outDevice = outputdev;


                //if (! outputDevice.IsOpen)
                //    outputDevice.Open();
                //outputDevice.SilenceAllNotes();
                SilenceAllNotes();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            System.Threading.Thread.Sleep(200); // fixes delay during initial playing, possibly due to midi device initialization
        }
Пример #16
0
 public FormImportMIDI()
 {
     InitializeComponent();
     tempo = 500000;
     isDoneParse = false;
     isClosing = false;
     isPlaying = false;
     startFromZero = true;
     outputDevice = Program.MIDIPlayer.OutputDevice;
     sequence = new Sequence();
     sequence.Format = 1;
     sequence.LoadCompleted += new EventHandler<AsyncCompletedEventArgs>(sequence_LoadCompleted);
     sequencer = new Sequencer();
     sequencer.Position = 0;
     sequencer.Sequence = this.sequence;
     sequencer.PlayingCompleted += new EventHandler(sequencer_PlayingCompleted);
     sequencer.ChannelMessagePlayed += new EventHandler<ChannelMessageEventArgs>(sequencer_ChannelMessagePlayed);
     sequencer.Stopped += new EventHandler<StoppedEventArgs>(sequencer_Stopped);
     sequencer.SysExMessagePlayed += new EventHandler<SysExMessageEventArgs>(sequencer_SysExMessagePlayed);
     sequencer.Chased += new EventHandler<ChasedEventArgs>(sequencer_Chased);
     timerLocation.Start();
 }
Пример #17
0
        public MidiOutput(string deviceName = null, bool ignoreMissingDevice = false, [System.Runtime.CompilerServices.CallerMemberName] string name = "")
        {
            string midiDeviceName = deviceName;
            if (string.IsNullOrEmpty(deviceName))
                midiDeviceName = Executor.Current.GetSetKey(this, name + ".DeviceName", string.Empty);

            int selectedDeviceId = -1;
            for (int i = 0; i < OutputDevice.DeviceCount; i++)
            {
                var midiCap = OutputDevice.GetDeviceCapabilities(i);

                if (midiCap.name == midiDeviceName)
                {
                    selectedDeviceId = i;
                    break;
                }
            }

            if (selectedDeviceId == -1)
            {
                if (!ignoreMissingDevice)
                    throw new ArgumentException("Midi device not detected");
                else
                    log.Warn("Midi device not detected");
            }
            else
            {
                this.outputDevice = new OutputDevice(selectedDeviceId);

                this.outputDevice.Error += outputDevice_Error;

                if (string.IsNullOrEmpty(deviceName))
                    Executor.Current.SetKey(this, name + ".DeviceName", midiDeviceName);
            }

            Executor.Current.Register(this);
        }
Пример #18
0
    /// <summary>
    /// Try to ensure that the selected device is opened by closing the open device (if any,
    /// and only if it is not the selected device) and opening the selected device (if not already open)
    /// </summary>
    private void EnsureDeviceOpen()
    {
        // Is the requested output device NOT currently opened?
        if (openedOutputDevice != midiOutputDeviceId)
        {
            // Is there some other output device open?
            if (openedOutputDevice != -1)
            {
                // Then close it
                try
                {
                    //output.Reset();
                    output.Close();
                    Debug.Log("Closed MIDI Output Device " + openedOutputDevice);
                }
                finally
                {
                    openedOutputDevice = -1;
                }
            }

            // Now try to open the requested device
            try
            {
                output             = new OutputDevice(midiOutputDeviceId);
                openedOutputDevice = midiOutputDeviceId;
                Debug.Log("Opened MIDI Output Device " + midiOutputDeviceId);
            }
            catch
            {
                Debug.Log("Failed to open MIDI Output Device " + midiOutputDeviceId);
                output             = null;
                openedOutputDevice = -1;
            }
        }
    }
Пример #19
0
        /// <summary>
        /// Create a new Game.
        /// </summary>
        /// <param name="flashcardSeconds">The maximum number of seconds that the player has to respond to a flashcard.</param>
        /// <param name="gameSeconds">The length of the game.  At the end of this time, it's game over.</param>
        /// <param name="virtualKeyboards">If supplied, the game will take input from these as well as the configured MIDI input device (if any.)</param>
        public Game(params VirtualKeyboard[] virtualKeyboards)
        {
            var settings = UserSettings.Instance;

            var types = new List<FlashcardGenerator>();
            if (settings.FlashcardTypes_Triad == true)
            {
                types.Add(new TriadFlashcardGenerator(new TradFlashcardGeneratorArgs()
                {
                    TriadTypes = TriadType.All,
                    TriadInversions = TriadInversion.All,
                    Accidentals = settings.Accidentals,
                    Staffs = settings.Staffs
                }));
            }
            if (settings.FlashcardTypes_Interval == true)
            {
                types.Add(new IntervalFlashcardGenerator(new IntervalFlashcardGeneratorArgs()
                {
                    IntervalTypes = Interval.All,
                    Staffs = settings.Staffs,
                    Accidentals = settings.Accidentals
                }));
            }
            if (settings.FlashcardTypes_Single == true || !types.Any()) // if they set no flashcard types, give them single.
            {
                types.Add(new SingleNoteFlashcardGenerator(new StaffFlashcardGeneratorArgs()
                    {
                        Staffs = settings.Staffs,
                        Accidentals = settings.Accidentals
                    }));
            }

            _flashcardSource = new MultipleFlashcardGenerator(types.ToArray());
            _currentResponse = new Dictionary<Note, bool>();
            _flashcardResults = new List<FlashcardResult>();

            // if the user changes MIDI devices mid-game, handle that.
            UserSettings.Instance.OutputDeviceChanged += new EventHandler(UserSettings_OutputDeviceChanged);
            UserSettings.Instance.InputDeviceChanged += new EventHandler(UserSettings_InputDeviceChanged);

            _outputDevice = UserSettings.Instance.GetOutputDevice();
            _inputDevice = UserSettings.Instance.GetInputDevice();

            if (_inputDevice != null)
                _inputDevice.ChannelMessageReceived += new EventHandler<ChannelMessageEventArgs>(ChannelMessageReceived);

            foreach(var vk in virtualKeyboards)
                vk.ChannelMessageReceived += new EventHandler<ChannelMessageEventArgs>(ChannelMessageReceived);

            _gameTimer = new Timer(GAME_DURATION * 1000);
            _flashcardTimer = new Timer(settings.MaxFlashcardTime * 1000);
            _nextFlashcardTimer = new Timer(500);
            _newGameCountdownTimer = new Timer(1000);
            _nextFlashcardTimer.AutoReset = false;
            _gameTimer.Elapsed += new ElapsedEventHandler(GameTimer_Elapsed);
            _flashcardTimer.Elapsed += new ElapsedEventHandler(FlashcardTimer_Elapsed);
            _nextFlashcardTimer.Elapsed += new ElapsedEventHandler(NextFlashcardTimer_Elapsed);

            GameMode = GameMode.NotStarted;
        }
Пример #20
0
        private bool openMidiOutput()
        {

            outDialog = new OutputDeviceDialog();

            if (OutputDevice.DeviceCount == 0)
            {
                MessageBox.Show("No MIDI output devices available.", "Error!",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return false;
            }
            else
            {
                try
                {
                    outDevice = new OutputDevice(outDeviceID);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return false;
                }

            }

            // Flag that MIDI output has successfully initialized
            midiStarted = true;
            btn_startMIDI.Text = "Stop MIDI";
            btn_startMIDI.BackColor = Color.LightCoral;

            return true;
        }
Пример #21
0
 public AsyncOutputPlayer()
 {
     this.outDevice = new OutputDevice(0);
 }
Пример #22
0
        public Form1()
        {
            InitializeComponent();

            panele[0, 0] = panel1;
            panele[1, 0] = panel2;
            panele[2, 0] = panel3;
            panele[3, 0] = panel4;

            panele[0, 1] = panel5;
            panele[1, 1] = panel6;
            panele[2, 1] = panel7;
            panele[3, 1] = panel8;

            panele[0, 2] = panel9;
            panele[1, 2] = panel10;
            panele[2, 2] = panel11;
            panele[3, 2] = panel12;

            panele[0, 3] = panel13;
            panele[1, 3] = panel14;
            panele[2, 3] = panel15;
            panele[3, 3] = panel16;

            List<Point> droga = new List<Point>();
            droga.Add(new Point(0, 0));
            droga.Add(new Point(1, 0));
            droga.Add(new Point(2, 0));
            droga.Add(new Point(3, 0));
            droga.Add(new Point(3, 1));
            droga.Add(new Point(3, 2));
            droga.Add(new Point(3, 3));
            ListaDrog.Add(droga);

            List<Point> droga1 = new List<Point>();
            droga1.Add(new Point(0, 0));
            droga1.Add(new Point(1, 0));
            droga1.Add(new Point(2, 0));
            droga1.Add(new Point(2, 1));
            droga1.Add(new Point(3, 1));
            droga1.Add(new Point(3, 2));
            droga1.Add(new Point(3, 3));
            ListaDrog.Add(droga1);

            List<Point> droga2 = new List<Point>();
            droga2.Add(new Point(0, 0));
            droga2.Add(new Point(1, 0));
            droga2.Add(new Point(1, 1));
            droga2.Add(new Point(2, 1));
            droga2.Add(new Point(3, 1));
            droga2.Add(new Point(3, 2));
            droga2.Add(new Point(3, 3));
            ListaDrog.Add(droga2);

            List<Point> droga3 = new List<Point>();
            droga3.Add(new Point(0, 0));
            droga3.Add(new Point(0, 1));
            droga3.Add(new Point(1, 1));
            droga3.Add(new Point(2, 1));
            droga3.Add(new Point(3, 1));
            droga3.Add(new Point(3, 2));
            droga3.Add(new Point(3, 3));
            ListaDrog.Add(droga3);

            List<Point> droga4 = new List<Point>();
            droga4.Add(new Point(0, 0));
            droga4.Add(new Point(0, 1));
            droga4.Add(new Point(1, 1));
            droga4.Add(new Point(2, 1));
            droga4.Add(new Point(2, 2));
            droga4.Add(new Point(3, 2));
            droga4.Add(new Point(3, 3));
            ListaDrog.Add(droga4);

            List<Point> droga5 = new List<Point>();
            droga5.Add(new Point(0, 0));
            droga5.Add(new Point(0, 1));
            droga5.Add(new Point(1, 1));
            droga5.Add(new Point(1, 2));
            droga5.Add(new Point(2, 2));
            droga5.Add(new Point(3, 2));
            droga5.Add(new Point(3, 3));
            ListaDrog.Add(droga5);

            List<Point> droga6 = new List<Point>();
            droga6.Add(new Point(0, 0));
            droga6.Add(new Point(0, 1));
            droga6.Add(new Point(0, 2));
            droga6.Add(new Point(1, 2));
            droga6.Add(new Point(2, 2));
            droga6.Add(new Point(3, 2));
            droga6.Add(new Point(3, 3));
            ListaDrog.Add(droga6);

            List<Point> droga7 = new List<Point>();
            droga7.Add(new Point(0, 0));
            droga7.Add(new Point(0, 1));
            droga7.Add(new Point(0, 2));
            droga7.Add(new Point(1, 2));
            droga7.Add(new Point(2, 2));
            droga7.Add(new Point(2, 3));
            droga7.Add(new Point(3, 3));
            ListaDrog.Add(droga7);

            List<Point> droga8 = new List<Point>();
            droga8.Add(new Point(0, 0));
            droga8.Add(new Point(0, 1));
            droga8.Add(new Point(0, 2));
            droga8.Add(new Point(1, 2));
            droga8.Add(new Point(1, 3));
            droga8.Add(new Point(2, 3));
            droga8.Add(new Point(3, 3));
            ListaDrog.Add(droga8);

            List<Point> droga9 = new List<Point>();
            droga9.Add(new Point(0, 0));
            droga9.Add(new Point(0, 1));
            droga9.Add(new Point(0, 2));
            droga9.Add(new Point(0, 3));
            droga9.Add(new Point(1, 3));
            droga9.Add(new Point(2, 3));
            droga9.Add(new Point(3, 3));
            ListaDrog.Add(droga9);

            List<Point> droga10 = new List<Point>();
            droga10.Add(new Point(0, 0));
            droga10.Add(new Point(1, 0));
            droga10.Add(new Point(2, 0));
            droga10.Add(new Point(2, 1));
            droga10.Add(new Point(2, 2));
            droga10.Add(new Point(3, 2));
            droga10.Add(new Point(3, 3));
            ListaDrog.Add(droga10);

            List<Point> droga11 = new List<Point>();
            droga11.Add(new Point(0, 0));
            droga11.Add(new Point(1, 0));
            droga11.Add(new Point(2, 0));
            droga11.Add(new Point(2, 1));
            droga11.Add(new Point(2, 2));
            droga11.Add(new Point(2, 3));
            droga11.Add(new Point(3, 3));
            ListaDrog.Add(droga11);

            List<Point> droga12 = new List<Point>();
            droga12.Add(new Point(0, 0));
            droga12.Add(new Point(1, 0));
            droga12.Add(new Point(1, 1));
            droga12.Add(new Point(2, 1));
            droga12.Add(new Point(2, 2));
            droga12.Add(new Point(2, 3));
            droga12.Add(new Point(3, 3));
            ListaDrog.Add(droga12);

            List<Point> droga13 = new List<Point>();
            droga13.Add(new Point(0, 0));
            droga13.Add(new Point(1, 0));
            droga13.Add(new Point(1, 1));
            droga13.Add(new Point(1, 2));
            droga13.Add(new Point(2, 2));
            droga13.Add(new Point(2, 3));
            droga13.Add(new Point(3, 3));
            ListaDrog.Add(droga13);

            List<Point> droga14 = new List<Point>();
            droga14.Add(new Point(0, 0));
            droga14.Add(new Point(1, 0));
            droga14.Add(new Point(1, 1));
            droga14.Add(new Point(1, 2));
            droga14.Add(new Point(1, 3));
            droga14.Add(new Point(2, 3));
            droga14.Add(new Point(3, 3));
            ListaDrog.Add(droga14);

            List<Point> droga15 = new List<Point>();
            droga15.Add(new Point(0, 0));
            droga15.Add(new Point(0, 1));
            droga15.Add(new Point(1, 1));
            droga15.Add(new Point(1, 2));
            droga15.Add(new Point(1, 3));
            droga15.Add(new Point(2, 3));
            droga15.Add(new Point(3, 3));
            ListaDrog.Add(droga15);

            List<Point> droga16 = new List<Point>();
            droga16.Add(new Point(0, 0));
            droga16.Add(new Point(0, 1));
            droga16.Add(new Point(0, 2));
            droga16.Add(new Point(1, 2));
            droga16.Add(new Point(1, 3));
            droga16.Add(new Point(2, 3));
            droga16.Add(new Point(3, 3));
            ListaDrog.Add(droga16);

            droga = new List<Point>();
            droga.Add(new Point(0, 0));
            droga.Add(new Point(0, 1));
            droga.Add(new Point(1, 1));
            droga.Add(new Point(1, 2));
            droga.Add(new Point(2, 2));
            droga.Add(new Point(2, 3));
            droga.Add(new Point(3, 3));
            ListaDrog.Add(droga);

            droga = new List<Point>();
            droga.Add(new Point(0, 0));
            droga.Add(new Point(0, 1));
            droga.Add(new Point(1, 1));
            droga.Add(new Point(2, 1));
            droga.Add(new Point(2, 2));
            droga.Add(new Point(2, 3));
            droga.Add(new Point(3, 3));
            ListaDrog.Add(droga);

            droga = new List<Point>();
            droga.Add(new Point(0, 0));
            droga.Add(new Point(1, 0));
            droga.Add(new Point(1, 1));
            droga.Add(new Point(2, 1));
            droga.Add(new Point(2, 2));
            droga.Add(new Point(3, 2));
            droga.Add(new Point(3, 3));
            ListaDrog.Add(droga);

            droga = new List<Point>();
            droga.Add(new Point(0, 0));
            droga.Add(new Point(1, 0));
            droga.Add(new Point(1, 1));
            droga.Add(new Point(1, 2));
            droga.Add(new Point(2, 2));
            droga.Add(new Point(3, 2));
            droga.Add(new Point(3, 3));
            ListaDrog.Add(droga);

            if (OutputDevice.DeviceCount < 3)
            {
                DeviceOK = false;
                MessageBox.Show("No LPD8 x 2 = No game", "Game Over",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);

                //Close();
            }
            else
            {
                try
                {
                    context = SynchronizationContext.Current;
                    outDevice1 = new OutputDevice(1);
                    outDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error);

                    context = SynchronizationContext.Current;
                    outDevice2 = new OutputDevice(2);
                    outDevice2.Error += new EventHandler<ErrorEventArgs>(inDevice_Error);
                }
                catch (Exception ex)
                {
                    DeviceOK = false;
                    MessageBox.Show(ex.Message, "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    //Close();
                }
            }

            if (DeviceOK)
            if (InputDevice.DeviceCount < 2)
            {
                DeviceOK = false;
                MessageBox.Show("LPD8 x2 = No game", "Game Over",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
                //Close();
            }
            else
            {
                try
                {
                    context = SynchronizationContext.Current;

                    inDevice1 = new InputDevice(0);
                    inDevice1.ChannelMessageReceived += HandleChannelMessageReceived;
                    inDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error);

                    AddLogDevice(0, InputDevice.GetDeviceCapabilities(0));

                    inDevice1.StartRecording();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    DeviceOK = false;
                    //Close();
                }

                try
                {
                    context = SynchronizationContext.Current;

                    inDevice2 = new InputDevice(1);
                    inDevice2.ChannelMessageReceived += HandleChannelMessageReceived;
                    inDevice2.Error += new EventHandler<ErrorEventArgs>(inDevice_Error);

                    AddLogDevice(1, InputDevice.GetDeviceCapabilities(1));

                    inDevice2.StartRecording();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    DeviceOK = false;
                    //Close();
                }
            }

            if (DeviceOK)
                Reset();
        }
Пример #23
0
 public OutputDevice GetOutputDevice()
 {
     if (_outputDevice == null && this.MIDIOutputDeviceNumber.HasValue)
     {
         try
         {
             _outputDevice = new OutputDevice(this.MIDIOutputDeviceNumber.Value);
         }
         catch (OutputDeviceException) // the input device is unavailable (in use or not attached.)
         {
             _outputDevice = null;
         }
     }
     return _outputDevice;
 }
Пример #24
0
 public MIDIOutputDevice(int deviceID)
 {
     OutputDevice = new OutputDevice(deviceID);
 }
Пример #25
0
		/// <summary>
		/// デバイスのポーリング
		/// </summary>
		/// <returns></returns>
		private bool PollDevice()
		{
			var deviceID = FindDevice();
			if (deviceID == Constants.DeviceNull)
			{
				// デバイスロスト
				PrimaryDevice.Shutdown();
				PrimaryDevice = null;
				return false;
			}

			// 新規デバイス
			if (PrimaryDevice == null)
			{
				PrimaryDevice = new OutputDevice(deviceID);
				PrimaryDevice.Startup();
			}

			return true;
		}
Пример #26
0
 /// <summary>
 /// The MIDI output device has changed.  Grab the new one.
 /// </summary>
 void UserSettings_OutputDeviceChanged(object sender, EventArgs e)
 {
     _outputDevice = UserSettings.Instance.GetOutputDevice();
 }
Пример #27
0
 public VirtualKeyboard()
 {
     _device = UserSettings.Instance.GetOutputDevice();
     UserSettings.Instance.OutputDeviceChanged += new EventHandler(UserSettings_OutputDeviceChanged);
     this.ChannelMessageReceived += new EventHandler<ChannelMessageEventArgs>(VirtualKeyboard_ChannelMessageReceived);
 }
Пример #28
0
 public PlayerMML(Sanford.Multimedia.Midi.OutputDevice outputDevice)
     : base()
 {
     midi = new MidiDevice(outputDevice);
     midi.SetInstrument(default(MyMidi.Instrument));
 }
Пример #29
0
 private static extern int midiStreamOpen(ref int handle, ref int deviceID, int reserved,
     OutputDevice.MidiOutProc proc, int instance, uint flag);
        public static OutputDevice CreateDevice(int deviceID, SynchronizationContext context)
        {
            OutputDevice ret = null;
            try
            {
                ret = new OutputDevice(deviceID, context);

                if (!ret.OpenMidi())
                {
                    ret.Dispose();
                    ret = null;
                }
            }
            catch { ret = null; }
            return ret;
        }
Пример #31
0
 /// <summary>
 /// Stop MIDI playback
 /// </summary>
 public void Stop()
 {
     timerRhythm.Stop();
     outDevice.Close();
     outDevice = new OutputDevice(0);
 }
Пример #32
0
        private void Load()
        {
            Loading = 0;
            outDevice = new OutputDevice(0);
            sequencer = new Sequencer();
            sequence = new Sequence();

            sequencer.ChannelMessagePlayed += delegate (object o, ChannelMessageEventArgs args)
            {
                ChannelCommand cmd = args.Message.Command;
                int channel = args.Message.MidiChannel;
                int data1 = args.Message.Data1;
                int data2 = args.Message.Data2;
                if (cmd == ChannelCommand.NoteOff || data2 == 0)
                {
                    if (lastPlayed[channel, data1] != null)
                    {
                        Note n = lastPlayed[channel, data1];
                        n.Playing = false;
                    }
                }
                else if (cmd == ChannelCommand.NoteOn)
                {
                    Note n = new Note()
                    {
                        Key = data1,
                        Length = 0,
                        Playing = true,
                        Position = 0,
                        Time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond,
                        Channel = channel,
                        Velocity = data2
                    };
                    lock (notes)
                        notes.Add(n);
                    if (lastPlayed[channel, data1] != null)
                        lastPlayed[channel, data1].Playing = false;
                    lastPlayed[channel, data1] = n;
                }

                lock (backlog)
                {
                    backlog.Enqueue(new Event(delegate
                    {
                        outDevice.Send(args.Message);
                        if (cmd == ChannelCommand.NoteOff || data2 == 0)
                            if (Keyboard.KeyPressed[data1] > 0)
                                Keyboard.KeyPressed[data1]--;
                        else if (cmd == ChannelCommand.NoteOn)
                            Keyboard.KeyPressed[data1]++;
                        else if (cmd == ChannelCommand.Controller)
                            if (data1 == 0x07)
                                Keyboard.ChannelVolume[channel] = data2;
                        else if (cmd == ChannelCommand.PitchWheel)
                        {
                            int pitchValue = Get14BitValue(data1, data2);
                            Keyboard.Pitchwheel[channel] = pitchValue;
                        }
                    }, Delay));
                }
            };
            sequencer.SysExMessagePlayed += delegate (object o, SysExMessageEventArgs args)
            {
                lock (backlog)
                    backlog.Enqueue(new Event(() => outDevice.Send(args.Message), Delay));
            };
            sequencer.Chased += delegate (object o, ChasedEventArgs args)
            {
                foreach (ChannelMessage message in args.Messages)
                    lock (backlog)
                        backlog.Enqueue(new Event(() => outDevice.Send(message), Delay));
            };
            sequencer.Stopped += delegate (object o, StoppedEventArgs args)
            {
                foreach (ChannelMessage message in args.Messages)
                    lock (backlog)
                        backlog.Enqueue(new Event(() => outDevice.Send(message), Delay));
            };
            sequence.LoadCompleted += delegate (object o, AsyncCompletedEventArgs args)
            {
                Loading = -1;
                sequencer.Sequence = sequence;
                sequencer.Start();
            };
            sequence.LoadProgressChanged += delegate (object sender, ProgressChangedEventArgs args)
            {
                Loading = args.ProgressPercentage;
            };
            sequence.LoadAsync(MIDIFile);
        }
Пример #33
0
        private void OnLoad(object sender, RoutedEventArgs e)
        {
            if (OutputDevice.DeviceCount == 0)
            {
                System.Windows.MessageBox.Show("No MIDI output devices available.");

                Close();
            }
            else
            {
                try
                {
                    outDevice = new OutputDevice(outDeviceID);

                    //sequence1.LoadProgressChanged += HandleLoadProgressChanged;
                    //sequence1.LoadCompleted += HandleLoadCompleted;
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show(ex.Message);

                    Close();
                }
            }
        }
Пример #34
0
        public MainForm()
        {
            InitializeComponent();

            panele[0, 0] = panel1;
            panele[1, 0] = panel2;
            panele[2, 0] = panel3;
            panele[3, 0] = panel4;

            panele[0, 1] = panel5;
            panele[1, 1] = panel6;
            panele[2, 1] = panel7;
            panele[3, 1] = panel8;

            foreach (GameType gameType in Enum.GetValues(typeof(GameType)))
            {
                lbxGames.Items.Add(gameType);
            }

            if (OutputDevice.DeviceCount < 2)
            {
                DeviceOK = false;
                MessageBox.Show("No LPD8 = No game", "Game Over",
                    MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                try
                {
                    context = SynchronizationContext.Current;
                    outDevice1 = new OutputDevice(1);
                    outDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error);
                }
                catch (Exception ex)
                {
                    DeviceOK = false;
                    MessageBox.Show(ex.Message, "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }

            if (DeviceOK)
                if (InputDevice.DeviceCount < 1)
                {
                    DeviceOK = false;
                    MessageBox.Show("LPD8 = No game", "Game Over",
                        MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                else
                {
                    try
                    {
                        context = SynchronizationContext.Current;

                        inDevice1 = new InputDevice(0);
                        inDevice1.ChannelMessageReceived += HandleChannelMessageReceived;
                        inDevice1.Error += new EventHandler<ErrorEventArgs>(inDevice_Error);

                        AddLogDevice(0, InputDevice.GetDeviceCapabilities(0));

                        inDevice1.StartRecording();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error!",
                            MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        DeviceOK = false;
                    }
                }

            if (DeviceOK)
                ResetSquares();
        }
        private void InitializeSequencer()
        {
            sequencer1.Stop();
            playing = false;

            outDevice = new OutputDevice(outDeviceID);
            this.sequence1.Format = 1;
            this.sequencer1.Position = 0;
            this.sequencer1.Sequence = this.sequence1;
            this.sequencer1.PlayingCompleted += new System.EventHandler(this.HandlePlayingCompleted);
            this.sequencer1.ChannelMessagePlayed += new System.EventHandler<Sanford.Multimedia.Midi.ChannelMessageEventArgs>(this.HandleChannelMessagePlayed);
            this.sequencer1.Stopped += new System.EventHandler<Sanford.Multimedia.Midi.StoppedEventArgs>(this.HandleStopped);
            this.sequencer1.SysExMessagePlayed += new System.EventHandler<Sanford.Multimedia.Midi.SysExMessageEventArgs>(this.HandleSysExMessagePlayed);
            this.sequencer1.Chased += new System.EventHandler<Sanford.Multimedia.Midi.ChasedEventArgs>(this.HandleChased);
            this.sequence1.LoadProgressChanged += HandleLoadProgressChanged;
            this.sequence1.LoadCompleted += HandleLoadCompleted;
        }
Пример #36
0
        public void Init()
        {
            // Make sure we don't initialize twice and create a disaster
            if (Initialized)
                return;
            Initialized = true;

            // Create timer for event management
            eventTimer = new Timer(10);
            eventTimer.Elapsed += delegate
            {
                lock (NoteManager.Backlog)
                {
                    while (NoteManager.Backlog.Any() && NoteManager.Backlog.First().StartTime <= Stopwatch.ElapsedMilliseconds)
                    {
                        Event ev = NoteManager.Backlog.Dequeue();
                        ev.Method();
                    }
                }
            };

            Loading = 0;
            // Create handles to MIDI devices
            outDevice = new OutputDevice(0);
            sequencer = new Sequencer();
            sequence = new Sequence();
            Loading = -1;
            // Set custom event handlers for sequencer
            sequencer.ChannelMessagePlayed += delegate (object o, ChannelMessageEventArgs args)
            {
                ChannelCommand cmd = args.Message.Command;
                int channel = args.Message.MidiChannel;
                int data1 = args.Message.Data1;
                int data2 = args.Message.Data2;
                if (cmd == ChannelCommand.NoteOff || (cmd == ChannelCommand.NoteOn && data2 == 0))
                {
                    if (NoteManager.LastPlayed[channel, data1] != null)
                    {
                        Note n = NoteManager.LastPlayed[channel, data1];
                        n.Playing = false;
                    }
                }
                else if (cmd == ChannelCommand.NoteOn)
                {
                    Note n = new Note
                    {
                        Key = data1,
                        Length = 0,
                        Playing = true,
                        Position = 0,
                        Time = Stopwatch.ElapsedMilliseconds,
                        Channel = channel,
                        Velocity = data2
                    };
                    lock (NoteManager.Notes)
                        NoteManager.Notes.Add(n);
                    if (NoteManager.LastPlayed[channel, data1] != null)
                        NoteManager.LastPlayed[channel, data1].Playing = false;
                    NoteManager.LastPlayed[channel, data1] = n;
                }

                lock (NoteManager.Backlog)
                {
                    NoteManager.Backlog.Enqueue(new Event(delegate
                    {
                        outDevice.Send(args.Message);
                        if (cmd == ChannelCommand.NoteOff || (cmd == ChannelCommand.NoteOn && data2 == 0))
                        {
                            if (Keyboard.KeyPressed[data1] > 0)
                                Keyboard.KeyPressed[data1]--;
                        }
                        else if (cmd == ChannelCommand.NoteOn)
                        {
                            Keyboard.KeyPressed[data1]++;
                        }
                        else if (cmd == ChannelCommand.Controller)
                        {
                            if (data1 == 0x07)
                                Keyboard.ChannelVolume[channel] = data2;
                        }
                        else if (cmd == ChannelCommand.PitchWheel)
                        {
                            int pitchValue = Get14BitValue(data1, data2);
                            Keyboard.Pitchwheel[channel] = pitchValue;
                        }
                    }, Stopwatch.ElapsedMilliseconds, Delay));
                }
            };
            sequencer.SysExMessagePlayed += delegate (object o, SysExMessageEventArgs args)
            {
                lock (NoteManager.Backlog)
                    NoteManager.Backlog.Enqueue(new Event(() => outDevice.Send(args.Message), Stopwatch.ElapsedMilliseconds, Delay));
            };
            sequencer.Chased += delegate (object o, ChasedEventArgs args)
            {
                foreach (ChannelMessage message in args.Messages)
                    lock (NoteManager.Backlog)
                        NoteManager.Backlog.Enqueue(new Event(() => outDevice.Send(message), Stopwatch.ElapsedMilliseconds, Delay));
            };
            sequencer.Stopped += delegate (object o, StoppedEventArgs args)
            {
                foreach (ChannelMessage message in args.Messages)
                    lock (NoteManager.Backlog)
                        NoteManager.Backlog.Enqueue(new Event(() => outDevice.Send(message), Stopwatch.ElapsedMilliseconds, Delay));
                // Stop everything when the MIDI is done playing
                Stop();
            };
            sequence.LoadCompleted += delegate (object o, AsyncCompletedEventArgs args)
            {
                Loading = -1;
                if (args.Cancelled)
                {
                    MessageBox.Show("The operation was cancelled.", "MIDITrailer - Error", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return;
                }
                sequencer.Sequence = sequence;
            };
            sequence.LoadProgressChanged += delegate (object sender, ProgressChangedEventArgs args)
            {
                Loading = args.ProgressPercentage;
            };
            
        }