1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Rosegarden
5 A sequencer and musical notation editor.
6 Copyright 2000-2021 the Rosegarden development team.
7 See the AUTHORS file for more details.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "Track.h"
17
18 #include "Composition.h"
19 #include "StaffExportTypes.h" // StaffTypes and Brackets
20
21 #include <sstream> // std::stringstream
22
23
24 namespace Rosegarden
25 {
26
27
Track(TrackId id,InstrumentId instrument,int position,const std::string & label,bool muted)28 Track::Track(TrackId id,
29 InstrumentId instrument,
30 int position,
31 const std::string &label,
32 bool muted) :
33 m_id(id),
34 m_muted(muted),
35 m_archived(false),
36 m_solo(false),
37 m_label(label),
38 m_shortLabel(""),
39 m_position(position),
40 m_instrument(instrument),
41 m_owningComposition(nullptr),
42 m_input_device(Device::ALL_DEVICES),
43 m_input_channel(-1),
44 m_thruRouting(Auto),
45 m_armed(false),
46 m_clef(0),
47 m_transpose(0),
48 m_color(0),
49 m_highestPlayable(127),
50 m_lowestPlayable(0),
51 m_staffSize(StaffTypes::Normal),
52 m_staffBracket(Brackets::None)
53 {
54 }
55
setPresetLabel(const std::string & label)56 void Track::setPresetLabel(const std::string &label)
57 {
58 if (m_presetLabel == label) return;
59
60 m_presetLabel = label;
61
62 if (m_owningComposition)
63 m_owningComposition->notifyTrackChanged(this);
64 }
65
setInstrument(InstrumentId instrument)66 void Track::setInstrument(InstrumentId instrument)
67 {
68 if (m_instrument == instrument) return;
69
70 m_instrument = instrument;
71
72 if (m_owningComposition)
73 m_owningComposition->notifyTrackChanged(this);
74 }
75
setMidiInputDevice(DeviceId id)76 void Track::setMidiInputDevice(DeviceId id)
77 {
78 if (m_input_device == id) return;
79
80 m_input_device = id;
81
82 if (m_owningComposition)
83 m_owningComposition->notifyTrackChanged(this);
84 }
85
setMidiInputChannel(char ic)86 void Track::setMidiInputChannel(char ic)
87 {
88 if (m_input_channel == ic) return;
89
90 m_input_channel = ic;
91
92 if (m_owningComposition)
93 m_owningComposition->notifyTrackChanged(this);
94 }
95
setThruRouting(ThruRouting thruRouting)96 void Track::setThruRouting(ThruRouting thruRouting)
97 {
98 // No change, bail.
99 if (m_thruRouting == thruRouting)
100 return;
101
102 m_thruRouting = thruRouting;
103
104 if (m_owningComposition)
105 m_owningComposition->notifyTrackChanged(this);
106 }
107
108
109 // Our virtual method for exporting Xml.
110 //
111 //
toXmlString() const112 std::string Track::toXmlString() const
113 {
114
115 std::stringstream track;
116
117 track << "<track id=\"" << m_id;
118 track << "\" label=\"" << encode(m_label);
119 track << "\" shortLabel=\"" << encode(m_shortLabel);
120 track << "\" position=\"" << m_position << "\"";
121
122 track << " muted=\"" << (m_muted ? "true" : "false") << "\"";
123
124 track << " archived=\"" << (m_archived ? "true" : "false") <<"\"";
125
126 track << " solo=\"" << (m_solo ? "true" : "false") << "\"";
127
128 track << " instrument=\"" << m_instrument << "\"";
129
130 track << " defaultLabel=\"" << m_presetLabel << "\"";
131 track << " defaultClef=\"" << m_clef << "\"";
132 track << " defaultTranspose=\"" << m_transpose << "\"";
133 track << " defaultColour=\"" << m_color << "\"";
134 track << " defaultHighestPlayable=\"" << m_highestPlayable << "\"";
135 track << " defaultLowestPlayable=\"" << m_lowestPlayable << "\"";
136
137 track << " staffSize=\"" << m_staffSize << "\"";
138 track << " staffBracket=\"" << m_staffBracket << "\"";
139
140 track << " inputDevice=\"" << m_input_device << "\"";
141 track << " inputChannel=\"" << static_cast<int>(m_input_channel) << "\"";
142 track << " thruRouting=\"" << static_cast<int>(m_thruRouting) << "\"";
143
144 track << "/>";
145
146 return track.str();
147
148 }
149
150
151 }
152