Skip to content

Commit 20f59ed

Browse files
committed
Move punch properties to Sequencer
1 parent 11d0ccb commit 20f59ed

File tree

7 files changed

+116
-64
lines changed

7 files changed

+116
-64
lines changed

src/main/lcdgui/screens/PunchScreen.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ void PunchScreen::open()
2626

2727
auto lastTick = sequencer.lock()->getActiveSequence()->getLastTick();
2828

29-
if (lastTick < time0 || lastTick < time1 || (time0 == 0 && time1 == 0))
29+
if (lastTick < sequencer.lock()->getPunchInTime() || lastTick < sequencer.lock()->getPunchOutTime() || (sequencer.lock()->getPunchInTime() == 0 && sequencer.lock()->getPunchOutTime() == 0))
3030
{
31-
setTime0(0);
32-
setTime1(sequencer.lock()->getActiveSequence()->getLastTick());
31+
sequencer.lock()->setPunchInTime(0);
32+
sequencer.lock()->setPunchOutTime(sequencer.lock()->getActiveSequence()->getLastTick());
3333
}
3434

3535
displayBackground();
3636
displayAutoPunch();
3737

38-
ls->setFunctionKeysArrangement(on);
38+
ls->setFunctionKeysArrangement(sequencer.lock()->isPunchEnabled());
3939
}
4040

4141
void PunchScreen::turnWheel(int i)
@@ -45,10 +45,14 @@ void PunchScreen::turnWheel(int i)
4545

4646
if (focusedFieldName == "auto-punch")
4747
{
48-
setAutoPunch(autoPunch + i);
48+
setAutoPunch(sequencer.lock()->getAutoPunchMode() + i);
4949
}
5050

5151
checkAllTimes(mpc, i);
52+
53+
// Sync punch times with Sequencer
54+
sequencer.lock()->setPunchInTime(time0);
55+
sequencer.lock()->setPunchOutTime(time1);
5256
}
5357

5458
void PunchScreen::function(int i)
@@ -62,7 +66,7 @@ void PunchScreen::function(int i)
6266
mpc.getLayeredScreen()->openScreen(tabNames[i]);
6367
break;
6468
case 5:
65-
on = !on;
69+
sequencer.lock()->setPunchEnabled(!sequencer.lock()->isPunchEnabled());
6670
mpc.getLayeredScreen()->openScreen<SequencerScreen>();
6771
break;
6872
}
@@ -75,7 +79,7 @@ void PunchScreen::setAutoPunch(int i)
7579
return;
7680
}
7781

78-
autoPunch = i;
82+
sequencer.lock()->setAutoPunchMode(i);
7983

8084
displayAutoPunch();
8185
displayTime();
@@ -84,7 +88,7 @@ void PunchScreen::setAutoPunch(int i)
8488

8589
void PunchScreen::displayAutoPunch()
8690
{
87-
findField("auto-punch")->setText(autoPunchNames[autoPunch]);
91+
findField("auto-punch")->setText(autoPunchNames[sequencer.lock()->getAutoPunchMode()]);
8892
}
8993

9094
void PunchScreen::displayTime()
@@ -93,31 +97,31 @@ void PunchScreen::displayTime()
9397

9498
for (int i = 0; i < 3; i++)
9599
{
96-
findField("time" + std::to_string(i))->Hide(autoPunch == 1);
97-
findLabel("time" + std::to_string(i))->Hide(autoPunch == 1);
98-
findField("time" + std::to_string(i + 3))->Hide(autoPunch == 0);
99-
findLabel("time" + std::to_string(i + 3))->Hide(autoPunch == 0);
100+
findField("time" + std::to_string(i))->Hide(sequencer.lock()->getAutoPunchMode() == 1);
101+
findLabel("time" + std::to_string(i))->Hide(sequencer.lock()->getAutoPunchMode() == 1);
102+
findField("time" + std::to_string(i + 3))->Hide(sequencer.lock()->getAutoPunchMode() == 0);
103+
findLabel("time" + std::to_string(i + 3))->Hide(sequencer.lock()->getAutoPunchMode() == 0);
100104
}
101105

102-
findLabel("time3")->Hide(autoPunch != 2);
106+
findLabel("time3")->Hide(sequencer.lock()->getAutoPunchMode() != 2);
103107

104-
findField("time0")->setTextPadded(SeqUtil::getBar(sequence, time0) + 1, "0");
105-
findField("time1")->setTextPadded(SeqUtil::getBeat(sequence, time0) + 1, "0");
106-
findField("time2")->setTextPadded(SeqUtil::getClock(sequence, time0), "0");
107-
findField("time3")->setTextPadded(SeqUtil::getBar(sequence, time1) + 1, "0");
108-
findField("time4")->setTextPadded(SeqUtil::getBeat(sequence, time1) + 1, "0");
109-
findField("time5")->setTextPadded(SeqUtil::getClock(sequence, time1), "0");
108+
findField("time0")->setTextPadded(SeqUtil::getBar(sequence, sequencer.lock()->getPunchInTime()) + 1, "0");
109+
findField("time1")->setTextPadded(SeqUtil::getBeat(sequence, sequencer.lock()->getPunchInTime()) + 1, "0");
110+
findField("time2")->setTextPadded(SeqUtil::getClock(sequence, sequencer.lock()->getPunchInTime()), "0");
111+
findField("time3")->setTextPadded(SeqUtil::getBar(sequence, sequencer.lock()->getPunchOutTime()) + 1, "0");
112+
findField("time4")->setTextPadded(SeqUtil::getBeat(sequence, sequencer.lock()->getPunchOutTime()) + 1, "0");
113+
findField("time5")->setTextPadded(SeqUtil::getClock(sequence, sequencer.lock()->getPunchOutTime()), "0");
110114
}
111115

112116
void PunchScreen::displayBackground()
113117
{
114118
std::string bgName = "punch-in";
115119

116-
if (autoPunch == 1)
120+
if (sequencer.lock()->getAutoPunchMode() == 1)
117121
{
118122
bgName = "punch-out";
119123
}
120-
else if (autoPunch == 2)
124+
else if (sequencer.lock()->getAutoPunchMode() == 2)
121125
{
122126
bgName = "punch-in-out";
123127
}

src/main/lcdgui/screens/PunchScreen.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ namespace mpc::lcdgui::screens
3838
private:
3939
const std::vector<std::string> tabNames{"punch", "trans", "second-seq"};
4040
const std::vector<std::string> autoPunchNames{"PUNCH IN ONLY", "PUNCH OUT ONLY", "PUNCH IN OUT"};
41-
int autoPunch = 0;
42-
bool on = false;
4341
int tab = 0;
4442

4543
void setAutoPunch(int i);

src/main/lcdgui/screens/SequencerScreen.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void SequencerScreen::open()
101101
{
102102
findBackground()->setBackgroundName("sequencer-2nd");
103103
}
104-
else if (punchScreen->on && !sequencer.lock()->isRecordingOrOverdubbing())
104+
else if (sequencer.lock()->isPunchEnabled() && !sequencer.lock()->isRecordingOrOverdubbing())
105105
{
106106
findBackground()->setBackgroundName("sequencer-punch-active");
107107
}
@@ -123,7 +123,7 @@ void SequencerScreen::open()
123123

124124
findChild("footer-label")->Hide(footerIsInvisible);
125125

126-
findChild("function-keys")->Hide(!footerIsInvisible || punchScreen->on || (mpc.getHardware()->getButton(hardware::ComponentId::ERASE)->isPressed() && sequencerIsRecordingOrOverdubbing));
126+
findChild("function-keys")->Hide(!footerIsInvisible || sequencer.lock()->isPunchEnabled() || (mpc.getHardware()->getButton(hardware::ComponentId::ERASE)->isPressed() && sequencerIsRecordingOrOverdubbing));
127127
}
128128

129129
void SequencerScreen::erase()
@@ -164,8 +164,7 @@ void SequencerScreen::close()
164164

165165
if (find(begin(screensThatDisablePunch), end(screensThatDisablePunch), nextScreen) != end(screensThatDisablePunch))
166166
{
167-
auto punchScreen = mpc.screens->get<PunchScreen>();
168-
punchScreen->on = false;
167+
sequencer.lock()->setPunchEnabled(false);
169168
}
170169

171170
sequencer.lock()->resetUndo();
@@ -542,13 +541,11 @@ void SequencerScreen::pressEnter()
542541
void SequencerScreen::function(int i)
543542
{
544543
ScreenComponent::function(i);
545-
auto punchScreen = mpc.screens->get<PunchScreen>();
546-
547-
if (punchScreen->on)
544+
if (sequencer.lock()->isPunchEnabled())
548545
{
549546
if (!sequencer.lock()->isRecordingOrOverdubbing() && i == 5)
550547
{
551-
punchScreen->on = false;
548+
sequencer.lock()->setPunchEnabled(false);
552549
findBackground()->setBackgroundName("sequencer");
553550
findChild("function-keys")->Hide(false);
554551
}
@@ -700,11 +697,9 @@ void SequencerScreen::turnWheel(int i)
700697
}
701698
else if (focusedFieldName == "sq")
702699
{
703-
auto punchScreen = mpc.screens->get<PunchScreen>();
704-
705700
if (sequencer.lock()->isPlaying())
706701
{
707-
if (!punchScreen->on)
702+
if (!sequencer.lock()->isPunchEnabled())
708703
{
709704
const auto seqIndex = sequencer.lock()->getCurrentlyPlayingSequenceIndex();
710705

@@ -716,9 +711,9 @@ void SequencerScreen::turnWheel(int i)
716711
}
717712
else
718713
{
719-
if (punchScreen->on)
714+
if (sequencer.lock()->isPunchEnabled())
720715
{
721-
punchScreen->on = false;
716+
sequencer.lock()->setPunchEnabled(false);
722717
findBackground()->setBackgroundName("sequencer");
723718
findChild("function-keys")->Hide(false);
724719
}
@@ -925,31 +920,31 @@ void SequencerScreen::displayPunchWhileRecording()
925920
auto isRecPressedOrLocked = hardware->getButton(hardware::ComponentId::REC)->isPressed() || mpc.clientEventController->clientHardwareEventController->buttonLockTracker.isLocked(hardware::ComponentId::REC);
926921
auto isOverdubPressedOrLocked = hardware->getButton(hardware::ComponentId::OVERDUB)->isPressed() || mpc.clientEventController->clientHardwareEventController->buttonLockTracker.isLocked(hardware::ComponentId::OVERDUB);
927922

928-
if (punchScreen->on && (isRecPressedOrLocked || isOverdubPressedOrLocked))
923+
if (sequencer.lock()->isPunchEnabled() && (isRecPressedOrLocked || isOverdubPressedOrLocked))
929924
{
930925
findBackground()->setBackgroundName("sequencer");
931926

932927
for (int i = 0; i < 3; i++)
933928
{
934929
auto punchRect = findChild<PunchRect>("punch-rect-" + std::to_string(i));
935-
punchRect->Hide((i == 0 && punchScreen->autoPunch == 1) || (i == 2 && punchScreen->autoPunch == 0));
936-
punchRect->setOn((i == 0 && punchScreen->autoPunch != 1) || (i == 1 && punchScreen->autoPunch == 1));
930+
punchRect->Hide((i == 0 && sequencer.lock()->getAutoPunchMode() == 1) || (i == 2 && sequencer.lock()->getAutoPunchMode() == 0));
931+
punchRect->setOn((i == 0 && sequencer.lock()->getAutoPunchMode() != 1) || (i == 1 && sequencer.lock()->getAutoPunchMode() == 1));
937932
}
938933

939934
auto time0 = findLabel("punch-time-0");
940935
auto time1 = findLabel("punch-time-1");
941936

942-
time0->Hide(punchScreen->autoPunch == 1);
943-
time1->Hide(punchScreen->autoPunch == 0);
937+
time0->Hide(sequencer.lock()->getAutoPunchMode() == 1);
938+
time1->Hide(sequencer.lock()->getAutoPunchMode() == 0);
944939

945940
auto seq = sequence.lock();
946941

947-
auto text1 = StrUtil::padLeft(std::to_string(SeqUtil::getBar(seq.get(), punchScreen->time0) + 1), "0", 3);
948-
auto text2 = StrUtil::padLeft(std::to_string(SeqUtil::getBeat(seq.get(), punchScreen->time0) + 1), "0", 2);
949-
auto text3 = StrUtil::padLeft(std::to_string(SeqUtil::getClock(seq.get(), punchScreen->time0)), "0", 2);
950-
auto text4 = StrUtil::padLeft(std::to_string(SeqUtil::getBar(seq.get(), punchScreen->time1) + 1), "0", 3);
951-
auto text5 = StrUtil::padLeft(std::to_string(SeqUtil::getBeat(seq.get(), punchScreen->time1) + 1), "0", 2);
952-
auto text6 = StrUtil::padLeft(std::to_string(SeqUtil::getClock(seq.get(), punchScreen->time1)), "0", 2);
942+
auto text1 = StrUtil::padLeft(std::to_string(SeqUtil::getBar(seq.get(), sequencer.lock()->getPunchInTime()) + 1), "0", 3);
943+
auto text2 = StrUtil::padLeft(std::to_string(SeqUtil::getBeat(seq.get(), sequencer.lock()->getPunchInTime()) + 1), "0", 2);
944+
auto text3 = StrUtil::padLeft(std::to_string(SeqUtil::getClock(seq.get(), sequencer.lock()->getPunchInTime())), "0", 2);
945+
auto text4 = StrUtil::padLeft(std::to_string(SeqUtil::getBar(seq.get(), sequencer.lock()->getPunchOutTime()) + 1), "0", 3);
946+
auto text5 = StrUtil::padLeft(std::to_string(SeqUtil::getBeat(seq.get(), sequencer.lock()->getPunchOutTime()) + 1), "0", 2);
947+
auto text6 = StrUtil::padLeft(std::to_string(SeqUtil::getClock(seq.get(), sequencer.lock()->getPunchOutTime())), "0", 2);
953948

954949
time0->setText("IN:" + text1 + "." + text2 + "." + text3);
955950
time1->setText("OUT:" + text4 + "." + text5 + "." + text6);
@@ -988,9 +983,7 @@ void SequencerScreen::stop()
988983
{
989984
ScreenComponent::stop();
990985

991-
auto punchScreen = mpc.screens->get<PunchScreen>();
992-
993-
if (punchScreen->on)
986+
if (sequencer.lock()->isPunchEnabled())
994987
{
995988
findBackground()->setBackgroundName("sequencer-punch-active");
996989

src/main/sequencer/FrameSeq.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,14 @@ void FrameSeq::triggerClickIfNeeded()
191191

192192
void FrameSeq::displayPunchRects()
193193
{
194-
auto punch = punchScreen->on && sequencer->isRecordingOrOverdubbing();
194+
auto punch = sequencer->isPunchEnabled() && sequencer->isRecordingOrOverdubbing();
195195

196196
if (punch)
197197
{
198-
bool punchIn = punchScreen->autoPunch == 0 || punchScreen->autoPunch == 2;
199-
bool punchOut = punchScreen->autoPunch == 1 || punchScreen->autoPunch == 2;
200-
auto punchInTime = punchScreen->time0;
201-
auto punchOutTime = punchScreen->time1;
198+
bool punchIn = sequencer->getAutoPunchMode() == 0 || sequencer->getAutoPunchMode() == 2;
199+
bool punchOut = sequencer->getAutoPunchMode() == 1 || sequencer->getAutoPunchMode() == 2;
200+
auto punchInTime = sequencer->getPunchInTime();
201+
auto punchOutTime = sequencer->getPunchOutTime();
202202

203203
if (punchIn && sequencer->getTickPosition() == punchInTime)
204204
{
@@ -293,9 +293,9 @@ bool FrameSeq::processSeqLoopEnabled()
293293

294294
if (sequencer->getTickPosition() >= seq->getLoopEnd() - 1)
295295
{
296-
auto punch = punchScreen->on && sequencer->isRecordingOrOverdubbing();
297-
bool punchIn = punchScreen->autoPunch == 0 || punchScreen->autoPunch == 2;
298-
bool punchOut = punchScreen->autoPunch == 1 || punchScreen->autoPunch == 2;
296+
auto punch = sequencer->isPunchEnabled() && sequencer->isRecordingOrOverdubbing();
297+
bool punchIn = sequencer->getAutoPunchMode() == 0 || sequencer->getAutoPunchMode() == 2;
298+
bool punchOut = sequencer->getAutoPunchMode() == 1 || sequencer->getAutoPunchMode() == 2;
299299

300300
if (punch && punchIn)
301301
{

src/main/sequencer/Sequencer.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,3 +2064,46 @@ void Sequencer::resetPlayedStepRepetitions()
20642064
{
20652065
playedStepRepetitions = 0;
20662066
}
2067+
2068+
bool Sequencer::isPunchEnabled()
2069+
{
2070+
return punchEnabled;
2071+
}
2072+
2073+
void Sequencer::setPunchEnabled(bool enabled)
2074+
{
2075+
punchEnabled = enabled;
2076+
}
2077+
2078+
int Sequencer::getAutoPunchMode()
2079+
{
2080+
return autoPunchMode;
2081+
}
2082+
2083+
void Sequencer::setAutoPunchMode(int mode)
2084+
{
2085+
if (mode >= 0 && mode <= 2)
2086+
{
2087+
autoPunchMode = mode;
2088+
}
2089+
}
2090+
2091+
int Sequencer::getPunchInTime()
2092+
{
2093+
return punchInTime;
2094+
}
2095+
2096+
void Sequencer::setPunchInTime(int time)
2097+
{
2098+
punchInTime = time;
2099+
}
2100+
2101+
int Sequencer::getPunchOutTime()
2102+
{
2103+
return punchOutTime;
2104+
}
2105+
2106+
void Sequencer::setPunchOutTime(int time)
2107+
{
2108+
punchOutTime = time;
2109+
}

src/main/sequencer/Sequencer.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ namespace mpc::sequencer
109109
int activeTrackIndex = 0;
110110
double tempo = 120.0;
111111
int nextSq = -1;
112+
113+
// Punch properties
114+
bool punchEnabled = false;
115+
int autoPunchMode = 0;
116+
int punchInTime = 0;
117+
int punchOutTime = 0;
112118

113119
std::shared_ptr<TempoChangeEvent> getCurrentTempoChangeEvent();
114120
void play(bool fromStart);
@@ -230,5 +236,15 @@ namespace mpc::sequencer
230236
void setOverdubbing(bool b);
231237
void playMetronomeTrack();
232238
void stopMetronomeTrack();
239+
240+
// Punch property getters and setters
241+
bool isPunchEnabled();
242+
void setPunchEnabled(bool enabled);
243+
int getAutoPunchMode();
244+
void setAutoPunchMode(int mode);
245+
int getPunchInTime();
246+
void setPunchInTime(int time);
247+
int getPunchOutTime();
248+
void setPunchOutTime(int time);
233249
};
234250
} // namespace mpc::sequencer

src/main/sequencer/Track.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,25 +551,23 @@ void Track::playNext()
551551
const auto isActiveTrackIndex = trackIndex == sequencer->getActiveTrackIndex();
552552
auto _delete = sequencer->isRecording() && (isActiveTrackIndex || recordingModeIsMulti) && (trackIndex < 64);
553553

554-
auto punchScreen = mpc.screens->get<PunchScreen>();
555-
556-
if (sequencer->isRecording() && punchScreen->on && trackIndex < 64)
554+
if (sequencer->isRecording() && sequencer->isPunchEnabled() && trackIndex < 64)
557555
{
558556
auto pos = sequencer->getTickPosition();
559557

560558
_delete = false;
561559

562-
if (punchScreen->autoPunch == 0 && pos >= punchScreen->time0)
560+
if (sequencer->getAutoPunchMode() == 0 && pos >= sequencer->getPunchInTime())
563561
{
564562
_delete = true;
565563
}
566564

567-
if (punchScreen->autoPunch == 1 && pos < punchScreen->time1)
565+
if (sequencer->getAutoPunchMode() == 1 && pos < sequencer->getPunchOutTime())
568566
{
569567
_delete = true;
570568
}
571569

572-
if (punchScreen->autoPunch == 2 && pos >= punchScreen->time0 && pos < punchScreen->time1)
570+
if (sequencer->getAutoPunchMode() == 2 && pos >= sequencer->getPunchInTime() && pos < sequencer->getPunchOutTime())
573571
{
574572
_delete = true;
575573
}

0 commit comments

Comments
 (0)