Skip to content

Commit

Permalink
don't jump to cue point when temporarily pausing to perform actions, …
Browse files Browse the repository at this point in the history
…send panic when pausing to perform actions
  • Loading branch information
alex-tee committed Feb 4, 2021
1 parent 753dedb commit df5612d
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 8 deletions.
7 changes: 7 additions & 0 deletions inc/audio/transport.h
Expand Up @@ -259,6 +259,13 @@ typedef struct Transport
/** Paused signal from process thread. */
ZixSem paused;

/**
* Position of the playhead before pausing.
*
* Used by UndoableAction.
*/
Position playhead_before_pause;

/** Play state. */
Play_State play_state;
} Transport;
Expand Down
8 changes: 6 additions & 2 deletions src/actions/undoable_action.c
Expand Up @@ -25,6 +25,7 @@
#include "actions/transport_action.h"
#include "actions/undoable_action.h"
#include "project.h"
#include "utils/flags.h"
#include "zrythm_app.h"

#include <glib.h>
Expand Down Expand Up @@ -73,9 +74,9 @@ undoable_action_init_loaded (
typedef struct EngineState
{
/** Engine running. */
int running;
int running;
/** Playback. */
bool playing;
bool playing;
} EngineState;

/**
Expand Down Expand Up @@ -118,6 +119,9 @@ resume_engine (

if (state->playing)
{
transport_move_playhead (
TRANSPORT, &TRANSPORT->playhead_before_pause,
F_NO_PANIC, F_NO_SET_CUE_POINT);
transport_request_roll (TRANSPORT);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/audio/engine.c
Expand Up @@ -895,8 +895,10 @@ engine_process_prepare (
/*zix_sem_post (&TRANSPORT->paused);*/
#ifdef HAVE_JACK
if (self->audio_backend == AUDIO_BACKEND_JACK)
jack_transport_stop (
self->client);
{
jack_transport_stop (
self->client);
}
#endif
}
else if (self->transport->play_state ==
Expand Down
13 changes: 11 additions & 2 deletions src/audio/metronome.c
Expand Up @@ -174,10 +174,19 @@ find_and_queue_metronome (
&bar_pos, i + 1);
long bar_offset_long =
bar_pos.frames - start_pos->frames;
g_return_if_fail (bar_offset_long >= 0);
if (bar_offset_long < 0)
{
g_critical (
"bar offset long (%ld) is < 0",
bar_offset_long);
g_message ("bar pos:");
position_print (&bar_pos);
g_message ("start pos:");
position_print (start_pos);
}
long metronome_offset_long =
bar_offset_long + loffset;
g_return_if_fail (bar_offset_long >= 0);
g_return_if_fail (metronome_offset_long >= 0);
nframes_t metronome_offset =
(nframes_t) metronome_offset_long;
g_return_if_fail (
Expand Down
4 changes: 3 additions & 1 deletion src/audio/transport.c
Expand Up @@ -429,12 +429,14 @@ transport_request_pause (
{
self->play_state = PLAYSTATE_PAUSE_REQUESTED;

TRANSPORT->playhead_before_pause =
self->playhead_pos;
if (!ZRYTHM_TESTING &&
g_settings_get_boolean (
S_TRANSPORT, "return-to-cue"))
{
transport_move_playhead (
self, &self->cue_pos, F_NO_PANIC,
self, &self->cue_pos, F_PANIC,
F_NO_SET_CUE_POINT);
}
}
Expand Down
40 changes: 39 additions & 1 deletion tests/audio/metronome.c
Expand Up @@ -93,14 +93,52 @@ test_find_and_queue_metronome ()
transport_add_to_playhead (
TRANSPORT, AUDIO_ENGINE->block_length);
metronome_queue_events (
AUDIO_ENGINE, 0, 1);
AUDIO_ENGINE, 0, 1);

/* assert metronome is queued for 1.1.1.0 */
g_assert_cmpint (
SAMPLE_PROCESSOR->num_current_samples, ==, 1);

}

{
Position play_pos;
position_set_to_bar (&play_pos, 16);
position_add_frames (&play_pos, -4);
transport_set_playhead_pos (
TRANSPORT, &play_pos);

for (nframes_t i = 0; i < 200; i++)
{
g_message ("%u", i);
SAMPLE_PROCESSOR->num_current_samples = 0;
metronome_queue_events (
AUDIO_ENGINE, 0, 1);
g_assert_cmpint (
SAMPLE_PROCESSOR->num_current_samples, ==,
i == 4);
transport_add_to_playhead (
TRANSPORT, 1);
}

position_set_to_bar (&play_pos, 16);
position_add_frames (&play_pos, -4);
transport_set_playhead_pos (
TRANSPORT, &play_pos);
for (nframes_t i = 0; i < 200; i++)
{
g_message ("%u", i);
SAMPLE_PROCESSOR->num_current_samples = 0;
metronome_queue_events (
AUDIO_ENGINE, 0, 2);
g_assert_cmpint (
SAMPLE_PROCESSOR->num_current_samples, ==,
(i >= 3 && i <= 4));
transport_add_to_playhead (
TRANSPORT, 1);
}
}

test_helper_zrythm_cleanup ();
}

Expand Down

0 comments on commit df5612d

Please sign in to comment.