-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgba_main.slint
162 lines (148 loc) · 5.78 KB
/
gba_main.slint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright © 2023 Jocelyn Turcotte <[email protected]>
// SPDX-License-Identifier: MIT
import {
FocusedPanel,
InstrumentsFocusScope,
PatternsFocusScope,
StepsFocusScope
} from "common.slint";
import {
GlobalSettings,
GlobalEngine,
GlobalUI
} from "globals.slint";
export {
GlobalSettings,
GlobalEngine,
GlobalUI
}
export enum FocusedScreen { main, menu }
export component MainWindow inherits Window {
out property<FocusedScreen> focused_screen: main;
out property<FocusedPanel> focused_panel: steps;
out property<int> focused_menu_row: 0;
// Menu UI values
out property<int> frames_per_step: GlobalSettings.song_settings.frames_per_step;
out property<bool> sync_enabled: GlobalSettings.settings.sync_enabled;
callback clear_status_text();
function root_key_pressed(e: KeyEvent) -> EventResult {
if e.modifiers.shift && e.text == Key.LeftArrow { cycle_focus_panel(false); }
else if e.modifiers.shift && e.text == Key.RightArrow { cycle_focus_panel(true); }
else if e.modifiers.shift && e.text == Key.UpArrow { cycle_focus_screen(false); }
else if e.modifiers.shift && e.text == Key.DownArrow { cycle_focus_screen(true); }
else if e.text == Key.LeftArrow { GlobalEngine.cycle_pattern_instrument(false); }
else if e.text == Key.RightArrow { GlobalEngine.cycle_pattern_instrument(true); }
else if e.text == Key.UpArrow { GlobalUI.select_next_song_pattern(false); }
else if e.text == Key.DownArrow { GlobalUI.select_next_song_pattern(true); }
else if e.text == Key.Return && e.modifiers.control { GlobalUI.toggle_play(false); }
else if e.text == Key.Return { GlobalUI.toggle_play(true); }
else if e.text == Key.Control {
GlobalEngine.mute_instruments();
clear_status_text();
} else {
return reject;
}
return accept;
}
function cycle_focus_panel(forward: bool) {
if forward {
if focused_panel == FocusedPanel.patterns {
focused_panel = FocusedPanel.steps;
steps_key_handler.focus();
} else if (focused_panel == FocusedPanel.steps){
focused_panel = FocusedPanel.instruments;
instruments_key_handler.focus();
}
} else {
if (focused_panel == FocusedPanel.instruments){
focused_panel = FocusedPanel.steps;
steps_key_handler.focus();
} else if focused_panel == FocusedPanel.steps {
focused_panel = FocusedPanel.patterns;
patterns_key_handler.focus();
}
}
}
function cycle_focus_screen(down: bool) {
if down {
if focused_screen == FocusedScreen.menu {
focused_screen = FocusedScreen.main;
focused_panel = FocusedPanel.steps;
steps_key_handler.focus();
}
} else {
if (focused_screen == FocusedScreen.main){
focused_screen = FocusedScreen.menu;
// focused_menu_row = 0;
menu_key_handler.focus();
}
}
}
function cycle_focus_menu_row(down: bool) {
if down {
if focused_menu_row < 3 {
focused_menu_row += 1;
}
} else {
if focused_menu_row > 0 {
focused_menu_row -= 1;
}
}
}
function cycle_frames_per_step(forward: bool) {
if forward {
if frames_per_step < 99 {
frames_per_step += 1;
}
} else {
if frames_per_step > 1 {
frames_per_step -= 1;
}
}
GlobalSettings.song_settings.frames_per_step = frames_per_step;
GlobalSettings.song_settings_changed(GlobalSettings.song_settings);
}
function toggle_sync() {
sync_enabled = !sync_enabled;
// FIXME: Implement or remove
GlobalSettings.settings.sync_enabled = sync_enabled;
GlobalSettings.settings_changed(GlobalSettings.settings);
}
forward_focus: steps_key_handler;
menu_key_handler := FocusScope {
key_pressed(e) => {
if e.text == Key.UpArrow && !e.modifiers.shift { cycle_focus_menu_row(false); }
else if e.text == Key.DownArrow && !e.modifiers.shift { cycle_focus_menu_row(true); }
else if focused_menu_row == 2 && e.text == Key.LeftArrow && GlobalUI.x_pressed { cycle_frames_per_step(false); }
else if focused_menu_row == 2 && e.text == Key.RightArrow && GlobalUI.x_pressed { cycle_frames_per_step(true); }
else if focused_menu_row == 3 && e.text == Key.LeftArrow && GlobalUI.x_pressed { toggle_sync(); }
else if focused_menu_row == 3 && e.text == Key.RightArrow && GlobalUI.x_pressed { toggle_sync(); }
else if e.text == "x" {
if focused_menu_row == 0 {
GlobalEngine.save_project();
} else if focused_menu_row == 1 {
GlobalEngine.clear_song_and_load_default_instruments();
}
}
else {
GlobalUI.update_press_states(e);
return root_key_pressed(e);
}
GlobalUI.update_press_states(e);
return accept;
}
key_released(e) => {
GlobalUI.update_release_states(e);
return accept;
}
}
patterns_key_handler := PatternsFocusScope {
root_key_pressed(e) => { root.root_key_pressed(e); }
}
steps_key_handler := StepsFocusScope {
root_key_pressed(e) => { root.root_key_pressed(e); }
}
instruments_key_handler := InstrumentsFocusScope {
root_key_pressed(e) => { root.root_key_pressed(e); }
}
}