-
Notifications
You must be signed in to change notification settings - Fork 0
/
maTrigList.cpp
300 lines (238 loc) · 6.83 KB
/
maTrigList.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
//
// MultiArp - Another step in the Great Midi Adventure!
// Copyright (C) 2017, 2018 Barry Neilsen
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//////////////////////////////////////////////////////////////////////////////
#include "maTrigList.h"
#include "maUtility.h"
using namespace std;
TrigList::TrigList()
{
//ctor
m_Help = "S-L/R: add trig stage, C-L/R: copy trig stage, S-Del: delete ";
}
TrigList::~TrigList()
{
//dtor
}
void TrigList::SetStatus()
{
int pos = 0;
// char buff[50];
m_FieldPositions.clear();
m_Highlights.clear();
m_Status = "[Trig List] ";
// for ( int i = 0; i < m_TrigItems.size(); i++ )
for ( auto it = m_TrigItems.begin(); it < m_TrigItems.end(); it++ )
{
if ( it > m_TrigItems.begin() )
m_Status += ' ';
pos = m_Status.size();
// m_Status += m_TrigItems.at(i).MenuString();
m_Status += it->MenuString();
m_FieldPositions.emplace_back(pos, static_cast<int>(m_Status.size() - pos));
}
if ( !m_FieldPositions.empty() )
m_Highlights.push_back(m_FieldPositions.at(m_PosEdit));
}
bool TrigList::HandleKey(key_type_t k)
{
switch ( k )
{
case enter:
if ( !m_TrigItems.empty() )
{
TrigListItem & n = m_TrigItems.at(m_PosEdit);
n.SetItemID(m_PosEdit + 1);
n.SetFocus();
n.SetStatus();
n.SetReturnFocus(this);
}
break;
case back_space:
case escape:
ReturnFocus();
break;
case left:
if ( m_PosEdit > 0 )
m_PosEdit -= 1;
break;
case right:
if ( m_PosEdit < m_TrigItems.size() - 1 )
m_PosEdit += 1;
break;
case ctrl_left:
if ( !m_TrigItems.empty() )
{
m_TrigItems.insert(m_TrigItems.begin() + m_PosEdit, m_TrigItems.at(m_PosEdit));
}
break;
case ctrl_right:
if ( !m_TrigItems.empty() )
{
m_TrigItems.insert(m_TrigItems.begin() + m_PosEdit + 1, m_TrigItems.at(m_PosEdit));
m_PosEdit += 1;
}
break;
case shift_left:
if ( m_TrigItems.empty() )
{
m_TrigItems.emplace_back();
m_PosEdit = 0;
}
else
m_TrigItems.insert(m_TrigItems.begin() + m_PosEdit, *(new TrigListItem()));
break;
case shift_delete:
if ( !m_TrigItems.empty() )
{
m_TrigItems.erase(m_TrigItems.begin() + m_PosEdit);
if ( m_PosEdit == m_TrigItems.size() )
m_PosEdit -= 1;
}
break;
case shift_right:
if ( m_TrigItems.empty() )
{
m_TrigItems.emplace_back();
m_PosEdit = 0;
}
else
{
m_TrigItems.insert(m_TrigItems.begin() + m_PosEdit + 1, *(new TrigListItem()));
m_PosEdit += 1;
}
break;
default:
return false;
}
m_FirstField = m_PosEdit == 0;
SetStatus();
return true;
}
string TrigList::ToString(const char * prefix)
{
string result;
if ( prefix != NULL )
{
result += prefix;
result += ' ';
}
result += "Trigs ";
for (auto it = m_TrigItems.begin(); it != m_TrigItems.end(); )
{
result += " \\\n ";
result += it->ToString();
if ( ++it < m_TrigItems.end() )
result += ", ";
}
return result;
}
void TrigList::FromString(string s)
{
// if ( s.find("Trigs") == string::npos )
// throw string("TrigList::FromString() - Not a valid trig list.");
vector<string> tokens = split(s.c_str(), ',');
if ( tokens.size() == 0 )
return;
m_TrigItems.clear();
for ( auto it = tokens.begin(); it != tokens.end(); it++ )
{
m_TrigItems.emplace_back();
m_TrigItems.back().FromString(*it);
}
}
void TrigList::AddArpeggio(vector<string>::iterator token, vector<string>::iterator finish)
{
// vector<string> tokens = split(s.c_str(), ' ');
// TODO: Currently just a aplaceholder to set up some test data.
// if ( m_TrigItems.empty() )
return;
m_TrigItems.front().Repeater().AddArpStage(2, 16);
// m_TrigItems.front().Repeater().AddArpStage(1, 2);
// m_TrigItems.front().Repeater().AddArpStage(-2, 4);
}
void TrigList::FromSimpleString(vector<string>::iterator token, vector<string>::iterator finish)
{
// vector<string> tokens = split(s.c_str(), ' ');
// if ( tokens.size() <= 1 )
// throw string("TrigList::FromSimpleString() - Nothing found.");
m_TrigItems.clear();
for ( ; token != finish; token++ )
{
m_TrigItems.emplace_back();
m_TrigItems.back().FromSimpleString(*token);
}
}
string TrigList::ToStringForDisplay()
{
string result;
char buff[50];
for ( unsigned i = 0; i < m_TrigItems.size(); i++ )
{
// if ( i > 0 )
// result += ' ';
if ( i == m_Pos )
{
sprintf(buff, "%3lu| ", m_Pos + 1);
result += buff;
}
result += m_TrigItems.at(i).MenuString(9);
}
return result;
}
string TrigList::ToStringForDisplay2(int & offset, int & length, unsigned displayWidth)
{
string result;
unsigned itemWidth = 9;
unsigned itemsPerRow = displayWidth/itemWidth;
// char buff[50];
offset = 0;
length = 0;
for ( unsigned i = 0; i < m_TrigItems.size(); i++ )
{
if ( i == m_Pos )
offset = result.size();
result += m_TrigItems.at(i).MenuString(9);
if ( i == m_Pos )
length = result.size() - offset;
}
// Scroll left if highlight is beyond displayWidth.
while ( static_cast<unsigned>(offset + length) > displayWidth )
{
int scroll = itemsPerRow * itemWidth;
result.erase(0, scroll);
offset -= scroll;
}
// Truncate if line itself goes beyond width.
if ( result.size() > displayWidth )
{
result = result.substr(0, displayWidth);
}
return result;
}
TrigListItem * TrigList::Step()
{
if ( ! m_TrigItems.empty() )
{
m_Pos += 1;
if ( m_Pos >= m_TrigItems.size() )
m_Pos = 0;
return & m_TrigItems.at(m_Pos);
}
else
return NULL;
}