-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrl.cpp
124 lines (106 loc) · 2.83 KB
/
ctrl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* @file ctrl.cpp
* @brief Brief description of file.
*
*/
#include <sstream>
#include <iostream>
#include "ctrl.h"
#include "diamond.h"
#include "midi.h"
#include "save.h"
using namespace std;
unordered_map<string,Ctrl *> Ctrl::map;
Ctrl *Ctrl::createOrFind(string name,bool nocreate){
Ctrl *v;
unordered_map<string,Ctrl *>::iterator res;
res = map.find(name);
if(res==map.end()){
if(nocreate)
return NULL;
v = new Ctrl(name);
map.emplace(name,v);
} else {
v = res->second;
}
return v;
}
Ctrl::~Ctrl() {
if(source)source->remove(this);
map.erase(nameString);
delete ring;
}
vector<Ctrl *> Ctrl::getList(){
vector<Ctrl *> lst;
unordered_map<string,Ctrl *>::iterator it;
for(it=map.begin();it!=map.end();it++){
lst.push_back(it->second);
}
std::sort(lst.begin(),lst.end(),[](Ctrl *i,Ctrl *j)->bool{
return i->nameString.compare(j->nameString)<0;});
return lst;
}
void Ctrl::checkAllCtrlsForSource(){
unordered_map<string,Ctrl *>::iterator it;
for(it=map.begin();it!=map.end();it++){
Ctrl *c = it->second;
if(c->source == NULL){
string s = ("ctrl '"+it->first+ "' has no source defined");
cout << s << endl;
}
/*
vector<Value *>::iterator iv;
for(iv=c->values.begin();iv!=c->values.end();iv++){
Value *v = *iv;
if(v->db != c->db){
throw _("DB should match values and channels");
}
}
*/
}
}
void Ctrl::removeAllAssociations(Value *v){
unordered_map<string,Ctrl *>::iterator it;
for(it=map.begin();it!=map.end();it++){
Ctrl *c = it->second;
c->remval(v);
}
}
void Ctrl::pollAllCtrlRings(){
unordered_map<string,Ctrl *>::iterator it;
for(it=map.begin();it!=map.end();it++){
Ctrl *c = it->second;
c->pollRing();
}
}
Ctrl *Ctrl::setsource(CtrlSource *s,string spec){
sourceString = spec;
const char *err = s->add(spec,this);
if(err==NULL){
s->setrangedefault(this);
} else {
sourceString = "error";
// printf("Error : %s\n",err);
}
return this;
}
void Ctrl::save(ostream& out){
out << " " << nameString << ": " << source->getName() << " \"" << sourceString << "\"";
out << " in " << inmin << ":" << inmax;
}
void Ctrl::saveAll(ostream &out){
out << "ctrl {\n";
vector<string> strs;
unordered_map<string,Ctrl *>::iterator it;
for(it=map.begin();it!=map.end();it++){
stringstream ss;
Ctrl *c = it->second;
// only bother with ctrls we actually have sources for
if(c->source != NULL){
c->save(ss);
strs.push_back(ss.str());
}
}
out << intercalate(strs,",\n");
out << "\n}\n";
}