Skip to content

Commit 30a4cea

Browse files
replace bars/pauses
1 parent ea2c16e commit 30a4cea

File tree

7 files changed

+85
-30
lines changed

7 files changed

+85
-30
lines changed

gui/BarReplaceDialog.hui

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Dialog bar-replace-dialog "Replace bars" width=350 height=80 headerbar closebutt
22
Grid ? "" vertical
33
Grid ? "" vertical
44
Label t_info "Keeping the overall duration" expandx center italic
5+
RadioButton type:bars "Bars"
56
Grid ? ""
67
Label t_number "Number" right disabled
78
SpinButton number "1" range=1:1000:1 expandx
@@ -15,6 +16,10 @@ Dialog bar-replace-dialog "Replace bars" width=350 height=80 headerbar closebutt
1516
---|
1617
Label t_result_bpm "=> Bpm" right disabled
1718
Label result_bpm "" bold
19+
RadioButton type:pause "Pause"
20+
Grid ? ""
21+
Label t_result_duration "=> Duration" right disabled
22+
Label result_duration "" bold
1823
Grid ? "" buttonbar
1924
Button /cancel "Cancel" image=hui:cancel
2025
---|

gui/PopupMenuBar.hui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Menu popup-menu-bar ""
22
Item header "Bar" disabled
33
Separator
4-
Item /bars-edit-speed "Edit speed..."
4+
Item /bars-edit-speed "Edit speed/duration..."
55
Item /bars-replace "Replace..."
66
Item /bars-scale "Scale" image=hui:zoom-in
77
Item /bars-add "Add bars..." flat image=hui:add

src/Tsunami.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Tsunami::Tsunami() :
6363
set_property("version", AppVersion);
6464
set_property("comment", _("The friendly audio workstation"));
6565
set_property("website", "https://github.com/momentarylapse/tsunami");
66-
set_property("copyright", "© 2007-2024 by Michael Ankele");
66+
set_property("copyright", "© 2007-2025 by Michael Ankele");
6767
set_property("author", "Michael Ankele <michi@lupina.de>;2er0;Benji <mail@benji.is>");
6868
//set_property("designer", "Michael Ankele <michi@lupina.de>;2er0;Benji <mail@benji.is>");
6969
set_property("documenter", "no one :P");

src/view/TsunamiWindow.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,20 +1117,10 @@ void TsunamiWindow::on_edit_bars_speed() {
11171117
void TsunamiWindow::on_replace_bars() {
11181118
if (view->sel._bars.num == 0)
11191119
return;
1120-
int num_bars = 0;
1121-
int num_pauses = 0;
1122-
for (int i: view->sel.bar_indices(song)) {
1123-
if (song->bars[i]->is_pause())
1124-
num_pauses++;
1125-
else
1126-
num_bars++;
1127-
}
1128-
if (num_bars > 0 and num_pauses == 0) {
1120+
if (view->sel.bar_indices(song).num > 0) {
11291121
hui::fly(new BarReplaceDialog(win, song, view->sel.bar_indices(song)));
1130-
} else if (num_bars == 0 and num_pauses == 1) {
1131-
hui::fly(new PauseEditDialog(win, song, view->sel.bar_indices(song)[0]));
11321122
} else {
1133-
session->e(_("Can only edit bars or a single pause at a time."));
1123+
session->e(_("No bars or pauses selected."));
11341124
}
11351125
}
11361126

src/view/dialog/BarReplaceDialog.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ BarReplaceDialog::BarReplaceDialog(hui::Window *parent, Song *_song, const Array
2424
duration += song->bars[i]->length;
2525

2626
new_bar = song->bars[sel[0]]->pattern();
27+
if (song->bars[sel[0]]->is_pause())
28+
new_bar = BarPattern(duration, 4, 1);
2729

2830
set_int("number", sel.num);
2931
set_int("beats", new_bar.beats.num);
@@ -36,10 +38,13 @@ BarReplaceDialog::BarReplaceDialog(hui::Window *parent, Song *_song, const Array
3638
check("complex", !new_bar.is_uniform());
3739
hide_control("beats", !new_bar.is_uniform());
3840
hide_control("pattern", new_bar.is_uniform());
41+
set_string("result_duration", song->get_time_str_long(duration));
42+
check("type:bars", true);
3943
check("shift-data", bar_dialog_move_data);
4044
check("scale-audio", bar_dialog_scale_audio);
4145
enable("scale-audio", bar_dialog_move_data);
4246

47+
on_type(Type::Bars);
4348
update_result_bpm();
4449

4550
event("ok", [this] { on_ok(); });
@@ -51,30 +56,27 @@ BarReplaceDialog::BarReplaceDialog(hui::Window *parent, Song *_song, const Array
5156
event("number", [this] { on_number(); });
5257
event("complex", [this] { on_complex(); });
5358
event("shift-data", [this] { on_shift_data(); });
59+
event("type:bars", [this] { on_type(Type::Bars); });
60+
event("type:pause", [this] { on_type(Type::Pause); });
5461
}
5562

5663
void BarReplaceDialog::on_ok() {
5764
song->begin_action_group("replace bars");
5865

5966
int number = get_int("number");
6067

61-
//if (number != sel.num){
68+
if (type == Type::Bars) {
6269
foreachb(int i, sel)
6370
song->delete_bar(i, false);
6471
new_bar.length = duration / number;
6572
for (int i=0; i<number; i++)
6673
song->add_bar(sel[0], new_bar, BarEditMode::Ignore);
67-
/*}else{
68-
foreachb(int i, sel){
69-
BarPattern b = *song->bars[i];
70-
b.num_beats = new_bar.num_beats;
71-
b.num_sub_beats = new_bar.num_sub_beats;
72-
//set_bar_pattern(b, get_string("pattern"));
73-
b.set_pattern(new_bar.pattern);
74-
b.length = duration / number;
75-
song->edit_bar(i, b, Bar::EditMode::IGNORE);
76-
}
77-
}*/
74+
} else {
75+
foreachb(int i, sel)
76+
song->delete_bar(i, false);
77+
new_bar = BarPattern(duration, 0, 1);
78+
song->add_bar(sel[0], new_bar, BarEditMode::Ignore);
79+
}
7880
song->end_action_group();
7981

8082
request_destroy();
@@ -121,4 +123,16 @@ void BarReplaceDialog::on_shift_data() {
121123
enable("scale-audio", is_checked(""));
122124
}
123125

126+
void BarReplaceDialog::on_type(Type _type) {
127+
type = _type;
128+
enable("number", type == Type::Bars);
129+
enable("beats", type == Type::Bars);
130+
enable("pattern", type == Type::Bars);
131+
enable("complex", type == Type::Bars);
132+
enable("divisor", type == Type::Bars);
133+
enable("result_bpm", type == Type::Bars);
134+
enable("result_duration", type == Type::Pause);
135+
}
136+
137+
124138
}

src/view/dialog/BarReplaceDialog.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ class BarReplaceDialog : public hui::Dialog {
3434
void on_pattern();
3535
void update_result_bpm();
3636
void on_shift_data();
37+
38+
enum class Type {
39+
Bars,
40+
Pause
41+
};
42+
Type type;
43+
void on_type(Type type);
3744
};
3845

3946
}

static/hui_resources.txt

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,17 +685,23 @@ Grid
685685
vertical
686686
0
687687
0
688-
2
688+
5
689689
Label
690690
t_info
691691
expandx,center,italic
692692
0
693693
0
694694
0
695+
RadioButton
696+
type:bars
697+
698+
1
699+
0
700+
0
695701
Grid
696702
?
697703

698-
1
704+
2
699705
0
700706
8
701707
Label
@@ -758,6 +764,30 @@ bold
758764
1
759765
2
760766
0
767+
RadioButton
768+
type:pause
769+
770+
3
771+
0
772+
0
773+
Grid
774+
?
775+
776+
4
777+
0
778+
2
779+
Label
780+
t_result_duration
781+
right,disabled
782+
0
783+
0
784+
0
785+
Label
786+
result_duration
787+
bold
788+
1
789+
0
790+
0
761791
Grid
762792
?
763793
buttonbar
@@ -9360,7 +9390,7 @@ default,image=hui:ok
93609390
# Language
93619391
English
93629392
# Number Of IDs
9363-
813
9393+
816
93649394
# Text
93659395
/bars-add
93669396
Add bars...
@@ -9375,7 +9405,7 @@ Delete
93759405
Edit...
93769406

93779407
/bars-edit-speed
9378-
Edit speed...
9408+
Edit speed/duration...
93799409

93809410
/bars-replace
93819411
Replace...
@@ -9854,6 +9884,15 @@ Number
98549884
bar-replace-dialog/t_result_bpm
98559885
=> Bpm
98569886

9887+
bar-replace-dialog/t_result_duration
9888+
=> Duration
9889+
9890+
bar-replace-dialog/type:bars
9891+
Bars
9892+
9893+
bar-replace-dialog/type:pause
9894+
Pause
9895+
98579896
bar_add_dialog/bad_t_beats
98589897
Beats
98599898

0 commit comments

Comments
 (0)