Skip to content

Commit 5a7ca2b

Browse files
authored
add section number to clip names, copy clip names along with clips (#3195)
* use section numbers with clip names - if clip has no name, display "Section: <section num>" - if clip has a name, display "<section num>: <clip name>" * copy clip names when duplicating clips - append a number to the clip name if necessary to avoid duplicates on the same output; if the name already ends with a number, the existing number is incremented instead
1 parent 0d55ca5 commit 5a7ca2b

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

src/deluge/gui/views/session_view.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ void SessionView::cloneClip(uint8_t yDisplayFrom, uint8_t yDisplayTo) {
21452145
Clip* newClip = (Clip*)modelStack->getTimelineCounter();
21462146

21472147
newClip->section = (uint8_t)(newClip->section + 1) % kMaxNumSections;
2148+
copyClipName(clipToClone, newClip, clipToClone->output);
21482149

21492150
int32_t newIndex = yDisplayTo + currentSong->songViewYScroll;
21502151

@@ -3566,6 +3567,34 @@ void SessionView::setupNewClip(Clip* newClip) {
35663567
}
35673568
}
35683569

3570+
void SessionView::copyClipName(Clip* source, Clip* target, Output* targetOutput) {
3571+
if (source->name.isEmpty()) {
3572+
return;
3573+
}
3574+
// Start from the original clip name. We have max 12 sections, so being able to append
3575+
// a two digit number is enough.
3576+
DEF_STACK_STRING_BUF(newName, source->name.getLength() + 2);
3577+
newName.append(source->name.get());
3578+
// If the name already exists on the target output, we'll append a number. We start from 2,
3579+
// because "BRIDGE" & "BRIDGE2" make more sense than "BRIDGE" & "BRIDGE1".
3580+
int32_t counter = 2;
3581+
// If the original ends in a number, grab it instead.
3582+
int32_t sourceEnd = newName.size();
3583+
int32_t end = sourceEnd;
3584+
while (end > 0 && isdigit(newName.data()[end - 1])) {
3585+
end--;
3586+
}
3587+
if (end < sourceEnd) {
3588+
counter = atoi(newName.data() + end);
3589+
}
3590+
// Keep trying until we have a name that's unique on the output.
3591+
while (targetOutput->getClipFromName(newName.data()) != nullptr) {
3592+
newName.truncate(end);
3593+
newName.appendInt(counter++);
3594+
}
3595+
target->name.set(newName.data());
3596+
}
3597+
35693598
Clip* SessionView::gridCreateClip(uint32_t targetSection, Output* targetOutput, Clip* sourceClip) {
35703599
actionLogger.deleteAllLogs();
35713600

@@ -3588,6 +3617,8 @@ Clip* SessionView::gridCreateClip(uint32_t targetSection, Output* targetOutput,
35883617
if (newClip == nullptr) {
35893618
return nullptr;
35903619
}
3620+
// ...with a derived name
3621+
copyClipName(sourceClip, newClip, targetOutput);
35913622
}
35923623

35933624
// Create new clip in existing track

src/deluge/gui/views/session_view.h

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class SessionView final : public ClipNavigationTimelineView {
119119

120120
Clip* getClipForLayout();
121121

122+
void copyClipName(Clip* source, Clip* target, Output* targetOutput);
123+
122124
// Members for grid layout
123125
inline bool gridFirstPadActive() { return (gridFirstPressedX != -1 && gridFirstPressedY != -1); }
124126
ActionResult gridHandlePads(int32_t x, int32_t y, int32_t on);

src/deluge/gui/views/view.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -2045,13 +2045,22 @@ void View::drawOutputNameFromDetails(OutputType outputType, int32_t channel, int
20452045
}
20462046

20472047
if (clip) {
2048-
if (!clip->name.isEmpty()) {
2049-
yPos = yPos + 14;
2050-
canvas.drawStringCentred(clip->name.get(), yPos, kTextSpacingX, kTextSpacingY);
2051-
deluge::hid::display::OLED::setupSideScroller(1, clip->name.get(), 0, OLED_MAIN_WIDTH_PIXELS, yPos,
2052-
yPos + kTextSpacingY, kTextSpacingX, kTextSpacingY,
2053-
false);
2048+
// "SECTION NN" is 10, "NN: " is 3 => 10 over current name is always enough.
2049+
DEF_STACK_STRING_BUF(info, clip->name.getLength() + 10);
2050+
if (clip->name.isEmpty()) {
2051+
info.append("Section ");
2052+
info.appendInt(clip->section + 1);
20542053
}
2054+
else {
2055+
info.appendInt(clip->section + 1);
2056+
info.append(": ");
2057+
info.append(clip->name.get());
2058+
}
2059+
yPos = yPos + 14;
2060+
canvas.drawStringCentred(info.data(), yPos, kTextSpacingX, kTextSpacingY);
2061+
deluge::hid::display::OLED::setupSideScroller(1, info.data(), 0, OLED_MAIN_WIDTH_PIXELS, yPos,
2062+
yPos + kTextSpacingY, kTextSpacingX, kTextSpacingY,
2063+
false);
20552064
}
20562065
}
20572066
else {

src/deluge/util/d_string.h

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ class StringBuf {
115115
void append(const char* str) { ::strncat(buf_, str, capacity_ - size() - 1); }
116116
void append(char c) { ::strncat(buf_, &c, 1); }
117117
void clear() { buf_[0] = 0; }
118+
void truncate(std::size_t newSize) {
119+
if (newSize < capacity_) {
120+
buf_[newSize] = 0;
121+
}
122+
}
118123

119124
// TODO: Validate buffer size. These can overflow
120125
void appendInt(int i, int minChars = 1) { intToString(i, buf_ + size(), minChars); }

0 commit comments

Comments
 (0)