Skip to content

Commit 4b50082

Browse files
committed
Added sample reveal on stop event
1 parent 5afebf6 commit 4b50082

4 files changed

Lines changed: 58 additions & 9 deletions

File tree

include/private/ui/trigger.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ namespace lsp
3434
protected:
3535
ui::IPort *pCurrentSample; // Current sample
3636
ui::IPort *pRevealSampleOnListen; // Reveal sample on listen option
37-
tk::Button *wSampleListen[meta::trigger_metadata::SAMPLE_FILES]; // Listen buttons for files
37+
tk::Button *wSampleListen[meta::trigger_metadata::SAMPLE_FILES]; // Listen buttons for files
38+
tk::Button *wSampleStop[meta::trigger_metadata::SAMPLE_FILES]; // Stop buttons for files
3839

3940
protected:
4041
static status_t slot_submit_listen_sample(tk::Widget *sender, void *ptr, void *data);
42+
static status_t slot_submit_stop_sample(tk::Widget *sender, void *ptr, void *data);
43+
44+
protected:
45+
status_t show_sample(size_t index);
4146

4247
public:
4348
explicit trigger(const meta::plugin_t *meta);

res/main/ui/plugins/trigger/single/mono.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
text="icons.playback_big.play"
303303
size="32" ui:inject="Button_cyan" toggle="false" pad.b="6"/>
304304
<button id="lc_${i}"
305+
ui:id="trg_stop_sample_${i}"
305306
font.name="lsp-icons" font.size="10"
306307
text="icons.playback_big.stop"
307308
size="32" ui:inject="Button_cyan" toggle="false" pad.b="6" />

res/main/ui/plugins/trigger/single/stereo.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@
313313
font.name="lsp-icons" font.size="10"
314314
text="icons.playback_big.play"
315315
size="32" ui:inject="Button_cyan" toggle="false" pad.b="6"/>
316-
<button id="lc_${i}" font.name="lsp-icons" font.size="10" text="icons.playback_big.stop" size="32" ui:inject="Button_cyan" toggle="false" pad.b="6"/>
316+
<button
317+
ui:id="trg_stop_sample_${i}"
318+
id="lc_${i}"
319+
font.name="lsp-icons" font.size="10"
320+
text="icons.playback_big.stop" size="32"
321+
ui:inject="Button_cyan" toggle="false" pad.b="6"/>
317322
<led id="no_${i}" pad.b="6" width="32" height="6"/>
318323
</ui:with>
319324
<cell rows="11">

src/main/ui/trigger.cpp

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ namespace lsp
5454

5555
for (size_t i=0; i<meta::trigger_metadata::SAMPLE_FILES; ++i)
5656
wSampleListen[i] = NULL;
57+
for (size_t i=0; i<meta::trigger_metadata::SAMPLE_FILES; ++i)
58+
wSampleStop[i] = NULL;
5759
}
5860

5961
trigger::~trigger()
@@ -110,12 +112,29 @@ namespace lsp
110112
if (listen != NULL)
111113
listen->slots()->bind(tk::SLOT_CHANGE, slot_submit_listen_sample, this);
112114

115+
tk::Button * const stop = w->get_widgetf<tk::Button>("trg_stop_sample_%d", int(i));
116+
if (stop != NULL)
117+
stop->slots()->bind(tk::SLOT_CHANGE, slot_submit_stop_sample, this);
118+
113119
wSampleListen[i] = listen;
120+
wSampleStop[i] = stop;
114121
}
115122

116123
return STATUS_OK;
117124
}
118125

126+
status_t trigger::show_sample(size_t index)
127+
{
128+
if (pCurrentSample == NULL)
129+
return STATUS_OK;
130+
131+
pCurrentSample->begin_edit();
132+
pCurrentSample->set_value(index);
133+
pCurrentSample->notify_all(ui::PORT_USER_EDIT);
134+
pCurrentSample->end_edit();
135+
return STATUS_OK;
136+
}
137+
119138
status_t trigger::slot_submit_listen_sample(tk::Widget *sender, void *ptr, void *data)
120139
{
121140
trigger * const self = static_cast<trigger *>(ptr);
@@ -135,13 +154,32 @@ namespace lsp
135154
for (size_t i=0; i<meta::trigger_metadata::SAMPLE_FILES; ++i)
136155
{
137156
if (sender == self->wSampleListen[i])
138-
{
139-
self->pCurrentSample->begin_edit();
140-
self->pCurrentSample->set_value(i);
141-
self->pCurrentSample->notify_all(ui::PORT_USER_EDIT);
142-
self->pCurrentSample->end_edit();
143-
return STATUS_OK;
144-
}
157+
return self->show_sample(i);
158+
}
159+
160+
return STATUS_OK;
161+
}
162+
163+
status_t trigger::slot_submit_stop_sample(tk::Widget *sender, void *ptr, void *data)
164+
{
165+
trigger * const self = static_cast<trigger *>(ptr);
166+
if (self == NULL)
167+
return STATUS_OK;
168+
if (self->pCurrentSample == NULL)
169+
return STATUS_OK;
170+
if ((self->pRevealSampleOnListen == NULL) || (self->pRevealSampleOnListen->value() < 0.5f))
171+
return STATUS_OK;
172+
173+
// Ensure that button has been pushed down
174+
tk::Button * const btn = tk::widget_cast<tk::Button>(sender);
175+
if ((btn == NULL) || (!btn->down()->get()))
176+
return STATUS_OK;
177+
178+
// Find the related sample and activate it
179+
for (size_t i=0; i<meta::trigger_metadata::SAMPLE_FILES; ++i)
180+
{
181+
if (sender == self->wSampleStop[i])
182+
return self->show_sample(i);
145183
}
146184

147185
return STATUS_OK;

0 commit comments

Comments
 (0)