Skip to content

Commit d075fd7

Browse files
committed
Added reset envelope button
1 parent 879c038 commit d075fd7

8 files changed

Lines changed: 155 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*******************************************************************************
44

55
=== 1.0.31 ===
6-
6+
* Added reset envelope button.
77

88
=== 1.0.30 ===
99
* Updated build scripts and dependencies.

include/private/ui/sampler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ namespace lsp
133133
tk::MessageBox *wMessageBox;
134134
tk::Edit *wCurrentInstrument; // Name of the current instrument
135135
tk::ComboGroup *wInstrumentsGroup; // Instruments group
136+
tk::Button *wResetEnvelope; // Reset envelope
136137
DragInSink *pDragInSink; // Drag&drop sink
137138

138139
lltl::parray<tk::Widget> vHydrogenMenus;
@@ -161,6 +162,8 @@ namespace lsp
161162

162163
static status_t slot_drag_request(tk::Widget *sender, void *ptr, void *data);
163164

165+
static status_t slot_reset_envelope(tk::Widget *sender, void *ptr, void *data);
166+
164167
protected:
165168
static ssize_t cmp_drumkit_files(const h2drumkit_t *a, const h2drumkit_t *b);
166169
static ssize_t cmp_sfz_regions(const sfz_region_t *a, const sfz_region_t *b);
@@ -178,10 +181,15 @@ namespace lsp
178181
status_t import_sfz_file(const io::Path *base, const io::Path *path);
179182
status_t add_sample(const io::Path *base, int id, int jd, const hydrogen::layer_t *layer);
180183
status_t add_instrument(int id, const hydrogen::instrument_t *inst);
184+
void begin_edit(const char *fmt...);
185+
void end_edit(const char *fmt...);
186+
void notify_port(const char *fmt...);
187+
void set_default_value(const char *fmt...);
181188
void set_float_value(float value, const char *fmt...);
182189
void set_path_value(const char *path, const char *fmt...);
183190
void set_kvt_instrument_name(core::KVTStorage *kvt, int id, const char *name);
184191
void set_ui_instrument_name(inst_name_t *inst, const LSPString *name);
192+
void reset_current_envelope();
185193

186194
void sync_hydrogen_files();
187195
void lookup_hydrogen_files();

res/main/ui/sampling/multiple.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<hbox pad.h="6" fill="true" bg.color="bg_schema">
166166
<void hexpand="true"/>
167167
<button id="ee${idx}" text="labels.adsr.envelope" width.min="50" ui:inject="Button_envelope" toggle="false" pad.r="6"/>
168+
<button ui:id="trg_reset_envelope" text="actions.reset" width.min="50" ui:inject="Button_envelope" toggle="false" pad.r="6"/>
168169
<vsep bg.color="bg" pad.h="2" hreduce="true"/>
169170
<ui:with pad.v="4">
170171
<button id="ls${idx}" text="labels.sedit.listen" width.min="50" ui:inject="Button_cyan" toggle="false" pad.h="6"/>

res/main/ui/sampling/single/mono.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<hbox pad.h="6" fill="true" bg.color="bg_schema">
125125
<void hexpand="true"/>
126126
<button id="ee${idx}" text="labels.adsr.envelope" width.min="50" ui:inject="Button_envelope" toggle="false" pad.r="6"/>
127+
<button ui:id="trg_reset_envelope" text="actions.reset" width.min="50" ui:inject="Button_envelope" toggle="false" pad.r="6"/>
127128
<vsep bg.color="bg" pad.h="2" hreduce="true"/>
128129
<ui:with pad.v="4">
129130
<button id="ls${idx}" text="labels.sedit.listen" width.min="50" ui:inject="Button_cyan" toggle="false" pad.h="6"/>

res/main/ui/sampling/single/stereo.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
<hbox pad.h="6" fill="true" bg.color="bg_schema">
127127
<void hexpand="true"/>
128128
<button id="ee${idx}" text="labels.adsr.envelope" width.min="50" ui:inject="Button_envelope" toggle="false" pad.r="6"/>
129+
<button ui:id="trg_reset_envelope" text="actions.reset" width.min="50" ui:inject="Button_envelope" toggle="false" pad.r="6"/>
129130
<vsep bg.color="bg" pad.h="2" hreduce="true"/>
130131
<ui:with pad.v="4">
131132
<button id="ls${idx}" text="labels.sedit.listen" width.min="50" ui:inject="Button_cyan" toggle="false" pad.h="6"/>

src/doc/manuals/plugins/multisampler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<p><b>'Samples' section:</b></p>
136136
<ul>
137137
<li><b>Envelope</b> - the button that enables the additional AHDBSSR (Attack, Hold, Decay, Break, Slope, Sustain, Release) envelope control over the sample.</li>
138+
<li><b>Reset</b> - the button that resets all AHDBSSR envelope parameters to default values.</li>
138139
<li><b>Listen</b> - the button that plays the preview of the selected sample for the selected instrument.</li>
139140
<li><b>Stop</b> - the button that stops the preview of the selected sample for the selected instrument.</li>
140141
<li><b>Main tab</b> - the main control of the sample</li>

src/doc/manuals/plugins/sampler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<p><b>'Samples' section:</b></p>
3131
<ul>
3232
<li><b>Envelope</b> - the button that enables the additional AHDBSSR (Attack, Hold, Decay, Break, Slope, Sustain, Release) envelope control over the sample.</li>
33+
<li><b>Reset</b> - the button that resets all AHDBSSR envelope parameters to default values.</li>
3334
<li><b>Listen</b> - the button that plays the preview of the selected sample.</li>
3435
<li><b>Stop</b> - the button that stops the preview of the selected sample.</li>
3536
<li><b>Main tab</b> - the main control of the sample</li>

src/main/ui/sampler.cpp

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ namespace lsp
285285
wMessageBox = NULL;
286286
wCurrentInstrument = NULL;
287287
wInstrumentsGroup = NULL;
288+
wResetEnvelope = NULL;
288289
pDragInSink = NULL;
289290
}
290291

@@ -367,6 +368,13 @@ namespace lsp
367368
if (res != STATUS_OK)
368369
return res;
369370

371+
// Perform basic initializstion
372+
pCurrentSample = wrapper()->port("ssel");
373+
374+
wResetEnvelope = wrapper()->controller()->widgets()->get<tk::Button>("trg_reset_envelope");
375+
if (wResetEnvelope != NULL)
376+
wResetEnvelope->slots()->bind(tk::SLOT_SUBMIT, slot_reset_envelope, this);
377+
370378
// Do not perform other initialization since it is a very simple single-instrument sampler
371379
if (!bMultiple)
372380
return STATUS_OK;
@@ -388,7 +396,6 @@ namespace lsp
388396

389397
// Find widget and port associated with the current selected instrument
390398
pCurrentInstrument = wrapper()->port("inst");
391-
pCurrentSample = wrapper()->port("ssel");
392399
wCurrentInstrument = wrapper()->controller()->widgets()->get<tk::Edit>("iname");
393400
wInstrumentsGroup = wrapper()->controller()->widgets()->get<tk::ComboGroup>("inst_cgroup");
394401

@@ -696,6 +703,11 @@ namespace lsp
696703
if (dlg == NULL)
697704
return;
698705

706+
if (path != NULL)
707+
path->begin_edit();
708+
if (file_type != NULL)
709+
file_type->begin_edit();
710+
699711
if (path != NULL)
700712
{
701713
LSPString fpath;
@@ -712,6 +724,11 @@ namespace lsp
712724
file_type->set_value(dlg->selected_filter()->get());
713725
file_type->notify_all(ui::PORT_USER_EDIT);
714726
}
727+
728+
if (path != NULL)
729+
path->begin_edit();
730+
if (file_type != NULL)
731+
file_type->end_edit();
715732
}
716733

717734
void sampler_ui::kvt_changed(core::KVTStorage *kvt, const char *id, const core::kvt_param_t *value)
@@ -1006,6 +1023,34 @@ namespace lsp
10061023
return STATUS_OK;
10071024
}
10081025

1026+
void sampler_ui::begin_edit(const char *fmt...)
1027+
{
1028+
char port_id[32];
1029+
va_list v;
1030+
va_start(v, fmt);
1031+
1032+
::vsnprintf(port_id, sizeof(port_id)/sizeof(char), fmt, v);
1033+
ui::IPort *p = pWrapper->port(port_id);
1034+
if (p != NULL)
1035+
p->begin_edit();
1036+
1037+
va_end(v);
1038+
}
1039+
1040+
void sampler_ui::end_edit(const char *fmt...)
1041+
{
1042+
char port_id[32];
1043+
va_list v;
1044+
va_start(v, fmt);
1045+
1046+
::vsnprintf(port_id, sizeof(port_id)/sizeof(char), fmt, v);
1047+
ui::IPort *p = pWrapper->port(port_id);
1048+
if (p != NULL)
1049+
p->end_edit();
1050+
1051+
va_end(v);
1052+
}
1053+
10091054
void sampler_ui::set_float_value(float value, const char *fmt...)
10101055
{
10111056
char port_id[32];
@@ -1023,6 +1068,34 @@ namespace lsp
10231068
va_end(v);
10241069
}
10251070

1071+
void sampler_ui::set_default_value(const char *fmt...)
1072+
{
1073+
char port_id[32];
1074+
va_list v;
1075+
va_start(v, fmt);
1076+
1077+
::vsnprintf(port_id, sizeof(port_id)/sizeof(char), fmt, v);
1078+
ui::IPort *p = pWrapper->port(port_id);
1079+
if (p != NULL)
1080+
p->set_default();
1081+
1082+
va_end(v);
1083+
}
1084+
1085+
void sampler_ui::notify_port(const char *fmt...)
1086+
{
1087+
char port_id[32];
1088+
va_list v;
1089+
va_start(v, fmt);
1090+
1091+
::vsnprintf(port_id, sizeof(port_id)/sizeof(char), fmt, v);
1092+
ui::IPort *p = pWrapper->port(port_id);
1093+
if (p != NULL)
1094+
p->notify_all(ui::PORT_USER_EDIT);
1095+
1096+
va_end(v);
1097+
}
1098+
10261099
void sampler_ui::set_path_value(const char *path, const char *fmt...)
10271100
{
10281101
char port_id[32];
@@ -1239,6 +1312,18 @@ namespace lsp
12391312
io::Path path;
12401313
status_t res;
12411314

1315+
begin_edit("sf_%d_%d", id, jd);
1316+
begin_edit("mk_%d_%d", id, jd);
1317+
begin_edit("vl_%d_%d", id, jd);
1318+
begin_edit("pi_%d_%d", id, jd);
1319+
1320+
lsp_finally {
1321+
end_edit("sf_%d_%d", id, jd);
1322+
end_edit("mk_%d_%d", id, jd);
1323+
end_edit("vl_%d_%d", id, jd);
1324+
end_edit("pi_%d_%d", id, jd);
1325+
};
1326+
12421327
if (layer != NULL)
12431328
{
12441329
if ((res = path.set(base)) != STATUS_OK)
@@ -2010,6 +2095,61 @@ namespace lsp
20102095
set_path_value(path->get_utf8(), "sf_%d_%d", inst, sample); // sample file
20112096
}
20122097

2098+
void sampler_ui::reset_current_envelope()
2099+
{
2100+
const int sample = (pCurrentSample != NULL) ? pCurrentSample->value() : 0;
2101+
2102+
static const char *prefixes[] = {
2103+
"eh", "eb",
2104+
"ta", "th", "td", "ts", "tr",
2105+
"bl", "sl",
2106+
"ca", "cd", "cs", "cr",
2107+
"ea", "ed", "es", "er",
2108+
NULL
2109+
};
2110+
2111+
if (bMultiple)
2112+
{
2113+
const int inst = (pCurrentInstrument != NULL) ? pCurrentInstrument->value() : 0;
2114+
2115+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2116+
begin_edit("%s_%d_%d", *prefix, inst, sample);
2117+
2118+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2119+
set_default_value("%s_%d_%d", *prefix, inst, sample);
2120+
2121+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2122+
notify_port("%s_%d_%d", *prefix, inst, sample);
2123+
2124+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2125+
end_edit("%s_%d_%d", *prefix, inst, sample);
2126+
}
2127+
else
2128+
{
2129+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2130+
begin_edit("%s_%d", *prefix, sample);
2131+
2132+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2133+
set_default_value("%s_%d", *prefix, sample);
2134+
2135+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2136+
notify_port("%s_%d", *prefix, sample);
2137+
2138+
for (const char ** prefix = prefixes; *prefix != NULL; ++prefix)
2139+
end_edit("%s_%d", *prefix, sample);
2140+
}
2141+
}
2142+
2143+
status_t sampler_ui::slot_reset_envelope(tk::Widget *sender, void *ptr, void *data)
2144+
{
2145+
sampler_ui *self= static_cast<sampler_ui *>(ptr);
2146+
if (self == NULL)
2147+
return STATUS_BAD_STATE;
2148+
2149+
self->reset_current_envelope();
2150+
return STATUS_OK;
2151+
}
2152+
20132153
} /* namespace plugui */
20142154
} /* namespace lsp */
20152155

0 commit comments

Comments
 (0)