@@ -95,14 +95,15 @@ RangeEditor::~RangeEditor() {}
9595 * RECORD CHANNEL SELECTOR
9696***************************/
9797
98- RecordChannelSelector::RecordChannelSelector (std::vector<bool > channelStates)
98+ RecordChannelSelector::RecordChannelSelector (std::vector<bool > channelStates, bool editable )
9999 : Component(),
100100 nChannels(channelStates.size()),
101101 mouseDragged(false ),
102102 startDragCoords(0 ,0 ),
103103 shiftKeyDown(false ),
104104 firstButtonSelectedState(false ),
105- isDragging(false )
105+ isDragging(false ),
106+ editable(editable)
106107{
107108
108109 int width = 368 ; // can use any multiples of 16 here for dynamic resizing
@@ -128,40 +129,48 @@ RecordChannelSelector::RecordChannelSelector(std::vector<bool> channelStates)
128129 }
129130 }
130131
131- // Add "SELECT ALL" button
132- selectButtons.add (new SelectButton (" ALL" ));
133- selectButtons.getLast ()->setBounds (0 , height, 0.25 *width, width / nColumns);
134- selectButtons.getLast ()->addListener (this );
135- addChildAndSetID (selectButtons.getLast ()," ALL" );
136-
137- // Add "SELECT NONE" button
138- selectButtons.add (new SelectButton (" NONE" ));
139- selectButtons.getLast ()->setBounds (0.25 *width, height, 0.25 *width, width / nColumns);
140- selectButtons.getLast ()->addListener (this );
141- addChildAndSetID (selectButtons.getLast ()," ALL" );
142-
143- if (nChannels > 8 )
132+ if (editable)
144133 {
145134
146- // Add "SELECT RANGE " button
147- selectButtons.add (new SelectButton (" RANGE " ));
148- selectButtons.getLast ()->setBounds (0.5 *width , height, 0.25 *width, width / nColumns);
135+ // Add "SELECT ALL " button
136+ selectButtons.add (new SelectButton (" ALL " ));
137+ selectButtons.getLast ()->setBounds (0 , height, 0.25 *width, width / nColumns);
149138 selectButtons.getLast ()->addListener (this );
150139 addChildAndSetID (selectButtons.getLast ()," ALL" );
151140
152- // Add Range Editor
153-
154- rangeEditor = new RangeEditor (" Range" , Font (" Small Text" , 12 , Font::plain));
155- rangeEditor->setBounds (0.75 *width, height, 0.25 *width, width / nColumns);
156- rangeEditor->addListener (this );
157- addChildAndSetID (rangeEditor," RANGE_EDITOR" );
141+ // Add "SELECT NONE" button
142+ selectButtons.add (new SelectButton (" NONE" ));
143+ selectButtons.getLast ()->setBounds (0.25 *width, height, 0.25 *width, width / nColumns);
144+ selectButtons.getLast ()->addListener (this );
145+ addChildAndSetID (selectButtons.getLast ()," ALL" );
158146
147+ if (nChannels > 8 )
148+ {
149+
150+ // Add "SELECT RANGE" button
151+ selectButtons.add (new SelectButton (" RANGE" ));
152+ selectButtons.getLast ()->setBounds (0.5 *width, height, 0.25 *width, width / nColumns);
153+ selectButtons.getLast ()->addListener (this );
154+ addChildAndSetID (selectButtons.getLast ()," ALL" );
155+
156+ // Add Range Editor
157+ rangeEditor = new RangeEditor (" Range" , Font (" Small Text" , 12 , Font::plain));
158+ rangeEditor->setBounds (0.75 *width, height, 0.25 *width, width / nColumns);
159+ rangeEditor->addListener (this );
160+ addChildAndSetID (rangeEditor," RANGE_EDITOR" );
161+
162+ }
163+
159164 }
160165
161166 if (nChannels <= 8 )
162167 width /= 2 ;
163168
164- setSize (width, height + buttonSize);
169+ if (editable)
170+ setSize (width, height + buttonSize);
171+ else
172+ setSize (width, height);
173+
165174 setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
166175
167176}
@@ -174,49 +183,55 @@ void RecordChannelSelector::mouseMove(const MouseEvent &event)
174183};
175184void RecordChannelSelector::mouseDown (const MouseEvent &event)
176185{
177- selectedButtons.clear ();
186+ if (editable)
187+ selectedButtons.clear ();
178188};
179189
180190void RecordChannelSelector::mouseDrag (const MouseEvent &event)
181191{
182192
183- mouseDragged = true ;
184-
185- int w = event.getDistanceFromDragStartX ();
186- int h = event.getDistanceFromDragStartY ();
187- int x = startDragCoords.getX ();
188- int y = startDragCoords.getY ();
189-
190- if (w < 0 )
193+ if (editable)
191194 {
192- x = x + w;
193- w = -w;
194- }
195195
196- if (h < 0 )
197- {
198- y = y + h;
199- h = -h;
200- }
196+ mouseDragged = true ;
201197
202- dragBox.setBounds (x, y, w > 0 ? w : 1 , h > 0 ? h : 1 );
198+ int w = event.getDistanceFromDragStartX ();
199+ int h = event.getDistanceFromDragStartY ();
200+ int x = startDragCoords.getX ();
201+ int y = startDragCoords.getY ();
203202
204- for (auto button : channelButtons)
205- {
206- if (button->getBounds ().intersects (dragBox) && !selectedButtons.contains (button->getId ()))
203+ if (w < 0 )
207204 {
208- selectedButtons.add (button->getId ());
205+ x = x + w;
206+ w = -w;
207+ }
209208
210- if (shiftKeyDown) // toggle
211- button->triggerClick ();
212- else // Use state of the first selected button
209+ if (h < 0 )
210+ {
211+ y = y + h;
212+ h = -h;
213+ }
214+
215+ dragBox.setBounds (x, y, w > 0 ? w : 1 , h > 0 ? h : 1 );
216+
217+ for (auto button : channelButtons)
218+ {
219+ if (button->getBounds ().intersects (dragBox) && !selectedButtons.contains (button->getId ()))
213220 {
214- button->setToggleState (firstButtonSelectedState, NotificationType::dontSendNotification);
221+ selectedButtons.add (button->getId ());
222+
223+ if (shiftKeyDown) // toggle
224+ button->triggerClick ();
225+ else // Use state of the first selected button
226+ {
227+ button->setToggleState (firstButtonSelectedState, NotificationType::dontSendNotification);
228+ }
229+
215230 }
216-
217231 }
232+
218233 }
219-
234+
220235};
221236
222237void RecordChannelSelector::modifierKeysChanged (const ModifierKeys &modifiers)
@@ -227,7 +242,7 @@ void RecordChannelSelector::modifierKeysChanged(const ModifierKeys &modifiers)
227242void RecordChannelSelector::mouseUp (const MouseEvent &event)
228243{
229244
230- if (!mouseDragged)
245+ if (!mouseDragged && editable )
231246 {
232247 for (auto button : channelButtons)
233248 {
@@ -243,81 +258,91 @@ void RecordChannelSelector::mouseUp(const MouseEvent &event)
243258
244259void RecordChannelSelector::textEditorReturnKeyPressed (TextEditor& editor)
245260{
246- channelStates = parseStringIntoRange (384 );
247261
248- if (channelStates.size () < 3 )
249- return ;
262+ if (editable)
263+ {
264+ channelStates = parseStringIntoRange (384 );
250265
251- for ( auto * btn : channelButtons )
252- btn-> setToggleState ( false , NotificationType::dontSendNotification) ;
266+ if (channelStates. size () < 3 )
267+ return ;
253268
254- int i = 0 ;
255- while (i <= channelStates.size () - 3 )
256- {
257- const int lim = channelStates[i+1 ];
258- const int comd = channelStates[i+2 ];
259- for (int fa = channelStates[i]; fa < lim; fa += comd)
269+ for (auto * btn : channelButtons)
270+ btn->setToggleState (false , NotificationType::dontSendNotification);
271+
272+ int i = 0 ;
273+ while (i <= channelStates.size () - 3 )
260274 {
261- channelButtons[i++]->setToggleState (true , NotificationType::dontSendNotification);
275+ const int lim = channelStates[i+1 ];
276+ const int comd = channelStates[i+2 ];
277+ for (int fa = channelStates[i]; fa < lim; fa += comd)
278+ {
279+ channelButtons[i++]->setToggleState (true , NotificationType::dontSendNotification);
280+ }
281+ i+=3 ;
262282 }
263- i+=3 ;
264- }
265283
266- for (auto val : channelStates)
267- {
268- std::cout << val << " ," ;
269- }
270- std::cout << std::endl;
284+ for (auto val : channelStates)
285+ {
286+ std::cout << val << " ," ;
287+ }
288+ std::cout << std::endl;
271289
272- for (auto * btn : channelButtons)
273- btn->setToggleState (false , NotificationType::dontSendNotification);
290+ for (auto * btn : channelButtons)
291+ btn->setToggleState (false , NotificationType::dontSendNotification);
274292
275- for (i = 0 ; i < channelStates.size (); i += 3 )
276- {
277- int startIdx = channelStates[i];
278- int endIdx = channelStates[i+1 ];
279- int step = channelStates[i+2 ];
280-
281- int ch = startIdx;
282- while (ch < endIdx)
293+ for (i = 0 ; i < channelStates.size (); i += 3 )
283294 {
284- channelButtons[ch]->setToggleState (true , NotificationType::dontSendNotification);
285- ch+=step;
286- }
295+ int startIdx = channelStates[i];
296+ int endIdx = channelStates[i+1 ];
297+ int step = channelStates[i+2 ];
298+
299+ int ch = startIdx;
300+ while (ch < endIdx)
301+ {
302+ channelButtons[ch]->setToggleState (true , NotificationType::dontSendNotification);
303+ ch+=step;
304+ }
287305
306+ }
288307 }
308+
289309}
290310
291311void RecordChannelSelector::buttonClicked (Button* button)
292312{
293-
294- for (auto * btn : selectButtons)
295- btn->setToggleState (false , NotificationType::dontSendNotification);
296-
297- if (button->getButtonText () == String (" ALL" ))
298- {
299- for (auto * btn : channelButtons)
300- btn->setToggleState (true , NotificationType::dontSendNotification);
301- button->setToggleState (true , NotificationType::dontSendNotification);
302-
303- }
304- else if (button->getButtonText () == String (" NONE" ))
313+
314+ if (editable)
305315 {
306- for (auto * btn : channelButtons)
316+
317+ for (auto * btn : selectButtons)
307318 btn->setToggleState (false , NotificationType::dontSendNotification);
308- button->setToggleState (true , NotificationType::dontSendNotification);
309- }
310- else if (button->getButtonText () == String (" RANGE:" ))
311- {
312- button->setToggleState (true , NotificationType::dontSendNotification);
313- }
314- else // channel button was manually selected
315- {
316- // TODO: Update text box with range string
319+
320+ if (button->getButtonText () == String (" ALL" ))
321+ {
322+ for (auto * btn : channelButtons)
323+ btn->setToggleState (true , NotificationType::dontSendNotification);
324+ button->setToggleState (true , NotificationType::dontSendNotification);
325+
326+ }
327+ else if (button->getButtonText () == String (" NONE" ))
328+ {
329+ for (auto * btn : channelButtons)
330+ btn->setToggleState (false , NotificationType::dontSendNotification);
331+ button->setToggleState (true , NotificationType::dontSendNotification);
332+ }
333+ else if (button->getButtonText () == String (" RANGE:" ))
334+ {
335+ button->setToggleState (true , NotificationType::dontSendNotification);
336+ }
337+ else // channel button was manually selected
338+ {
339+ // TODO: Update text box with range string
340+ }
341+
342+ // rangeEditor->setText(rangeString);
343+
317344 }
318345
319- // rangeEditor->setText(rangeString);
320-
321346}
322347
323348void RecordChannelSelector::updateRangeString ()
0 commit comments