private void InternalNote(Object o, ChannelMessageEventArgs args)
        {
            ChannelMessageBuilder builder = new ChannelMessageBuilder(args.Message);

            NoteEvent noteEvent = new NoteEvent {
                note     = builder.Data1,
                origNote = builder.Data1,
                trackNum = sequencer.GetTrackNum(args.MidiTrack),
                track    = args.MidiTrack,
            };

            if (sequencer.GetTrackNum(noteEvent.track) == this.TrackNum)
            {
                noteEvent.note = NoteHelper.ApplyOctaveShift(noteEvent.note, this.OctaveNum);

                ChannelCommand cmd = args.Message.Command;
                int            vel = builder.Data2;
                if ((cmd == ChannelCommand.NoteOff) || (cmd == ChannelCommand.NoteOn && vel == 0))
                {
                    this.ProcessOffNote(noteEvent);
                }
                if ((cmd == ChannelCommand.NoteOn) && vel > 0)
                {
                    this.ProcessOnNote(noteEvent);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the ChannelMessage class with the
 /// specified command value, Midi channel, and first data value.
 /// </summary>
 /// <param name="command">
 /// The Midi command represented by the message.
 /// </param>
 /// <param name="channel">
 /// The Midi channel associated with the message.
 /// </param>
 /// <param name="data1">
 /// The first data value.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Thrown if the Midi channel or the first data value is out of range.
 /// </exception>
 public ChannelMessage(ChannelCommand command, int channel,
                       int data1)
 {
     Command     = command;
     MidiChannel = channel;
     Data1       = data1;
 }
Exemple #3
0
        void HandleChannelCommand(ChannelCommand packet)
        {
            Channel channel = ChannelManager.GetChannelForPlayerByNamePart(packet.ChannelName, GetPlayer());

            if (channel == null)
            {
                return;
            }

            switch (packet.GetOpcode())
            {
            case ClientOpcodes.ChatChannelAnnouncements:
                channel.Announce(GetPlayer());
                break;

            case ClientOpcodes.ChatChannelDeclineInvite:
                channel.DeclineInvite(GetPlayer());
                break;

            case ClientOpcodes.ChatChannelDisplayList:
            case ClientOpcodes.ChatChannelList:
                channel.List(GetPlayer());
                break;

            case ClientOpcodes.ChatChannelOwner:
                channel.SendWhoOwner(GetPlayer());
                break;
            }
        }
Exemple #4
0
        private void DrawNotes(Graphics g, Rectangle visibleAreaRectangle, Dictionary <Track.Command, CommandLineInfo> visibleNoteList)
        {
            //if (Channel == null)
            //{
            //    // nothing to draw
            //    return;
            //}

            int keysX = this.TextAreaWidth + 1;
            var brush = Brushes.Black;

            foreach (var info in visibleNoteList.Values)
            {
                if (ChannelCommand.NoteIsSharp(info.Command))
                {
                    brush = Brushes.Black;
                }
                else
                {
                    brush = Brushes.White;
                }
                g.FillRectangle(brush, keysX, info.LineArea.Y, keyAreaWidth, info.LineArea.Height);

                g.DrawString(info.Command.GetDescription(),
                             this.Font,
                             Brushes.Black,
                             2,
                             info.LineArea.Y + (info.LineArea.Height / 2) - (g.MeasureString(info.Command.GetDescription(), this.Font).Height / 2));
            }
        }
Exemple #5
0
        public static ChannelMessage ConvertKeyStrokeEventArgsToChannelMessage(PianoKeyStrokeEventArgs keyStrokeEventArgs)
        {
            if (keyStrokeEventArgs == null)
            {
                return(null);
            }

            var channelCommand = new ChannelCommand();
            int data1          = keyStrokeEventArgs.midiKeyId;
            int data2          = keyStrokeEventArgs.KeyVelocity;

            //If the key stroke is neither a press or a release, return a null object
            switch (keyStrokeEventArgs.KeyStrokeType)
            {
            case KeyStrokeType.KeyPress:
                channelCommand = ChannelCommand.NoteOn;
                break;

            case KeyStrokeType.KeyRelease:
                channelCommand = ChannelCommand.NoteOn;
                data2          = 0;
                break;

            default: return(null);
            }

            return(new ChannelMessage(channelCommand, 1, data1, data2));
        }
 public MidiToSendModel(ChannelCommand channelCommand, int b1, int b2, int b3)
 {
     this.channelCommand = channelCommand;
     B1 = b1;
     B2 = b2;
     B3 = b3;
 }
Exemple #7
0
 public static void Split(this ChannelMessage message, out ChannelCommand command, out int channel, out int number, out int value)
 {
     command = message.Command;
     channel = message.MidiChannel;
     number  = message.Data1;
     value   = message.Data2;
 }
 public ChannelMessage(ChannelCommand command, int midiChannel, int data1)
 {
     this.command     = command;
     this.midiChannel = midiChannel;
     this.data1       = data1;
     this.messageType = MessageType.Channel;
 }
        /// <summary>
        /// Reads the next channel message.
        /// </summary>
        /// <param name="status">
        /// The status value for the next channel message.
        /// </param>
        /// <param name="data1">
        /// The first data byte.
        /// </param>
        /// <returns>
        /// The next channel message.
        /// </returns>
        private ChannelMessage ReadChannelMessage(int status, int data1)
        {
            ChannelMessage msg;
            ChannelCommand command = (ChannelCommand)(status & ChannelMask);
            int            channel = status & ~ChannelMask;

            // If this is a channel message that has two data bytes.
            if (command != ChannelCommand.ChannelPressure &&
                command != ChannelCommand.ProgramChange)
            {
                // Get second data byte.
                int data2 = binReader.ReadByte();

                // Create channel message.
                msg = new ChannelMessage(command, channel, data1, data2);
            }
            // Else this channel message only has one data byte.
            else
            {
                // Create channel message.
                msg = new ChannelMessage(command, channel, data1);
            }

            return(msg);
        }
Exemple #10
0
        /// <summary>
        /// Envoi une instruction Midi
        /// </summary>
        /// <param name="type"></param>
        /// <param name="channel"></param>
        /// <param name="data1"></param>
        /// <param name="data2"></param>
        private static void SendChannel(ChannelCommand type, int channel, int data1, int data2)
        {
            if (IsConnect())
            {
                try
                {
                    _msg.Command     = type;
                    _msg.MidiChannel = channel;
                    _msg.Data1       = data1;
                    _msg.Data2       = data2;

                    _msg.Build();

                    _OutputLaunchPad.Send(_msg.Result);
                }
                catch (Exception)
                {
                    throw new ErrorSendingDataException();
                }
            }
            else
            {
                throw new NoMidiDeviceConnectedException();
            }
        }
Exemple #11
0
        void DrawCommand(ChannelCommand command, int xBase, int yBase, Graphics g, StringFormat style)
        {
            int x = xBase;
            int y = yBase;

            var cmd  = (ZMusicMagicLibrary.NSPC.Track.Command)command.Command;
            var text = $"{cmd.GetDescription()}";

            if (command.Command >= 0x01 && command.Command < 0x80)
            {
                text = $"{command.Command.ToString("X2")}";
            }
            if (command.Parameters.Count > 0)
            {
                text += $" ( {String.Join(",", command.Parameters.Select(o => o.ToString("X2")).ToArray())} )";
            }
            g.DrawString(text, Font, new SolidBrush(ForeColor), x, y, style);

            var stringSize = g.MeasureString(text, Font);

            y += (int)stringSize.Height + 2;

            //if ((int)stringSize.Width > maxX)
            //{
            //    maxX = (int)stringSize.Width + 10;
            //}
        }
 public void SendChannelMessage(ChannelCommand command, int midiChannel, byte data1)
 {
     var handler = ChannelMessageReceived;
     if(handler != null)
     {
         handler(this, new ChannelMessageEventArgs(new ChannelMessage(command, midiChannel, data1)));
     }
 }
Exemple #13
0
 public MidiMessage(int data1, int data2, ChannelCommand message, int firsttime, int lasttime)
 {
     Data1       = data1;
     Data2       = data2;
     MessageType = message;
     FirstTime   = firsttime;
     LastTime    = lasttime;
 }
/*
        public MidiInputEvent(ChannelMessage message)
        {
            //note-on command with velocity of 0 is note-off command
            if (message.Command == ChannelCommand.NoteOn && message.Data2 == 0)
            {
                Command = ChannelCommand.NoteOff;
            }
            else
            {
                Command = message.Command;
            }

            Command = message.Command;
            MidiChannel = message.MidiChannel;
            Data1 = message.Data1;

            bindableObject = new BindableObject(String.Format("MIDI_{0}_{1}_{2}", Command, MidiChannel, Data1),  this);
        }
*/

        public MidiEventBase(ChannelCommand channelCommand, int midiChannel, int data1, int data2)
        {
            this.channelCommand = channelCommand;
            this.midiChannel = midiChannel;
            this.data1 = data1;
            this.data2 = data2;

            bindingId = GetID(channelCommand, midiChannel, data1, data2);
        }
Exemple #15
0
 private bool IsNoteOffEvent(ChannelCommand command, int channel, MidiEvent @event)
 {
     // An event is a NoteOff event if it is actually a NoteOff event,
     // or if it is a NoteOn event where the note has already been played and the attack velocity is 0.
     return((command == ChannelCommand.NoteOff) ||
            ((command == ChannelCommand.NoteOn) &&
             (noteCache?[channel]?.GetValueOrDefault(@event.MidiMessage.GetBytes()[1]) != null) &&
             (@event.MidiMessage.GetBytes()[2] == 0)));
 }
Exemple #16
0
 public static void Send(this OutputDevice device, ChannelMessageBuilder builder,
                         ChannelCommand command, int data1, int data2 = 0, int midiChannel = 0)
 {
     builder.Command     = command;
     builder.Data1       = data1;
     builder.Data2       = data2;
     builder.MidiChannel = midiChannel;
     builder.Build();
     device.Send(builder.Result);
 }
 public void MIDI_Send(ChannelCommand miditype, int midichdev, int midiparm, int mididata1, int mididata2)
 {
     try
     {
         this.outDevice.Send(new ChannelMessage(miditype, (int)midichdev, (int)mididata1, (int)mididata2));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
     }
 }
Exemple #18
0
        private static ChannelMessage GetChannelMessage(ChannelCommand command, int channel, int data1, int data2)
        {
            ChannelMessageBuilder on = new ChannelMessageBuilder();
            on.MidiChannel = channel;
            on.Command = command;
            on.Data1 = data1;
            on.Data2 = data2;
            on.Build();

            return on.Result;
        }
Exemple #19
0
        public void SendMIDI(ChannelCommand command, int channel, int data1, int data2)
        {
            if (!connected)
            {
                return;
            }

            ChannelMessage cm = new ChannelMessage(command, channel, data1, data2);

            outDevice.Send(cm);
        }
Exemple #20
0
        private void ZapalMidi(Panel panel, ChannelCommand cm)
        {
            ChannelMessageBuilder cmb = new ChannelMessageBuilder();

            cmb.Command     = cm;
            cmb.MidiChannel = 3;
            cmb.Data1       = Convert.ToInt32(panel.Tag);
            cmb.Data2       = 127;
            cmb.Build();

            outDevice1.Send(cmb.Result);
        }
Exemple #21
0
 /// <summary>
 /// Returns a value indicating how many bytes are used for the
 /// specified channel command type.
 /// </summary>
 /// <param name="cmd">
 /// The channel command type to test.
 /// </param>
 /// <returns>
 /// The number of bytes used for the specified channel command type.
 /// </returns>
 public static int BytesPerType(ChannelCommand cmd)
 {
     if (cmd == ChannelCommand.ChannelPressure ||
         cmd == ChannelCommand.ProgramChange)
     {
         return(1);
     }
     else
     {
         return(2);
     }
 }
Exemple #22
0
        /// <summary>
        /// Adds a MIDI event to the current track
        /// </summary>
        /// <param name="command">MIDI command represented by the message</param>
        /// <param name="data">The first data byte</param>
        public void AddEvent(ChannelCommand command, int data)
        {
            var shortMessageBuilder = new ChannelMessageBuilder
            {
                Command = command,
                Data1   = CurrentTrackNumber,
                Data2   = data,
            };

            shortMessageBuilder.Build();
            QueueMessage(shortMessageBuilder.Result);
        }
Exemple #23
0
        public static void SplitAs(this ChannelMessage message, ChannelCommand command, out bool success, out int channel, out int number, out int value)
        {
            if (message.Command == command)
            {
                success = true;
                message.Split(out command, out channel, out number, out value);
            }

            success = false;
            channel = 0;
            number  = 0;
            value   = 0;
        }
Exemple #24
0
        public void CustomFeedBack(string devname, TodoVariable var, double value)
        {
            int idx = this.outputdevname.IndexOf(devname);

            //Need to find device and have it started
            if (idx > -1)
            {
                if (this.outputstatus[idx] == eTodoMidiStatus.Started)
                {
                    try
                    {
                        OutputDevice dev = this.outdevs[idx];
                        foreach (AbstractTodoInput ti in var.Inputs)
                        {
                            if (ti is TodoMidiInput)
                            {
                                TodoMidiInput mi = (TodoMidiInput)ti;

                                if (mi.Device == devname || mi.Device == "Any")
                                {
                                    ChannelCommand cmd = ChannelCommand.Controller;
                                    if (mi.ControlType == eTodoMidiType.Controller)
                                    {
                                        cmd = ChannelCommand.Controller;
                                    }
                                    else
                                    {
                                        if (mi.ControlType == eTodoMidiType.Note)
                                        {
                                            if (value == 0.0)
                                            {
                                                cmd = ChannelCommand.NoteOff;
                                            }
                                            else
                                            {
                                                cmd = ChannelCommand.NoteOn;
                                            }
                                        }
                                    }
                                    ChannelMessage msg = new ChannelMessage(cmd, mi.MidiChannel, mi.ControlValue, Convert.ToInt32(value * 127.0));
                                    dev.Send(msg);
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
        /// <summary>
        /// Returns a value indicating how many bytes are used for the
        /// specified ChannelCommand.
        /// </summary>
        /// <param name="command">
        /// The ChannelCommand value to test.
        /// </param>
        /// <returns>
        /// The number of bytes used for the specified ChannelCommand.
        /// </returns>
        internal static int DataBytesPerType(ChannelCommand command)
        {
            int result;

            if (command == ChannelCommand.ChannelPressure || command == ChannelCommand.ProgramChange)
            {
                result = 1;
            }
            else
            {
                result = 2;
            }

            return(result);
        }
Exemple #26
0
        /// <summary>
        /// Initializes a new instance of the ChannelEventArgs class with the
        /// specified command, MIDI channel, and data 1 values.
        /// </summary>
        /// <param name="command">
        /// The command value.
        /// </param>
        /// <param name="midiChannel">
        /// The MIDI channel.
        /// </param>
        /// <param name="data1">
        /// The data 1 value.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If midiChannel is less than zero or greater than 15. Or if
        /// data1 is less than zero or greater than 127.
        /// </exception>
        public ChannelMessage(ChannelCommand command, int midiChannel, int data1)
        {
            msg = 0;

            msg = PackCommand(msg, command);
            msg = PackMidiChannel(msg, midiChannel);
            msg = PackData1(msg, data1);

            #region Ensure

            Debug.Assert(Command == command);
            Debug.Assert(MidiChannel == midiChannel);
            Debug.Assert(Data1 == data1);

            #endregion
        }
Exemple #27
0
        public void KeyPressEvent(MidiKeyboard keyboard, int key, ChannelCommand command)
        {
            if (command != ChannelCommand.NoteOn)
            {
                return;
            }

            lock (this)
            {
                if (ready)
                {
                    return;
                }

                var on = keyboard.OnKeys;

                if (on.Count() == 1)
                {
                    timeFirstNotePlayed = DateTime.Now;
                }

                if (on.Count() != chord.Count())
                {
                    return;
                }

                if ((DateTime.Now - timeFirstNotePlayed).TotalMilliseconds >= 500)
                {
                    return;
                }


                for (int i = 0; i < chord.Count(); i++)
                {
                    if ((absolute && (on.ElementAt(i).AbsolutePitch != chord.ElementAt(i))) ||
                        (!absolute && (on.ElementAt(i).RelativePitch != chord.ElementAt(i))))
                    {
                        Played = false;
                        ready  = true;
                        return;
                    }
                }
                Played = true;
                ready  = true;
                return;
            }
        }
 public ChannelMessage(ChannelCommand command, int data1, int data2, int midiChannel = 0)
 {
     msg = 0;
     msg = PackCommand(msg, command);
     if (midiChannel != 0)
     {
         msg = PackMidiChannel(msg, midiChannel);
     }
     if (data1 != 0)
     {
         msg = PackData1(msg, data1);
     }
     if (data2 != 0)
     {
         msg = PackData2(msg, data2);
     }
 }
Exemple #29
0
        public void KeyPressEvent(MidiKeyboard keyboard, int absolutePitch, ChannelCommand command)
        {
            if (command != ChannelCommand.NoteOn)
            {
                return;
            }

            lock (this)
            {
                if (ready)
                {
                    return;
                }

                this.Played = this.keyToPlay.AbsolutePitch == absolutePitch;
                this.ready  = true;
            }
        }
Exemple #30
0
    /// <summary>
    /// Initializes a new instance of the ChannelEventArgs class with the
    /// specified command, MIDI channel, data 1, and data 2 values.
    /// </summary>
    /// <param name="command">
    /// The command value.
    /// </param>
    /// <param name="midiChannel">
    /// The MIDI channel.
    /// </param>
    /// <param name="data1">
    /// The data 1 value.
    /// </param>
    /// <param name="data2">
    /// The data 2 value.
    /// </param>
    /// <exception cref="ArgumentOutOfRangeException">
    /// If midiChannel is less than zero or greater than 15. Or if
    /// data1 or data 2 is less than zero or greater than 127.
    /// </exception>
    public ChannelMessage(ChannelCommand command, int midiChannel,
                          int data1, int data2)
    {
        msg = 0;

        msg = PackCommand(msg, command);
        msg = PackMidiChannel(msg, midiChannel);
        msg = PackData1(msg, data1);
        msg = PackData2(msg, data2);

        #region Ensure

        System.Diagnostics.Debug.Assert(Command == command);
        System.Diagnostics.Debug.Assert(MidiChannel == midiChannel);
        System.Diagnostics.Debug.Assert(Data1 == data1);
        System.Diagnostics.Debug.Assert(Data2 == data2);

        #endregion
    }
        public static ChannelMessage ConvertKeyStrokeEventArgsToChannelMessage(PianoKeyStrokeEventArgs keyStrokeEventArgs)
        {
            var channelCommand = new ChannelCommand();
            int data1 = keyStrokeEventArgs.midiKeyId;
            int data2 = keyStrokeEventArgs.KeyVelocity;

            //If the key stroke is neither a press or a release, return a null object
            switch (keyStrokeEventArgs.keyStrokeType)
            {
                case KeyStrokeType.KeyPress:
                    channelCommand = ChannelCommand.NoteOn;
                    break;
                case KeyStrokeType.KeyRelease:
                    channelCommand = ChannelCommand.NoteOn;
                    data2 = 0;
                    break;
                default: return null;
            }

            return new ChannelMessage(channelCommand, 1, data1, data2);
        }
Exemple #32
0
        public void setLed(ChannelCommand command, int channel, ledMode ledMode)
        {
            ChannelMessage channelMessage = null;

            switch (ledMode)
            {
            case ledMode.Off:
                channelMessage = new ChannelMessage(command, 1, channel, 0);
                break;

            case ledMode.Green:
                channelMessage = new ChannelMessage(command, 1, channel, 1);
                break;

            case ledMode.BlinkGreen:
                channelMessage = new ChannelMessage(command, 1, channel, 2);
                break;

            case ledMode.Red:
                channelMessage = new ChannelMessage(command, 1, channel, 3);
                break;

            case ledMode.BlinkRed:
                channelMessage = new ChannelMessage(command, 1, channel, 4);
                break;

            case ledMode.Yellow:
                channelMessage = new ChannelMessage(command, 1, channel, 5);
                break;

            case ledMode.BlinkYellow:
                channelMessage = new ChannelMessage(command, 1, channel, 6);
                break;

            default:
                channelMessage = new ChannelMessage(command, 1, channel, 127);
                break;
            }
            _outputDevice.Send(channelMessage);
        }
Exemple #33
0
        public void KeyPressEvent(MidiKeyboard keyboard, int absolutePitch, ChannelCommand command)
        {
            if (command != ChannelCommand.NoteOn)
            {
                return;
            }

            lock (this)
            {
                if (ready)
                {
                    return;
                }

                if ((DateTime.Now - lastKeyPress).TotalMilliseconds <= 500)
                {   // Don't accept key press if it happens nearly simultaneously
                    return;
                }
                int relativePitch = absolutePitch % 12;
                if ((absolute && (absolutePitch == melody.ElementAt(idx))) ||
                    (!absolute && (relativePitch == melody.ElementAt(idx))))
                {   // If we played the correct note in the sequence then move to next note
                    lastKeyPress = DateTime.Now;
                    idx++;
                    if (idx == melody.Count)
                    {   // If we've played all the notes in the sequence then end
                        Played = true;
                        ready  = true;
                        return;
                    }
                }
                else if (breakOnError)
                {
                    // we played a wrong note and breakOnError == true
                    ready = true;
                }
            }
        }
Exemple #34
0
        protected override void DoFeedBack(TodoVariable var, TodoMidiInput source)
        {
            for (int i = 0; i < this.outputstatus.Count; i++)
            {
                if (this.outputstatus[i] == eTodoMidiStatus.Started)
                {
                    try
                    {
                        OutputDevice   dev = this.outdevs[i];
                        ChannelCommand cmd = ChannelCommand.Controller;
                        if (source.ControlType == eTodoMidiType.Controller)
                        {
                            cmd = ChannelCommand.Controller;
                        }
                        else
                        {
                            if (source.ControlType == eTodoMidiType.Note)
                            {
                                if (var.ValueRaw == 0.0)
                                {
                                    cmd = ChannelCommand.NoteOff;
                                }
                                else
                                {
                                    cmd = ChannelCommand.NoteOn;
                                }
                            }
                        }

                        ChannelMessage msg = new ChannelMessage(cmd, source.MidiChannel, source.ControlValue, Convert.ToInt32(var.ValueRaw * 127.0));
                        dev.Send(msg);
                    }
                    catch
                    {
                    }
                }
            }
        }
Exemple #35
0
		public void InsertChannelMessage(int pos, ChannelCommand command, int midiChannel, int data1, int data2)
		{
			Console.WriteLine("InsertChannelMessage({0}, {1}, {2}, {3}, {4});", pos, command, midiChannel, data1, data2);
			_track.Insert(pos, new ChannelMessage(command, midiChannel, data1, data2));
		}
Exemple #36
0
        /// <summary>
        /// Initializes a new instance of the ChannelEventArgs class with the 
        /// specified command, MIDI channel, data 1, and data 2 values.
        /// </summary>
        /// <param name="command">
        /// The command value.
        /// </param>
        /// <param name="midiChannel">
        /// The MIDI channel.
        /// </param>
        /// <param name="data1">
        /// The data 1 value.
        /// </param>
        /// <param name="data2">
        /// The data 2 value.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If midiChannel is less than zero or greater than 15. Or if 
        /// data1 or data 2 is less than zero or greater than 127. 
        /// </exception>
        public ChannelMessage(ChannelCommand command, int midiChannel, 
            int data1, int data2)
        {
            msg = 0;

            msg = PackCommand(msg, command);
            msg = PackMidiChannel(msg, midiChannel);
            msg = PackData1(msg, data1);
            msg = PackData2(msg, data2);

            #region Ensure

            Debug.Assert(Command == command);
            Debug.Assert(MidiChannel == midiChannel);
            Debug.Assert(Data1 == data1);
            Debug.Assert(Data2 == data2);

            #endregion
        }
Exemple #37
0
 protected MidiSlider(int channel, ChannelCommand command, byte msb, byte lsb, ControlContinuation continuation)
     : base(channel, command, msb, lsb)
 {
 }
Exemple #38
0
 /// <summary>
 /// Sets the control's ChannelMessage MSB and LSB.
 /// </summary>
 protected MidiControl(int channel, ChannelCommand command, byte msb, byte lsb)
 {
     ChannelMessages.Add(BuildMessage(command, channel, msb, lsb));
 }
Exemple #39
0
        protected ChannelMessage BuildMessage(ChannelCommand command, int channel, int data1, int data2)
        {
            if(channel > 15 || channel < 0)
                throw new ApplicationException("Channel index must be in range 0..15");
            if(data1 > 127 || data1 < 0)
                throw new ApplicationException("Value must be in range 0..127");
            if(data2 > 127 || data2 < 0)
                throw new ApplicationException("Value must be in range 0..127");

            ChannelMessageBuilder builder = new ChannelMessageBuilder();
            builder.Command = command;
            builder.MidiChannel = channel;
            builder.Data1 = data1;
            builder.Data2 = data2;
            builder.Build();
            return builder.Result;
        }
 /// <summary>
 /// Returns a value indicating how many bytes are used for the 
 /// specified channel command type.
 /// </summary>
 /// <param name="cmd">
 /// The channel command type to test.
 /// </param>
 /// <returns>
 /// The number of bytes used for the specified channel command type.
 /// </returns>
 public static int BytesPerType(ChannelCommand cmd)
 {
     if(cmd == ChannelCommand.ChannelPressure ||
         cmd == ChannelCommand.ProgramChange)
         return 1;
     else
         return 2;
 }
 public NoteEvent(ChannelCommand command, int midiChannel, int data1)
     : base(command, midiChannel, data1, 0)
 {
 }
Exemple #42
0
 /// <summary>
 /// Sets the control's ChannelMessage MSB and LSB.
 /// </summary>
 protected MidiControl(int channel, ChannelCommand command, int msb, int lsb)
 {
     ChannelMessages.Add(new ChannelMessage(command, channel, msb, lsb));
 }
Exemple #43
0
 /// <summary>
 /// Sets the control's ChannelMessage MSB. LSBs are not used.
 /// </summary>
 protected MidiControl(int channel, ChannelCommand command, int value)
 {
     ChannelMessages.Add(new ChannelMessage(command, channel, value, 0));
 }
 /// <summary>
 /// Initializes a new instance of the ChannelMessage class with the 
 /// specified command value.
 /// </summary>
 /// <param name="command">
 /// The Midi command represented by this message.
 /// </param>
 public ChannelMessage(ChannelCommand command)
 {
     Command = command;
     MidiChannel = 0;
 }
        public static string GetID(ChannelCommand command, int midiChannel, int data1, int data2)
        {

            string format;
            switch (command)
            {

                // ignore noteOff and make it noteOn.
                case (ChannelCommand.NoteOff):
                    format = String.Format("MIDI_{0}_{1}_{2}", ChannelCommand.NoteOn, midiChannel, data1);
                    break;

                default:
                    format = String.Format("MIDI_{0}_{1}_{2}", command, midiChannel, data1);
                    break;
            }

            return format;
        }
Exemple #46
0
        protected List<ChannelMessage> GetChannelMessages(ChannelCommand noteOnOff)
        {
            List<ChannelMessage> messages = new List<ChannelMessage>();
            ChannelMessageBuilder builder = new ChannelMessageBuilder();
            builder.MidiChannel = this.Channel;

            //foreach(MidiControl midiControl in this.MidiControls)
            //{
            //    messages.AddRange(midiControl.ChannelMessages);
            //}
            builder.Command = noteOnOff;
            foreach(NoteMessage midiNote in _notes)
            {
                builder.Data1 = midiNote.Pitch;
                builder.Data2 = midiNote.Velocity;

                builder.Build();

                messages.Add(builder.Result);
            }
            return messages;
        }
 public MidiEventBase CreateMidiEvent(ChannelCommand command, int midiChannel, int data1, int data2)
 {
     return CreateMidiEvent(MidiEventBase.GetID(command, midiChannel, data1, data2));
 }
 /// <summary>
 /// Initializes a new instance of the ChannelMessage class with the
 /// specified command value, Midi channel, first data value, and 
 /// second data value.
 /// </summary>
 /// <param name="command">
 /// The Midi command represented by the message.
 /// </param>
 /// <param name="channel">
 /// The Midi channel associated with the message.
 /// </param>
 /// <param name="data1">
 /// The first data value.
 /// </param>
 /// <param name="data2">
 /// The second data value.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Thrown if the Midi channel, first data value, or second data value 
 /// is out of range.
 /// </exception>
 public ChannelMessage(ChannelCommand command, int channel, 
     int data1, int data2)
 {
     Command = command;
     MidiChannel = channel;
     Data1 = data1;
     Data2 = data2;
 }
Exemple #49
0
 protected MidiSwitch(int channel, ChannelCommand command, byte value)
     : base(channel, command, value)
 {
 }
        /// <summary>
        /// Returns a value indicating how many bytes are used for the 
        /// specified ChannelCommand.
        /// </summary>
        /// <param name="command">
        /// The ChannelCommand value to test.
        /// </param>
        /// <returns>
        /// The number of bytes used for the specified ChannelCommand.
        /// </returns>
        internal static int DataBytesPerType(ChannelCommand command)
        {
            int result;

            if (command == ChannelCommand.ChannelPressure || command == ChannelCommand.ProgramChange)
            {
                result = 1;
            }
            else
            {
                result = 2;
            }

            return result;
        }
 public ControlChangeEvent(ChannelCommand command, int midiChannel, int data1): base(command, midiChannel, data1, 0)
 {
 }
 /// <summary>
 /// Packs the command value into an integer message.
 /// </summary>
 /// <param name="message">
 /// The message into which the command is packed.
 /// </param>
 /// <param name="command">
 /// The command value to pack into the message.
 /// </param>
 /// <returns>
 /// An integer message.
 /// </returns>
 internal static int PackCommand(int message, ChannelCommand command)
 {
     return (message & CommandMask) | (int)command;
 }
Exemple #53
0
 /// <summary>
 /// Sets the control's ChannelMessage MSB. LSBs are not used.
 /// </summary>
 protected MidiControl(int channel, ChannelCommand command, byte value)
 {
     ChannelMessages.Add(BuildMessage(command, channel, value, 0));
 }
 /// <summary>
 /// Initializes a new instance of the ChannelMessage class with the 
 /// specified command value and Midi channel.
 /// </summary>
 /// <param name="command">
 /// The Midi command represented by the message.
 /// </param>
 /// <param name="channel">
 /// The Midi channel associated with the message.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// Thrown if the Midi channel is set to a value less than zero or 
 /// greater than ChannelValueMax.
 /// </exception>
 public ChannelMessage(ChannelCommand command, int channel)
 {
     Command = command;
     MidiChannel = channel;
 }
 public ChannelMessage(ChannelCommand command, int data1, int data2, int midiChannel = 0)
 {
     msg = 0;
     msg = PackCommand(msg, command);
     if (midiChannel != 0)
         msg = PackMidiChannel(msg, midiChannel);
     if (data1 != 0)
         msg = PackData1(msg, data1);
     if (data2 != 0)
         msg = PackData2(msg, data2);
 }
        private void ZapalMidi(Panel panel, ChannelCommand cm)
        {
            ChannelMessageBuilder cmb = new ChannelMessageBuilder();
            cmb.Command = cm;
            cmb.MidiChannel = 3;
            cmb.Data1 = Convert.ToInt32(panel.Tag);
            cmb.Data2 = 127;
            cmb.Build();

            outDevice1.Send(cmb.Result);
        }