コード例 #1
0
ファイル: CarryMsgs.cs プロジェクト: notator/MNXtoSVG
        /// <summary>
        /// Checks that the new msg is a noteOff and has the same channel as existing msgs.
        /// </summary>
        private void CheckMsg(MidiMsg msg)
        {
            M.Assert(IsNoteOffMsg(msg));

            if (_msgs.Count > 0 && (_msgs[0].Channel != msg.Channel))
            {
                M.Assert(false);
            }
        }
コード例 #2
0
ファイル: CarryMsgs.cs プロジェクト: notator/MNXtoSVG
        private bool IsNoteOffMsg(MidiMsg msg)
        {
            int statusHighNibbble = msg.Status & 0xF0;

            if (statusHighNibbble == M.CMD_NOTE_OFF_0x80 || (statusHighNibbble == M.CMD_NOTE_ON_0x90 && msg.Data2 == 0))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: CarryMsgs.cs プロジェクト: notator/MNXtoSVG
 /// <summary>
 /// Checks that all messages are noteOffs and have the same channel.
 /// </summary>
 public void Add(MidiMsg msg)
 {
     CheckMsg(msg);
     _msgs.Add(msg);
 }
コード例 #4
0
ファイル: BasicMidiChordDef.cs プロジェクト: notator/MNXtoSVG
        /// <summary>
        /// Writes a single moment element which may contain
        /// NoteOffs, bank, patch, pitchWheelDeviation, NoteOns.
        /// Moritz never writes SysEx messages.
        /// </summary>
        public void WriteSVG(XmlWriter w, int channel, CarryMsgs carryMsgs)
        {
            w.WriteStartElement("moment");
            w.WriteAttributeString("msDuration", MsDuration.ToString());

            if (carryMsgs.Count > 0)
            {
                carryMsgs.WriteSVG(w);
                carryMsgs.Clear();
            }

            if (carryMsgs.IsStartOfSwitches)
            {
                BankIndex                   = GetValue(BankIndex, 0);
                PatchIndex                  = GetValue(PatchIndex, 0);
                PitchWheelDeviation         = GetValue(PitchWheelDeviation, 2);
                carryMsgs.IsStartOfSwitches = false;
            }

            if ((BankIndex != null && BankIndex != carryMsgs.BankState) ||
                (PatchIndex != null && PatchIndex != carryMsgs.PatchState) ||
                (PitchWheelDeviation != null && PitchWheelDeviation != carryMsgs.PitchWheelDeviationState))
            {
                w.WriteStartElement("switches");
                if (BankIndex != null && BankIndex != carryMsgs.BankState)
                {
                    MidiMsg msg = new MidiMsg(M.CMD_CONTROL_CHANGE_0xB0 + channel, M.CTL_BANK_CHANGE_0, BankIndex);
                    msg.WriteSVG(w);
                    carryMsgs.BankState = (byte)BankIndex;
                }
                if (PatchIndex != null && PatchIndex != carryMsgs.PatchState)
                {
                    MidiMsg msg = new MidiMsg(M.CMD_PATCH_CHANGE_0xC0 + channel, (int)PatchIndex, null);
                    msg.WriteSVG(w);
                    carryMsgs.PatchState = (byte)PatchIndex;
                }
                if (PitchWheelDeviation != null && PitchWheelDeviation != carryMsgs.PitchWheelDeviationState)
                {
                    MidiMsg msg1 = new MidiMsg(M.CMD_CONTROL_CHANGE_0xB0 + channel, M.CTL_REGISTEREDPARAMETER_COARSE_101, M.SELECT_PITCHBEND_RANGE_0);
                    msg1.WriteSVG(w);
                    MidiMsg msg2 = new MidiMsg(M.CMD_CONTROL_CHANGE_0xB0 + channel, M.CTL_DATAENTRY_COARSE_6, PitchWheelDeviation);
                    msg2.WriteSVG(w);
                    carryMsgs.PitchWheelDeviationState = (byte)PitchWheelDeviation;
                }
                w.WriteEndElement(); // switches
            }

            if (Pitches != null)
            {
                M.Assert(Velocities != null && Pitches.Count == Velocities.Count);
                w.WriteStartElement("noteOns");
                int status = M.CMD_NOTE_ON_0x90 + channel; // NoteOn
                for (int i = 0; i < Pitches.Count; ++i)
                {
                    MidiMsg msg = new MidiMsg(status, Pitches[i], Velocities[i]);
                    msg.WriteSVG(w);
                }
                w.WriteEndElement(); // end of noteOns

                if (HasChordOff)
                {
                    status = M.CMD_NOTE_OFF_0x80 + channel;
                    int data2 = M.DEFAULT_NOTEOFF_VELOCITY_64;
                    foreach (byte pitch in Pitches)
                    {
                        carryMsgs.Add(new MidiMsg(status, pitch, data2));
                    }
                }
            }

            w.WriteEndElement(); // end of moment
        }