Debian Codegraph @

src/gui/speed.cpp

raw
1 /**
2 * Furnace Tracker - multi-system chiptune tracker
3 * Copyright (C) 2021-2025 tildearrow and contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "gui.h"
21 #include "imgui.h"
22 #include "misc/cpp/imgui_stdlib.h"
23 #include "intConst.h"
24
25 void FurnaceGUI::drawSpeed(bool asChild) {
26 if (nextWindow==GUI_WINDOW_SPEED) {
27 speedOpen=true;
28 ImGui::SetNextWindowFocus();
29 nextWindow=GUI_WINDOW_NOTHING;
30 }
31 if (!speedOpen && !asChild) return;
32 bool began=asChild?ImGui::BeginChild("Speed"):ImGui::Begin("Speed",&speedOpen,globalWinFlags,_("Speed"));
33 if (began) {
34 if (ImGui::BeginTable("Props",2,ImGuiTableFlags_SizingStretchProp)) {
35 ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,0.0);
36 ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0);
37
38 ImGui::TableNextRow();
39 ImGui::TableNextColumn();
40 ImGui::AlignTextToFramePadding();
41 if (ImGui::SmallButton(tempoView?_("Base Tempo##TempoOrHz"):_("Tick Rate##TempoOrHz"))) {
42 tempoView=!tempoView;
43 }
44 if (ImGui::IsItemHovered()) {
45 if (tempoView) {
46 ImGui::SetTooltip(_("click to display tick rate"));
47 } else {
48 ImGui::SetTooltip(_("click to display base tempo"));
49 }
50 }
51 ImGui::TableNextColumn();
52 float avail=ImGui::GetContentRegionAvail().x;
53 float halfAvail=(avail-ImGui::GetStyle().ItemSpacing.x)*0.5;
54 ImGui::SetNextItemWidth(halfAvail);
55 float setHz=tempoView?e->curSubSong->hz*2.5:e->curSubSong->hz;
56 if (ImGui::InputFloat("##Rate",&setHz,1.0f,10.0f,"%g")) { MARK_MODIFIED
57 if (tempoView) setHz/=2.5;
58 if (setHz<1) setHz=1;
59 if (setHz>999) setHz=999;
60 e->setSongRate(setHz);
61 }
62 if (tempoView) {
63 ImGui::SameLine();
64 ImGui::Text("= %gHz",e->curSubSong->hz);
65 } else {
66 if (e->curSubSong->hz>=49.98 && e->curSubSong->hz<=50.02) {
67 ImGui::SameLine();
68 ImGui::Text("PAL");
69 }
70 if (e->curSubSong->hz>=59.9 && e->curSubSong->hz<=60.11) {
71 ImGui::SameLine();
72 ImGui::Text("NTSC");
73 }
74 }
75
76 ImGui::TableNextRow();
77 ImGui::TableNextColumn();
78 ImGui::AlignTextToFramePadding();
79 if (keepGrooveAlive || e->curSubSong->speeds.len>2) {
80 if (ImGui::SmallButton(_("Groove"))) {
81 e->lockEngine([this]() {
82 e->curSubSong->speeds.len=1;
83 });
84 if (e->isPlaying()) play();
85 }
86 if (ImGui::IsItemHovered()) {
87 ImGui::SetTooltip(_("click for one speed"));
88 }
89 } else if (e->curSubSong->speeds.len>1) {
90 if (ImGui::SmallButton(_("Speeds"))) {
91 e->lockEngine([this]() {
92 e->curSubSong->speeds.len=4;
93 e->curSubSong->speeds.val[2]=e->curSubSong->speeds.val[0];
94 e->curSubSong->speeds.val[3]=e->curSubSong->speeds.val[1];
95 });
96 if (e->isPlaying()) play();
97 }
98 if (ImGui::IsItemHovered()) {
99 ImGui::SetTooltip(_("click for groove pattern"));
100 }
101 } else {
102 if (ImGui::SmallButton(_("Speed"))) {
103 e->lockEngine([this]() {
104 e->curSubSong->speeds.len=2;
105 e->curSubSong->speeds.val[1]=e->curSubSong->speeds.val[0];
106 });
107 if (e->isPlaying()) play();
108 }
109 if (ImGui::IsItemHovered()) {
110 ImGui::SetTooltip(_("click for two (alternating) speeds"));
111 }
112 }
113 ImGui::TableNextColumn();
114 if (keepGrooveAlive || e->curSubSong->speeds.len>2) {
115 int intVersion[256];
116 unsigned char intVersionLen=e->curSubSong->speeds.len;
117 unsigned char ignoredLoop=0;
118 unsigned char ignoredRel=0;
119 memset(intVersion,0,sizeof(int));
120 for (int i=0; i<16; i++) {
121 intVersion[i]=e->curSubSong->speeds.val[i];
122 }
123 if (intVersionLen>16) intVersionLen=16;
124
125 keepGrooveAlive=false;
126
127 ImGui::SetNextItemWidth(avail);
128 if (ImGui::InputText("##SpeedG",&grooveString)) {
129 decodeMMLStr(grooveString,intVersion,intVersionLen,ignoredLoop,1,255,ignoredRel);
130 if (intVersionLen<1) {
131 intVersionLen=1;
132 intVersion[0]=6;
133 }
134 if (intVersionLen>16) intVersionLen=16;
135 e->lockEngine([this,intVersion,intVersionLen]() {
136 e->curSubSong->speeds.len=intVersionLen;
137 for (int i=0; i<16; i++) {
138 e->curSubSong->speeds.val[i]=intVersion[i];
139 }
140 });
141 if (e->isPlaying()) play();
142 MARK_MODIFIED;
143 }
144 if (!ImGui::IsItemActive()) {
145 encodeMMLStr(grooveString,intVersion,intVersionLen,-1,-1,false);
146 } else {
147 keepGrooveAlive=true;
148 }
149 } else {
150 ImGui::SetNextItemWidth(halfAvail);
151 if (ImGui::InputScalar("##Speed1",ImGuiDataType_U8,&e->curSubSong->speeds.val[0],&_ONE,&_THREE)) { MARK_MODIFIED
152 if (e->curSubSong->speeds.val[0]<1) e->curSubSong->speeds.val[0]=1;
153 if (e->isPlaying()) play();
154 }
155 if (e->curSubSong->speeds.len>1) {
156 ImGui::SameLine();
157 ImGui::SetNextItemWidth(halfAvail);
158 if (ImGui::InputScalar("##Speed2",ImGuiDataType_U8,&e->curSubSong->speeds.val[1],&_ONE,&_THREE)) { MARK_MODIFIED
159 if (e->curSubSong->speeds.val[1]<1) e->curSubSong->speeds.val[1]=1;
160 if (e->isPlaying()) play();
161 }
162 }
163 }
164
165 ImGui::TableNextRow();
166 ImGui::TableNextColumn();
167 ImGui::AlignTextToFramePadding();
168 ImGui::Text(_("Virtual Tempo"));
169 ImGui::TableNextColumn();
170 ImGui::SetNextItemWidth(halfAvail);
171 if (ImGui::InputScalar("##VTempoN",ImGuiDataType_S16,&e->curSubSong->virtualTempoN,&_ONE,&_TEN)) { MARK_MODIFIED
172 if (e->curSubSong->virtualTempoN<1) e->curSubSong->virtualTempoN=1;
173 if (e->curSubSong->virtualTempoN>255) e->curSubSong->virtualTempoN=255;
174 e->virtualTempoChanged();
175 }
176 if (ImGui::IsItemHovered()) {
177 ImGui::SetTooltip(_("Numerator"));
178 }
179 ImGui::SameLine();
180 ImGui::SetNextItemWidth(halfAvail);
181 if (ImGui::InputScalar("##VTempoD",ImGuiDataType_S16,&e->curSubSong->virtualTempoD,&_ONE,&_TEN)) { MARK_MODIFIED
182 if (e->curSubSong->virtualTempoD<1) e->curSubSong->virtualTempoD=1;
183 if (e->curSubSong->virtualTempoD>255) e->curSubSong->virtualTempoD=255;
184 e->virtualTempoChanged();
185 }
186 if (ImGui::IsItemHovered()) {
187 ImGui::SetTooltip(_("Denominator (set to base tempo)"));
188 }
189
190 ImGui::TableNextRow();
191 ImGui::TableNextColumn();
192 ImGui::AlignTextToFramePadding();
193 ImGui::Text(_("Divider"));
194 ImGui::TableNextColumn();
195 ImGui::SetNextItemWidth(halfAvail);
196 unsigned char realTB=e->curSubSong->timeBase+1;
197 if (ImGui::InputScalar("##TimeBase",ImGuiDataType_U8,&realTB,&_ONE,&_THREE)) { MARK_MODIFIED
198 if (realTB<1) realTB=1;
199 if (realTB>16) realTB=16;
200 e->curSubSong->timeBase=realTB-1;
201 }
202 ImGui::SameLine();
203 ImGui::Text("%.2f BPM",calcBPM(e->curSubSong->speeds,e->curSubSong->hz,e->curSubSong->virtualTempoN,e->curSubSong->virtualTempoD));
204
205 ImGui::TableNextRow();
206 ImGui::TableNextColumn();
207 ImGui::AlignTextToFramePadding();
208 ImGui::Text(_("Highlight"));
209 ImGui::TableNextColumn();
210 ImGui::SetNextItemWidth(halfAvail);
211 if (ImGui::InputScalar("##Highlight1",ImGuiDataType_U8,&e->curSubSong->hilightA,&_ONE,&_FOUR)) {
212 MARK_MODIFIED;
213 }
214 ImGui::SameLine();
215 ImGui::SetNextItemWidth(halfAvail);
216 if (ImGui::InputScalar("##Highlight2",ImGuiDataType_U8,&e->curSubSong->hilightB,&_ONE,&_FOUR)) {
217 MARK_MODIFIED;
218 }
219 ImGui::EndTable();
220 }
221
222 ImGui::Separator();
223
224 if (ImGui::BeginTable("Props2",3,ImGuiTableFlags_SizingStretchProp)) {
225 ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,0.0);
226 ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0);
227 ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch,0.0);
228 ImGui::TableNextRow();
229 ImGui::TableNextColumn();
230 ImGui::AlignTextToFramePadding();
231 ImGui::Text(_("Pattern Length"));
232 ImGui::TableNextColumn();
233 float avail=ImGui::GetContentRegionAvail().x;
234 ImGui::SetNextItemWidth(avail);
235 int patLen=e->curSubSong->patLen;
236 if (ImGui::InputInt("##PatLength",&patLen,1,16)) { MARK_MODIFIED
237 if (patLen<1) patLen=1;
238 if (patLen>DIV_MAX_PATTERNS) patLen=DIV_MAX_PATTERNS;
239 e->curSubSong->patLen=patLen;
240 }
241
242 ImGui::TableNextRow();
243 ImGui::TableNextColumn();
244 ImGui::AlignTextToFramePadding();
245 ImGui::Text(_("Song Length"));
246 ImGui::TableNextColumn();
247 ImGui::SetNextItemWidth(avail);
248 int ordLen=e->curSubSong->ordersLen;
249 if (ImGui::InputInt("##OrdLength",&ordLen,1,4)) { MARK_MODIFIED
250 if (ordLen<1) ordLen=1;
251 if (ordLen>DIV_MAX_PATTERNS) ordLen=DIV_MAX_PATTERNS;
252 e->curSubSong->ordersLen=ordLen;
253 if (curOrder>=ordLen) {
254 setOrder(ordLen-1);
255 }
256 }
257
258 ImGui::EndTable();
259 }
260 }
261 if (!asChild && ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SPEED;
262 if (asChild) {
263 ImGui::EndChild();
264 } else {
265 ImGui::End();
266 }
267 }