Esempio n. 1
0
        public void WriteSVG(SvgWriter w, int channel, int msDuration, CarryMsgs carryMsgs)
        {
            if (carryMsgs.IsStartOfEnvs)
            {
                PanMsbs             = GetDefault(PanMsbs, 64);
                ModulationWheelMsbs = GetDefault(ModulationWheelMsbs, 0);
                ExpressionMsbs      = GetDefault(ExpressionMsbs, 127);
                PitchWheelMsbs      = GetDefault(PitchWheelMsbs, 64);

                carryMsgs.IsStartOfEnvs = false;
            }

            if (DoWriteControl(PanMsbs, carryMsgs.PanState) ||
                DoWriteControl(ModulationWheelMsbs, carryMsgs.ModWheelState) ||
                DoWriteControl(ExpressionMsbs, carryMsgs.ExpressionState) ||
                DoWriteControl(PitchWheelMsbs, carryMsgs.PitchWheelState))
            {
                w.WriteStartElement("envs"); // envelopes

                if (DoWriteControl(PanMsbs, carryMsgs.PanState))
                {
                    carryMsgs.PanState = WriteCCEnv(w, channel, M.CTL_PAN_10, PanMsbs, msDuration);
                }

                if (DoWriteControl(ModulationWheelMsbs, carryMsgs.ModWheelState))
                {
                    carryMsgs.ModWheelState = WriteCCEnv(w, channel, M.CTL_MODWHEEL_1, ModulationWheelMsbs, msDuration);
                }

                if (DoWriteControl(ExpressionMsbs, carryMsgs.ExpressionState))
                {
                    carryMsgs.ExpressionState = WriteCCEnv(w, channel, M.CTL_EXPRESSION_11, ExpressionMsbs, msDuration);
                }

                if (DoWriteControl(PitchWheelMsbs, carryMsgs.PitchWheelState))
                {
                    string statusString = null;
                    w.WriteStartElement("env"); // envelope

                    statusString = $"0x{(M.CMD_PITCH_WHEEL_0xE0 + channel).ToString("X")}";
                    w.WriteAttributeString("s", statusString);

                    carryMsgs.PitchWheelState = WriteD1AndD2VTs(w, PitchWheelMsbs, PitchWheelMsbs, msDuration);

                    w.WriteEndElement(); // end env
                }

                w.WriteEndElement(); // end envs
            }
        }
Esempio n. 2
0
        public void WriteSVG(SvgWriter w, int channel, CarryMsgs carryMsgs)
        {
            w.WriteStartElement("score", "midi", null);

            w.WriteStartElement("moments");
            w.WriteStartElement("moment");
            w.WriteAttributeString("msDuration", _msDuration.ToString());

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

            w.WriteEndElement(); // moment
            w.WriteEndElement(); // moments

            // Moritz never writes an envs element here, but other applications might.

            w.WriteEndElement(); // score:midi
        }
Esempio n. 3
0
        /// <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
        }