Skip to content

Commit

Permalink
Added Stop button for stopping audio file preview
Browse files Browse the repository at this point in the history
  • Loading branch information
sadko4u committed Dec 6, 2024
1 parent 8268fc4 commit d4b84b3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*******************************************************************************

=== 1.0.24 ===

* Added Stop button for stopping audio file preview.

=== 1.0.23 ===
* Updated build scripts and dependencies.
Expand Down
3 changes: 3 additions & 0 deletions include/private/plugins/impulse_reverb.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ namespace lsp
typedef struct af_descriptor_t
{
dspu::Toggle sListen; // Listen toggle
dspu::Toggle sStop; // Stop toggle
dspu::Sample *pOriginal; // Original audio file
dspu::Sample *pProcessed; // Processed audio file for sampler
float *vThumbs[meta::impulse_reverb_metadata::TRACKS_MAX]; // Thumbnails
Expand All @@ -120,6 +121,7 @@ namespace lsp
plug::IPort *pFadeIn;
plug::IPort *pFadeOut;
plug::IPort *pListen;
plug::IPort *pStop;
plug::IPort *pReverse; // Reverse
plug::IPort *pStatus; // Status of file loading
plug::IPort *pLength; // Length of file
Expand Down Expand Up @@ -155,6 +157,7 @@ namespace lsp
dspu::Bypass sBypass;
dspu::SamplePlayer sPlayer;
dspu::Equalizer sEqualizer; // Wet signal equalizer
dspu::Playback vPlaybacks[meta::impulse_reverb_metadata::FILES]; // Playbacks

float *vOut;
float *vBuffer; // Rendering buffer
Expand Down
9 changes: 8 additions & 1 deletion res/main/ui/convolution/impulse_reverb/mono.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@
<knob id="itc${i}" size="20"/>
<knob id="ifi${i}" size="20" scolor="fade_in"/>
<knob id="ifo${i}" size="20" scolor="fade_out"/>
<cell rows="2"><button id="ils${i}" size="32" toggle="false"/></cell>
<cell rows="2">
<hbox fill="false">
<ui:with font.name="lsp-icons" font.size="16" size="32" ui:inject="Button_cyan" toggle="false">
<button id="ils${i}" text="icons.playback.play" />
<button id="ilc${i}" text="icons.playback.stop" />
</ui:with>
</hbox>
</cell>
</ui:with>

<ui:with pad.h="6" pad.b="4" width.min="48" sline="true">
Expand Down
9 changes: 8 additions & 1 deletion res/main/ui/convolution/impulse_reverb/stereo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,14 @@
<knob id="itc${i}" size="20"/>
<knob id="ifi${i}" size="20" scolor="fade_in"/>
<knob id="ifo${i}" size="20" scolor="fade_out"/>
<cell rows="2"><button id="ils${i}" size="32" toggle="false"/></cell>
<cell rows="2">
<hbox fill="false">
<ui:with font.name="lsp-icons" font.size="16" size="32" ui:inject="Button_cyan" toggle="false">
<button id="ils${i}" text="icons.playback.play" />
<button id="ilc${i}" text="icons.playback.stop" />
</ui:with>
</hbox>
</cell>
</ui:with>

<ui:with pad.h="6" pad.b="4" width.min="48" sline="true">
Expand Down
3 changes: 2 additions & 1 deletion src/doc/manuals/plugins/impulse_reverb.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
<li><b>Tail cut</b> - cut amount of milliseconds from the end of the impulse files, can be used to remove large reverberation tail.</li>
<li><b>Fade in</b> - adds additional fading at the beginning of the impulse file.</li>
<li><b>Fade out</b> - adds additional fading at the end of the impulse file.</li>
<li><b>Listen</b> - this button allows to listen contents of the audio file.</li>
<li><b>Listen</b> - this button allows to listen preview of the audio file.</li>
<li><b>Stop</b> - this button allows to stop preview of the audio file.</li>
</ul>
<p><b>'Processors' section:</b></p>
<ul>
Expand Down
3 changes: 2 additions & 1 deletion src/main/meta/impulse_reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ namespace lsp
CONTROL("itc" id, "Tail cut" label, U_MSEC, impulse_reverb_metadata::CONV_LENGTH), \
CONTROL("ifi" id, "Fade in" label, U_MSEC, impulse_reverb_metadata::CONV_LENGTH), \
CONTROL("ifo" id, "Fade out" label, U_MSEC, impulse_reverb_metadata::CONV_LENGTH), \
TRIGGER("ils" id, "Impulse listen" label), \
TRIGGER("ils" id, "Impulse listen preview" label), \
TRIGGER("ilc" id, "Impulse stop preview" label), \
SWITCH("irv" id, "Impulse reverse" label, 0.0f), \
STATUS("ifs" id, "Load status" label), \
METER("ifl" id, "Impulse length" label, U_MSEC, impulse_reverb_metadata::CONV_LENGTH), \
Expand Down
50 changes: 42 additions & 8 deletions src/main/plug/impulse_reverb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ namespace lsp
af->pFadeIn = NULL;
af->pFadeOut = NULL;
af->pListen = NULL;
af->pStop = NULL;
af->pReverse = NULL;
af->pStatus = NULL;
af->pLength = NULL;
Expand Down Expand Up @@ -289,6 +290,9 @@ namespace lsp
destroy_samples(gc_list);

c->sEqualizer.destroy();
for (size_t i=0; i<meta::impulse_reverb_metadata::FILES; ++i)
c->vPlaybacks[i].destroy();

c->vOut = NULL;
c->vBuffer = NULL;
}
Expand Down Expand Up @@ -370,6 +374,7 @@ namespace lsp
af_descriptor_t *f = &vFiles[i];

f->sListen.init();
f->sStop.init();

f->pOriginal = NULL;
f->pProcessed = NULL;
Expand Down Expand Up @@ -399,6 +404,7 @@ namespace lsp
f->pFadeIn = NULL;
f->pFadeOut = NULL;
f->pListen = NULL;
f->pStop = NULL;
f->pReverse = NULL;
f->pStatus = NULL;
f->pLength = NULL;
Expand Down Expand Up @@ -499,6 +505,7 @@ namespace lsp
BIND_PORT(f->pFadeIn);
BIND_PORT(f->pFadeOut);
BIND_PORT(f->pListen);
BIND_PORT(f->pStop);
BIND_PORT(f->pReverse);
BIND_PORT(f->pStatus);
BIND_PORT(f->pLength);
Expand Down Expand Up @@ -748,6 +755,8 @@ namespace lsp
// Listen button pressed?
if (f->pListen != NULL)
f->sListen.submit(f->pListen->value());
if (f->pStop != NULL)
f->sStop.submit(f->pStop->value());
}
}

Expand Down Expand Up @@ -879,22 +888,44 @@ namespace lsp

void impulse_reverb::process_listen_events()
{
const size_t fadeout = dspu::millis_to_samples(fSampleRate, 5.0f);
dspu::PlaySettings ps;

for (size_t i=0; i<meta::impulse_reverb_metadata::FILES; ++i)
{
af_descriptor_t *f = &vFiles[i];

if (!f->sListen.pending())
continue;
// Need to start audio preview playback?
if (f->sListen.pending())
{
lsp_trace("Submitted listen toggle");
dspu::Sample *s = vChannels[0].sPlayer.get(i);
const size_t n_c = (s != NULL) ? s->channels() : 0;
if (n_c > 0)
{
for (size_t j=0; j<2; ++j)
{
channel_t *c = &vChannels[j];
ps.set_channel(i, j % n_c);
ps.set_playback(0, 0, GAIN_AMP_0_DB);

lsp_trace("Submitted listen toggle");
dspu::Sample *s = vChannels[0].sPlayer.get(i);
size_t n_c = (s != NULL) ? s->channels() : 0;
if (n_c > 0)
c->vPlaybacks[i].cancel(fadeout, 0);
c->vPlaybacks[i] = c->sPlayer.play(&ps);
}
}
f->sListen.commit();
}

// Need to cancel audio preview playback?
if (f->sStop.pending())
{
for (size_t j=0; j<2; ++j)
vChannels[j].sPlayer.play(i, j%n_c, 1.0f, 0);
{
channel_t *c = &vChannels[j];
c->vPlaybacks[i].cancel(fadeout, 0);
}
f->sStop.commit();
}
f->sListen.commit();
}
}

Expand Down Expand Up @@ -1240,6 +1271,7 @@ namespace lsp
v->write_object("sBypass", &c->sBypass);
v->write_object("sPlayer", &c->sPlayer);
v->write_object("sEqualizer", &c->sEqualizer);
v->write_object_array("vPlaybacks", c->vPlaybacks, meta::impulse_reverb_metadata::FILES);

v->write("vOut", c->vOut);
v->write("vBuffer", c->vBuffer);
Expand Down Expand Up @@ -1296,6 +1328,7 @@ namespace lsp
v->begin_object(af, sizeof(af_descriptor_t));
{
v->write_object("sListen", &af->sListen);
v->write_object("sStop", &af->sStop);
v->write_object("pOriginal", af->pOriginal);
v->write_object("pProcessed", af->pProcessed);

Expand All @@ -1320,6 +1353,7 @@ namespace lsp
v->write("pFadeIn", af->pFadeIn);
v->write("pFadeOut", af->pFadeOut);
v->write("pListen", af->pListen);
v->write("pStop", af->pStop);
v->write("pReverse", af->pReverse);
v->write("pStatus", af->pStatus);
v->write("pLength", af->pLength);
Expand Down

0 comments on commit d4b84b3

Please sign in to comment.