3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/strings/formatter.h>
19 Zone::Zone(Layout &l):
23 layout.add_zone(*this);
28 layout.remove_zone(*this);
31 void Zone::set_name(const string &g, const string &q, unsigned n)
37 signal_name_changed.emit(group, qualifier, number);
40 string Zone::get_name() const
42 string result = group;
43 if(!qualifier.empty())
49 result += format(" %d", number);
53 void Zone::add_track(Track &track)
56 throw InvalidParameterValue("Can't add track to zone");
58 tracks.insert(&track);
61 bool Zone::add_tracks(const TrackSet &trks)
63 TrackSet pending = trks;
68 for(TrackSet::const_iterator i=pending.begin(); i!=pending.end(); ++i)
80 throw InvalidParameterValue("Cound not add any tracks to zone");
81 return pending.empty();
88 void Zone::save(list<DataFile::Statement> &st) const
90 st.push_back((DataFile::Statement("group"), group));
91 if(!qualifier.empty())
92 st.push_back((DataFile::Statement("qualifier"), qualifier));
94 st.push_back((DataFile::Statement("number"), number));
96 set<unsigned> block_ids;
97 for(TrackSet::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
98 block_ids.insert((*i)->get_block().get_id());
100 for(set<unsigned>::const_iterator i=block_ids.begin(); i!=block_ids.end(); ++i)
101 st.push_back((DataFile::Statement("block"), *i));
104 bool Zone::is_valid(Track &t) const
109 const vector<Track *> &links = t.get_links();
110 for(vector<Track *>::const_iterator i=links.begin(); i!=links.end(); ++i)
111 if(*i && tracks.count(*i))
118 Zone::Loader::Loader(Zone &z):
119 DataFile::ObjectLoader<Zone>(z)
121 add("block", &Loader::block);
122 add("group", &Zone::group);
123 add("number", &Zone::number);
124 add("qualifier", &Zone::qualifier);
127 void Zone::Loader::block(unsigned b)
129 Block &blk = obj.layout.get_block(b);
130 const set<Track *> &btracks = blk.get_tracks();
131 obj.tracks.insert(btracks.begin(), btracks.end());