Skip to content

Commit

Permalink
issue #6 (westlicht#373) Song Mode sync
Browse files Browse the repository at this point in the history
  • Loading branch information
mebitek committed Jan 3, 2024
1 parent db89588 commit 228e7d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/apps/sequencer/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,7 @@ void Engine::togglePlay(bool shift) {
void Engine::clockStart() {
_clock.masterStart();


int syncSong = _model.settings().userSettings().get<SyncSong>(SettingSyncSong)->getValue();

if (syncSong==1) {
int slotCount = _project.song().slotCount();

if (slotCount>0 && !_project.playState().songState().playing()) {
int _selectedSlot = slotCount > 0 ? clamp(1, 0, slotCount - 1) : -1;
_project.playState().playSong(_selectedSlot, PlayState::ExecuteType::Immediate);
}
}
startSong();

}

Expand All @@ -264,6 +254,28 @@ void Engine::clockContinue() {

void Engine::clockReset() {
_clock.masterReset();
stopSong();
}

bool Engine::clockRunning() const {
return _state.running();
}


void Engine::startSong() {
int syncSong = _model.settings().userSettings().get<SyncSong>(SettingSyncSong)->getValue();

if (syncSong==1) {
int slotCount = _project.song().slotCount();

if (slotCount>0 && !_project.playState().songState().playing()) {
int _selectedSlot = slotCount > 0 ? clamp(1, 0, slotCount - 1) : -1;
_project.playState().playSong(_selectedSlot, PlayState::ExecuteType::Immediate);
}
}
}

void Engine::stopSong() {
int syncSong = _model.settings().userSettings().get<SyncSong>(SettingSyncSong)->getValue();

if (syncSong==1) {
Expand All @@ -273,10 +285,6 @@ void Engine::clockReset() {
}
}

bool Engine::clockRunning() const {
return _state.running();
}

void Engine::toggleRecording() {
_state.setRecording(!_state.recording());
}
Expand Down Expand Up @@ -800,6 +808,7 @@ void Engine::initClock() {
// start clock on first clock pulse if reset is not hold and clock is not running
if (clockSetup.clockInputMode() == ClockSetup::ClockInputMode::Reset && !_clock.isRunning() && !_dio.resetInput.get()) {
_clock.slaveStart(ClockSourceExternal);
startSong();
}
if (value) {
_clock.slaveTick(ClockSourceExternal);
Expand All @@ -813,23 +822,29 @@ void Engine::initClock() {
case ClockSetup::ClockInputMode::Reset:
if (value) {
_clock.slaveReset(ClockSourceExternal);
stopSong();
} else {
_clock.slaveStart(ClockSourceExternal);
startSong();
}
break;
case ClockSetup::ClockInputMode::Run:
if (value) {
_clock.slaveContinue(ClockSourceExternal);
startSong();
} else {
_clock.slaveStop(ClockSourceExternal);
stopSong();
}
break;
case ClockSetup::ClockInputMode::StartStop:
if (value) {
_clock.slaveStart(ClockSourceExternal);
startSong();
} else {
_clock.slaveStop(ClockSourceExternal);
_clock.slaveReset(ClockSourceExternal);
stopSong()
}
break;
case ClockSetup::ClockInputMode::Last:
Expand Down
4 changes: 4 additions & 0 deletions src/apps/sequencer/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class Engine : private Clock::Listener {
void clockReset();
bool clockRunning() const;

// song control
void startSong();
void stopSong();

// recording
void toggleRecording();
void setRecording(bool recording);
Expand Down

0 comments on commit 228e7d1

Please sign in to comment.