Skip to content

Commit ad8723e

Browse files
committed
impl: Improve speed of several macros
"Set panning", "Set pitch", "Set velocity", "Replace key" and "Reset" macros are now much faster.
1 parent 2c2a765 commit ad8723e

8 files changed

Lines changed: 37 additions & 118 deletions

File tree

scripts/draw_window_macro_arpeggio/draw_window_macro_arpeggio.gml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function draw_window_macro_arpeggio() {
4242
val = 0
4343
pattern = string_digits_symbol(pattern, "|")
4444
pattern = string(pattern + "|")
45-
arp = selection_to_array(pattern)
45+
var arp = selection_to_array(pattern)
4646
arplen = string_count("|", pattern)
4747
while (val < total_vals) {
4848
for (i = 0; i < arplen; i++;) {
@@ -66,6 +66,7 @@ function draw_window_macro_arpeggio() {
6666
var new_str = array_to_selection(arr_data, total_vals)
6767
selection_load_ext(selection_x, selection_y, new_str)
6868
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
69+
if(!keyboard_check(vk_alt)) selection_place(false)
6970
}
7071
if (draw_button2(x1 + 70, y1 + 98, 60, condstr(language !=1, "Cancel", "取消")) && (windowopen = 1 || theme != 3)) {windowclose = 1}
7172
if (display_mouse_get_x() - window_get_x() >= 0 && display_mouse_get_y() - window_get_y() >= 0 && display_mouse_get_x() - window_get_x() < 0 + window_width && display_mouse_get_y() - window_get_y() < 0 + window_height) {

scripts/draw_window_macro_setpanning/draw_window_macro_setpanning.gml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,8 @@ function draw_window_macro_setpanning() {
2929
windowalpha = 0
3030
windowclose = 0
3131
windowopen = 0
32-
str = selection_code
33-
val = 0
34-
var arr_data = selection_to_array(str)
3532
window = 0
36-
total_vals = array_length(arr_data)
37-
val = 0
38-
while (val < total_vals) {
39-
val += 5
40-
arr_data[val] = setpan + 100
41-
val += 2
42-
while arr_data[val] != -1 {
43-
val += 4
44-
arr_data[val] = setpan + 100
45-
val += 2
46-
}
47-
val ++
48-
}
49-
var new_str = array_to_selection(arr_data, total_vals)
50-
selection_load_ext(selection_x, selection_y, new_str)
51-
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
33+
selection_change(m_pan, setpan + 100, false)
5234
if(!keyboard_check(vk_alt)) selection_place(false)
5335
}
5436
if (draw_button2(x1 + 70, y1 + 98, 60, condstr(language !=1, "Cancel", "取消")) && (windowopen = 1 || theme != 3)) {windowclose = 1}

scripts/draw_window_macro_setpitch/draw_window_macro_setpitch.gml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,8 @@ function draw_window_macro_setpitch() {
3030
windowalpha = 0
3131
windowclose = 0
3232
windowopen = 0
33-
str = selection_code
34-
val = 0
35-
var arr_data = selection_to_array(str)
3633
window = 0
37-
total_vals = array_length(arr_data)
38-
val = 0
39-
while (val < total_vals) {
40-
val += 6
41-
if (!addpitch) arr_data[val] = setpit
42-
else arr_data[val] = real(arr_data[val]) + real(setpit)
43-
val += 1
44-
while arr_data[val] != -1 {
45-
val += 5
46-
if (!addpitch) arr_data[val] = setpit
47-
else arr_data[val] = real(arr_data[val]) + real(setpit)
48-
val += 1
49-
}
50-
val ++
51-
}
52-
var new_str = array_to_selection(arr_data, total_vals)
53-
selection_load_ext(selection_x, selection_y, new_str)
54-
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
34+
selection_change(m_pit, setpit, addpitch)
5535
if(!keyboard_check(vk_alt)) selection_place(false)
5636
}
5737
if (draw_button2(x1 + 70, y1 + 98, 60, condstr(language !=1, "Cancel", "取消")) && (windowopen = 1 || theme != 3)) {windowclose = 1}

scripts/draw_window_macro_setvelocity/draw_window_macro_setvelocity.gml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,25 @@ function draw_window_macro_setvelocity() {
3030
windowalpha = 0
3131
windowclose = 0
3232
windowopen = 0
33-
str = selection_code
34-
val = 0
35-
var arr_data = selection_to_array(str)
3633
window = 0
37-
total_vals = array_length(arr_data)
38-
val = 0
39-
while (val < total_vals) {
40-
val += 4
41-
if (percentvel) arr_data[val] = arr_data[val] * setvel / 100
42-
else arr_data[val] = setvel
43-
if (arr_data[val] > 100) arr_data[val] = 100
44-
val += 3
45-
while arr_data[val] != -1 {
46-
val += 3
47-
if (percentvel) arr_data[val] = arr_data[val] * setvel / 100
48-
else arr_data[val] = setvel
49-
if (arr_data[val] > 100) arr_data[val] = 100
50-
val += 3
34+
str = selection_code
35+
if (!percentvel) {
36+
selection_change(m_vel, setvel, false)
37+
} else {
38+
str = selection_code
39+
if (selected = 0) return 0
40+
for (a = 0; a < selection_l; a += 1) {
41+
if (selection_colfirst[a] > -1) {
42+
for (b = selection_colfirst[a]; b <= selection_collast[a]; b += 1) {
43+
if (selection_exists[a, b]) {
44+
selection_vel[a, b] = selection_vel[a, b] * setvel / 100
45+
}
46+
}
47+
}
5148
}
52-
val ++
49+
selection_code_update()
50+
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
5351
}
54-
var new_str = array_to_selection(arr_data, total_vals)
55-
selection_load_ext(selection_x, selection_y, new_str)
56-
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
5752
if(!keyboard_check(vk_alt)) selection_place(false)
5853
}
5954
if (draw_button2(x1 + 70, y1 + 98, 60, condstr(language != 1, "Cancel", "取消")) && (windowopen = 1 || theme != 3)) {windowclose = 1}

scripts/draw_window_macro_stagger/draw_window_macro_stagger.gml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function draw_window_macro_stagger() {
5353
conf = 0
5454
pattern = string_digits_symbol(pattern, "|")
5555
pattern = string(pattern + "|")
56-
arp = selection_to_array(pattern)
56+
var arp = selection_to_array(pattern)
5757
arplen = string_count("|", pattern)
5858

5959
maxlength = 0;
@@ -89,8 +89,7 @@ function draw_window_macro_stagger() {
8989
var new_str = array_to_selection(arr_data, total_vals)
9090
selection_load(selection_x, selection_y, new_str, true)
9191
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
92-
// Deselect selection
93-
selection_remove(selection_x, selection_y, selection_x + selection_l, selection_y + selection_h, true, false)
92+
if(!keyboard_check(vk_alt)) selection_place(false)
9493
}
9594
if (draw_button2(x1 + 75, y1 + 128, 60, condstr(language != 1, "Cancel", "取消")) && (windowopen = 1 || theme != 3)) {windowclose = 1}
9695
if (display_mouse_get_x() - window_get_x() >= 0 && display_mouse_get_y() - window_get_y() >= 0 && display_mouse_get_x() - window_get_x() < 0 + window_width && display_mouse_get_y() - window_get_y() < 0 + window_height) {
Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
11
function macro_replacekey() {
22
// macro_replacekey()
33
// Replaces all notes with the first note in the selection. Good for batch chord and tremolo edits.
4-
var str, total_vals, val, key
4+
var str, key
55
str = selection_code
66
if (selected = 0) return 0
77
var arr_data = selection_to_array(str)
8-
total_vals = array_length(arr_data)
9-
val = 0
108
key = arr_data[3]
11-
//show_debug_message(string_count("-1", str))
12-
//for (var i = 0; i < total_vals; i++;) {show_debug_message(arr_data[i])}
13-
while (val < total_vals) {
14-
val += 3
15-
arr_data[val] = key
16-
val += 4
17-
while arr_data[val] != -1 {
18-
val += 2
19-
arr_data[val] = key
20-
val += 4
21-
}
22-
val ++
23-
}
24-
var new_str = array_to_selection(arr_data, total_vals)
25-
selection_load_ext(selection_x, selection_y, new_str)
26-
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
27-
selection_code_update()
28-
29-
30-
9+
selection_change(m_key, key, false)
10+
if(!keyboard_check(vk_alt)) selection_place(false)
3111
}
Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
11
function macro_reset() {
22
// macro_reset()
3-
var str, total_vals, val
4-
str = selection_code
3+
var str = selection_code
54
if (selected = 0) return 0
6-
var arr_data = selection_to_array(str)
7-
total_vals = array_length(arr_data)
8-
val = 0
9-
//show_debug_message(string_count("-1", str))
10-
//for (var i = 0; i < total_vals; i++;) {show_debug_message(arr_data[i])}
11-
while (val < total_vals) {
12-
val += 4
13-
arr_data[val] = 100
14-
val ++
15-
arr_data[val] = 100
16-
val ++
17-
arr_data[val] = 0
18-
val ++
19-
while arr_data[val] != -1 {
20-
val += 3
21-
arr_data[val] = 100
22-
val ++
23-
arr_data[val] = 100
24-
val ++
25-
arr_data[val] = 0
26-
val ++
27-
}
28-
val ++
5+
for (a = 0; a < selection_l; a += 1) {
6+
if (selection_colfirst[a] > -1) {
7+
for (b = selection_colfirst[a]; b <= selection_collast[a]; b += 1) {
8+
if (selection_exists[a, b]) {
9+
selection_vel[a, b] = 100
10+
selection_pan[a, b] = 100
11+
selection_pit[a, b] = 0
12+
}
13+
}
14+
}
2915
}
30-
var new_str = array_to_selection(arr_data, total_vals)
31-
selection_load_ext(selection_x, selection_y, new_str)
16+
selection_code_update()
3217
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
3318
if(!keyboard_check(vk_alt)) selection_place(false)
34-
35-
3619
}

scripts/macro_tremolo_fadeout/macro_tremolo_fadeout.gml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ function macro_tremolo_fadeout() {
8282
selection_load(selection_x, selection_y, new_str, true)
8383
history_set(h_selectchange, selection_x, selection_y, try_compress_selection(selection_code), selection_x, selection_y, try_compress_selection(str))
8484
if(!keyboard_check(vk_alt)) selection_place(false)
85-
selection_code_update()
8685

8786

8887
}

0 commit comments

Comments
 (0)