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 }
/// <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 }