Example #1
0
 public void PlayBack(MidiOut midiOut, int milliSecondsPerNote)
 {
     PlayBack(
         note => midiOut.Send(MidiMessage.StartNote(note, 100, 1).RawData),
         note => midiOut.Send(MidiMessage.StopNote(note, 100, 1).RawData),
         milliSecondsPerNote);
 }
            public void PlayNewNote(int note, int velocity)
            {
                var nextNote = new NoteOnEvent(0, _channel, note, velocity, 0);

                StopPlaying();
                _midiOut.Send(nextNote.GetAsShortMessage());
                PlayingNote = nextNote;
            }
Example #3
0
 public void SetLight(bool state)
 {
     if (commandCode == MidiCommandCode.ControlChange)
     {
         midiOut.Send(new ControlChangeEvent(0, channel, (MidiController)(controller), state ? 127 : 0).GetAsShortMessage());
     }
     else if (commandCode == MidiCommandCode.NoteOn)
     {
         midiOut.Send(new NoteOnEvent(0, 1, controller, state ? 127 : 0, 0).GetAsShortMessage());
     }
 }
Example #4
0
 public void Note(int channel, int note, int velocity)
 {
     if (velocity > 0)
     {
         Output.Send(MidiMessage.StartNote(note, velocity, channel + 1).RawData);
     }
     else
     {
         Output.Send(MidiMessage.StopNote(note, 0, channel + 1).RawData);
     }
 }
Example #5
0
        public static void StopChord(MidiOut midiOut, int channel, int volume = 127, params int[] chord)
        {
            midiOut.Send(MidiMessage.StopNote(chord[0], volume, channel).RawData);
            midiOut.Send(MidiMessage.StopNote(chord[1], volume, channel).RawData);
            midiOut.Send(MidiMessage.StopNote(chord[2], volume, channel).RawData);

            if (chord.Length == 4)
            {
                midiOut.Send(MidiMessage.StopNote(chord[3], volume, channel).RawData);
            }
        }
Example #6
0
 public void startPlayingNote(int buttonNo)
 {
     if (checkButton(buttonNo) && noteStatus[buttonNo] == false)
     {
         // while(true)
         midiout.Send(MidiMessage.StartNote(getButtonNote(buttonNo), 127, 5).RawData);
         //Program.port.sendCommand(BitConverter.GetBytes(MidiMessage.StartNote(getButtonNote(buttonNo), 127, 1).RawData));
         //Console.WriteLine("Note: " + getButtonNote(buttonNo) + " start play.");
         noteStatus[buttonNo] = true;
     }
 }
        public int PlayTone(byte octave, Tones tone, int strength = 127) //Воспроизводим желаемую ноту (напр. "C#5").
        {
            int note = 12 + octave * 12 + (int)tone;                     // 12 полутонов в октаве, начинаем считать с 1-й октавы

            if (!_playingTones.Contains(note))
            {
                _midiOut.Send(MidiMessage.StartNote(note, strength, Chanel).RawData); // воспроизводим ноту на основном канале
                _playingTones.Add(note);
            }

            return(note);
        }
Example #8
0
        public int PlayNote(int note, int strength = 127)
        {
            //int note = 12 + octave * 12 + (int)tone; // 12 полутонов в октаве, начинаем считать с 0-й октавы (есть еще и -1-ая)

            if (!NotesPlayingNow.Contains(note))
            {
                midiOut.Send(MidiMessage.StartNote(note, strength, Chanel).RawData); // воспроизводим ноту на канале 0
                NotesPlayingNow.Add(note);
            }

            return(note);
        }
Example #9
0
        public void SetVolume(int channel, int volume)
        {
            if (volume < 1)
            {
                volume = 1;
            }
            if (volume > 127)
            {
                volume = 127;
            }

            midiOut.Send(MidiMessage.ChangeControl(7, volume, channel).RawData);
        }
Example #10
0
        public void Close()
        {
            MIDIMessage ms = new MIDIMessage();

            ms.ControlType = ControlChangeType.AllNotesOff;
            midiOut.Send(ms.RawData);
            midiOut.Close();
            for (int i = 0; i < Config.Channel.Count; i++)
            {
                mixer.Gate(i, false);
            }
            waveOut.Stop();
        }
        private void RemovePlayingNote(int note)
        {
            if (!_playingNotes.ContainsKey(note))
            {
                return;
            }
            foreach (var(channel, noteNr) in _playingNotes[note])
            {
                var midi = new NoteOnEvent(0, channel, noteNr, 0, 1);
                _outDevice.Send(midi.GetAsShortMessage());
            }

            _playingNotes.Remove(note);
        }
Example #12
0
        private void Button_MouseClick(object sender, MouseEventArgs e)
        {
            Button button = sender as Button;

            if (button.Text == string.Empty)
            {
                midiOut.Send(MidiMessage.StartNote(48 + button.TabIndex, 100, 1).RawData);
                button.Text = "X";
            }
            else
            {
                midiOut.Send(MidiMessage.StartNote(48 + button.TabIndex, 0, 1).RawData);
                button.Text = string.Empty;
            }
        }
Example #13
0
        static void FilterNote(MidiEvent e)
        {
            var shouldSend = true;


            if (e is NoteEvent && ((NoteEvent)e).CommandCode == MidiCommandCode.NoteOn)
            {
                shouldSend = Scale.IsInScale(scaleProgression, ((NoteEvent)e).NoteName);
                Program.mainForm.OnNotePressed(((NoteEvent)e).NoteName);
            }

            if (e is NoteEvent && ((NoteEvent)e).CommandCode == MidiCommandCode.NoteOff)
            {
                Program.mainForm.OnNoteReleased(((NoteEvent)e).NoteName);
            }

            if (shouldSend)
            {
                midiOut.Send(e.GetAsShortMessage());
            }
            else
            {
                Console.WriteLine(String.Format("Event {0} was filtered out.", e));
            }
        }
Example #14
0
 /// <summary>
 /// Send a note midi message.
 /// </summary>
 /// <param name="channel"></param>
 /// <param name="note"></param>
 /// <param name="velocity"></param>
 public void SendNote(int channel, int note, int velocity)
 {
     if (_mdev != null)
     {
         lock (_lock)
         {
             NoteEvent evt = new NoteEvent(0,
                                           channel,
                                           velocity > 0 ? MidiCommandCode.NoteOn : MidiCommandCode.NoteOff,
                                           note,
                                           velocity);
             int msg = evt.GetAsShortMessage();
             _mdev.Send(msg);
         }
     }
 }
Example #15
0
 public static void SendControlChange(MidiOut midiOut, ControlChange cc, int value, int channel)
 {
     if (cc != null)
     {
         midiOut.Send(MidiMessage.ChangeControl(cc.CC, value, channel).RawData);
     }
 }
            public MidiSingleNoteTracker(MidiOut midiOut, int channel, int patch)
            {
                _midiOut = midiOut;
                _channel = channel;
                _patch   = patch;

                midiOut.Send(new PatchChangeEvent(0, channel, patch).GetAsShortMessage());  // Flute
            }
Example #17
0
 public void SendMessage(Byte channel, Byte first, Byte second)
 {
     if (midiOutputDevice != null)
     {
         var onEvent = new ControlChangeEvent(0, channel, (MidiController)first, second);
         midiOutputDevice.Send(onEvent.GetAsShortMessage());
     }
 }
 private void PlayNote(int NoteNumber)
 {
     System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart((note) => {
         try
         {
             using (MidiOut midiOut = new MidiOut(0))
             {
                 midiOut.Volume = 65535;
                 midiOut.Send(MidiMessage.StartNote(NoteNumber, 127, 1).RawData);
                 System.Threading.Thread.Sleep(1000);
                 midiOut.Send(MidiMessage.StopNote(NoteNumber, 127, 1).RawData);
             }
         }
         catch {; }
     }));
     th.Start(NoteNumber);
 }
Example #19
0
 public void Play(int bar, MidiOut midi)
 {
     if (playing)
     {
         var previousBar = bar - 1;
         if (previousBar < 0)
         {
             previousBar = keys.Length - 1;
         }
         midi.Send(MidiMessage.StopNote(keys[previousBar], 127, 10).RawData);
         playing = false;
     }
     if (keys[bar] != 0)
     {
         midi.Send(MidiMessage.StartNote(keys[bar], 127, 10).RawData);
         playing = true;
     }
 }
Example #20
0
        public void Send()
        {
            //todo https://github.com/naudio/NAudio/blob/master/Docs/MidiInAndOut.md
            _bassMidiOut.Send(new NoteEvent(5, 1, MidiCommandCode.NoteOn, 50, 64).GetAsShortMessage());
            _bassMidiOut.Dispose();

            _tenorMidiOut.Send(new NoteEvent(1000, 1, MidiCommandCode.NoteOn, 58, 64).GetAsShortMessage());
            _tenorMidiOut.Dispose();
        }
Example #21
0
    private void SendMessage(int note, int velocity, int channel = 1, bool ignoreControls = false)
    {
        if (ignoreControls && IsControl(note))
        {
            return;
        }
        var noteOnEvent = new NoteOnEvent(0, channel, note, velocity, 1);

        controllerOut.Send(noteOnEvent.GetAsShortMessage());
    }
Example #22
0
        private static void RandomlyPlaystuff()
        {
            int    midiOutDevice = 0; // GS Wavetable Synth
            Random r             = new Random();

            Dictionary <string, NoteOnEvent> currentlyPlaying = new Dictionary <string, NoteOnEvent>();


            using (var midiOut = new MidiOut(midiOutDevice))
            {
                // first lets set the patches for channels 1-9
                for (int i = 1; i <= 9; i++)
                {
                    var patchChange = new PatchChangeEvent(0, i, (i - 1) * 8);
                    midiOut.Send(patchChange.GetAsShortMessage());
                }
                // Okay, now lets figure out where our things are at

                for (int i = 0; i < 100; i++)
                {
                    int noteToPlay     = r.Next(20, 100);
                    int velocityToPlay = r.Next(50, 100);
                    int channel        = r.Next(1, 2); // channel indicates patch

                    string hash = $"{channel}";

                    NoteOnEvent existingNoteOn;
                    if (currentlyPlaying.TryGetValue(hash, out existingNoteOn))
                    {
                        midiOut.Send(existingNoteOn.OffEvent.GetAsShortMessage());
                        currentlyPlaying.Remove(hash);
                    }

                    var noteOn = new NoteOnEvent(0, channel, noteToPlay, velocityToPlay, 0);
                    midiOut.Send(noteOn.GetAsShortMessage());
                    Console.ReadLine();
                }
                foreach (var existingNote in currentlyPlaying.Values)
                {
                    midiOut.Send(existingNote.OffEvent.GetAsShortMessage());
                }
            }
        }
Example #23
0
 void stopNote(int note)
 {
     if (midiOutIndex == -1)
     {
         return;
     }
     using (MidiOut midiOut = new MidiOut(midiOutIndex))
     {
         midiOut.Send(MidiMessage.StopNote(note, 127, 1).RawData);
     }
 }
Example #24
0
 void playNote(int note)
 {
     if (midiOutIndex == -1)
     {
         return;
     }
     using (MidiOut midiOut = new MidiOut(midiOutIndex))
     {
         midiOut.Send(MidiMessage.StartNote(note, 127, 1).RawData);
         Console.WriteLine("play note" + note);
     }
 }
Example #25
0
 static void Main()
 {
     using (MidiOut midiOut = new MidiOut(0))
     {
         midiOut.Volume = 65535;
         midiOut.Send(MidiMessage.StartNote(60, 127, 1).RawData);
         //MessageBox.Show("Sent");
         Thread.Sleep(300);
         //midiOut.Send(MidiMessage.StopNote(60, 0, 1).RawData);
         Thread.Sleep(300);
     }
 }
Example #26
0
 public static void PlayNote(int key, int duration)
 {
     MidiOut.Volume = 65535;
     MidiOut.Send(MidiMessage.StartNote(key, 127, 1).RawData);
     Thread.Sleep(duration);
     MidiOut.Send(MidiMessage.StopNote(key, 0, 1).RawData);
 }
Example #27
0
        public void PlayNotes(IEnumerable <Note> noteSequence, int instrumentNumber, int channelNumber, int volume, bool playUntilKeyHit = false)
        {
            midiOut.Send(MidiMessage.ChangePatch(instrumentNumber, channelNumber).RawData);
            bool breakWhileLoop = false;

            do
            {
                foreach (var note in noteSequence)
                {
                    midiOut.Send(MidiMessage.StartNote(note.Number, volume, channelNumber).RawData);
                    Thread.Sleep(note.DurationInMs);
                    midiOut.Send(MidiMessage.StopNote(note.Number, volume, channelNumber).RawData);
                    if (Console.KeyAvailable)
                    {
                        breakWhileLoop = true;
                        break;
                    }
                }
            } while (playUntilKeyHit && !(breakWhileLoop));

            return;
        }
Example #28
0
 private void PlayNote(MidiOut midi, List <Note> song, ref int songTime, ref Timer t, int songL)
 {
     if (songTime == songL)
     {
         t.Stop();
     }
     Console.WriteLine("Interval: {0}", songTime);
     foreach (Note n in song)
     {
         if (songTime == n.milliIntoSongStart)
         {
             //play note
             midi.Send(MidiMessage.StartNote(Note.NoteToMIDI(n), n.Volume, 1).RawData);
         }
         if (songTime == n.milliIntoSongEnd)
         {
             //Stop playing that note
             midi.Send(MidiMessage.StopNote(Note.NoteToMIDI(n), 0, 1).RawData);
         }
     }
     songTime += 5;
 }
Example #29
0
        public void NoteOn(int note, int vel, int channel)
        {
            if (valid8bit(note) && valid8bit(vel))
            {
                //for (int arp = 0; arp < 5; arp++)
                //{
                if (forceScaleCorrection)
                {
                    note = pitchCorrection(note + octShift);
                }

                if (currentNoteOn[channel] > 0)
                {
                    NoteOff(channel);
                }                                                          //turn off any currently sounding notes = monophonic instrument

                currentNoteOn[channel] = note;
                midiOut.Send(MidiMessage.StartNote(note, vel, channel).RawData);

                //Thread.Sleep(10);
                //}
            }
        }
Example #30
0
        /// <summary>
        /// Sends the patch change currently being composed. A patch number must be set
        /// before the sending the event.
        /// </summary>
        /// <returns>The currently selected <see cref="IMidiOutputDevice"/>.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the control
        /// number or value have not been set yet.</exception>
        public IMidiOutputDevice Send()
        {
            if (this._patchNumber == null)
            {
                throw new InvalidOperationException("A patch number is required");
            }

            using (MidiOut midi = new MidiOut(this._device.DeviceId))
            {
                midi.Send(new PatchChangeEvent(0, this._channel, this._patchNumber.Value).GetAsShortMessage());
            }

            return(this._device);
        }