Debian Codegraph @

src/gui/debugWindow.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 "guiConst.h"
22 #include "debug.h"
23 #include "IconsFontAwesome4.h"
24 #include <SDL_timer.h>
25 #include <fmt/printf.h>
26 #include "imgui.h"
27 #include "imgui_internal.h"
28
29 PendingDrawOsc _debugDo;
30 static float oscDebugData[2048];
31 static int oscDebugLen=800;
32 static int oscDebugHeight=400;
33 static float oscDebugLineSize=1.0;
34 static float oscDebugMin=-1.0;
35 static float oscDebugMax=1.0;
36 static float oscDebugPower=1.0;
37 static int oscDebugRepeat=1;
38 static int numApples=1;
39 static int getGainChan=0;
40 static int getGainVol=0;
41
42 static void _drawOsc(const ImDrawList* drawList, const ImDrawCmd* cmd) {
43 if (cmd!=NULL) {
44 if (cmd->UserCallbackData!=NULL) {
45 ((FurnaceGUI*)(((PendingDrawOsc*)cmd->UserCallbackData)->gui))->runPendingDrawOsc((PendingDrawOsc*)cmd->UserCallbackData);
46 }
47 }
48 }
49
50 void FurnaceGUI::drawDebug() {
51 static int bpOrder;
52 static int bpRow;
53 static int bpTick;
54 static bool bpOn;
55
56 static double ptcClock;
57 static double ptcDivider;
58 static int ptcOctave;
59 static int ptcMode;
60 static int ptcBlockBits;
61 if (nextWindow==GUI_WINDOW_DEBUG) {
62 debugOpen=true;
63 ImGui::SetNextWindowFocus();
64 nextWindow=GUI_WINDOW_NOTHING;
65 }
66 if (!debugOpen) return;
67 ImGui::SetNextWindowSizeConstraints(ImVec2(100.0f*dpiScale,100.0f*dpiScale),ImVec2(canvasW,canvasH));
68 if (ImGui::Begin("Debug",&debugOpen,globalWinFlags|ImGuiWindowFlags_NoDocking,_("Debug"))) {
69 ImGui::Text("NOTE: use with caution.");
70 if (ImGui::TreeNode("Debug Controls")) {
71 if (e->isHalted()) {
72 if (ImGui::Button("Resume")) e->resume();
73 } else {
74 if (ImGui::Button("Pause")) e->halt();
75 }
76 ImGui::SameLine();
77 if (ImGui::Button("Frame Advance")) e->haltWhen(DIV_HALT_TICK);
78 ImGui::SameLine();
79 if (ImGui::Button("Row Advance")) e->haltWhen(DIV_HALT_ROW);
80 ImGui::SameLine();
81 if (ImGui::Button("Pattern Advance")) e->haltWhen(DIV_HALT_PATTERN);
82
83 if (ImGui::Button("Play Command Stream")) nextWindow=GUI_WINDOW_CS_PLAYER;
84
85 if (ImGui::Button("Panic")) e->syncReset();
86 ImGui::SameLine();
87 if (ImGui::Button("Abort")) {
88 abort();
89 }
90 ImGui::TreePop();
91 }
92 if (ImGui::TreeNode("Breakpoint")) {
93 ImGui::InputInt("Order",&bpOrder);
94 ImGui::InputInt("Row",&bpRow);
95 ImGui::InputInt("Tick",&bpTick);
96 ImGui::Checkbox("Enable",&bpOn);
97 ImGui::TreePop();
98 }
99 if (ImGui::TreeNode("Chip Status")) {
100 ImGui::Text("for best results set latency to minimum or use the Frame Advance button.");
101 ImGui::Columns(e->song.systemLen);
102 for (int i=0; i<e->song.systemLen; i++) {
103 void* ch=e->getDispatch(i);
104 ImGui::TextColored(uiColors[GUI_COLOR_ACCENT_PRIMARY],"Chip %d: %s",i,getSystemName(e->song.system[i]));
105 if (e->song.system[i]==DIV_SYSTEM_NULL) {
106 ImGui::Text("NULL");
107 } else {
108 putDispatchChip(ch,e->song.system[i]);
109 }
110 ImGui::NextColumn();
111 }
112 ImGui::Columns();
113 ImGui::TreePop();
114 }
115 if (ImGui::TreeNode("Dispatch Status")) {
116 ImGui::Text("for best results set latency to minimum or use the Frame Advance button.");
117 ImGui::Columns(e->getTotalChannelCount());
118 for (int i=0; i<e->getTotalChannelCount(); i++) {
119 void* ch=e->getDispatchChanState(i);
120 ImGui::TextColored(uiColors[GUI_COLOR_ACCENT_PRIMARY],"Ch. %d: %d, %d",i,e->dispatchOfChan[i],e->dispatchChanOfChan[i]);
121 if (ch==NULL) {
122 ImGui::Text("NULL");
123 } else {
124 putDispatchChan(ch,e->dispatchChanOfChan[i],e->sysOfChan[i]);
125 }
126 ImGui::NextColumn();
127 }
128 ImGui::Columns();
129 ImGui::TreePop();
130 }
131 if (ImGui::TreeNode("Channel Status")) {
132 ImGui::Text("for best results set latency to minimum or use the Frame Advance button.");
133 ImGui::Columns(e->getTotalChannelCount());
134 for (int i=0; i<e->getTotalChannelCount(); i++) {
135 DivChannelState* ch=e->getChanState(i);
136 ImGui::TextColored(uiColors[GUI_COLOR_ACCENT_PRIMARY],"Channel %d:",i);
137 if (ch==NULL) {
138 ImGui::Text("NULL");
139 } else {
140 ImGui::Text("* General:");
141 ImGui::Text("- note = %d",ch->note);
142 ImGui::Text("- oldNote = %d",ch->oldNote);
143 ImGui::Text("- pitch = %d",ch->pitch);
144 ImGui::Text("- portaSpeed = %d",ch->portaSpeed);
145 ImGui::Text("- portaNote = %d",ch->portaNote);
146 ImGui::Text("- volume = %.4x",ch->volume);
147 ImGui::Text("- volSpeed = %d",ch->volSpeed);
148 ImGui::Text("- volSpeedTarget = %d",ch->volSpeedTarget);
149 ImGui::Text("- cut = %d",ch->cut);
150 ImGui::Text("- rowDelay = %d",ch->rowDelay);
151 ImGui::Text("- volMax = %.4x",ch->volMax);
152 ImGui::Text("- delayOrder = %d",ch->delayOrder);
153 ImGui::Text("- delayRow = %d",ch->delayRow);
154 ImGui::Text("- retrigSpeed = %d",ch->retrigSpeed);
155 ImGui::Text("- retrigTick = %d",ch->retrigTick);
156 ImGui::PushStyleColor(ImGuiCol_Text,(ch->vibratoDepth>0)?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_TEXT]);
157 ImGui::Text("* Vibrato:");
158 ImGui::Text("- depth = %d",ch->vibratoDepth);
159 ImGui::Text("- rate = %d",ch->vibratoRate);
160 ImGui::Text("- pos = %d",ch->vibratoPos);
161 ImGui::Text("- shape = %d",ch->vibratoShape);
162 ImGui::Text("- fine = %d",ch->vibratoFine);
163 ImGui::PopStyleColor();
164 ImGui::PushStyleColor(ImGuiCol_Text,(ch->tremoloDepth>0)?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_TEXT]);
165 ImGui::Text("* Tremolo:");
166 ImGui::Text("- depth = %d",ch->tremoloDepth);
167 ImGui::Text("- rate = %d",ch->tremoloRate);
168 ImGui::Text("- pos = %d",ch->tremoloPos);
169 ImGui::PopStyleColor();
170 ImGui::PushStyleColor(ImGuiCol_Text,(ch->arp>0)?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_TEXT]);
171 ImGui::Text("* Arpeggio:");
172 ImGui::Text("- arp = %.2X",ch->arp);
173 ImGui::Text("- stage = %d",ch->arpStage);
174 ImGui::Text("- ticks = %d",ch->arpTicks);
175 ImGui::PopStyleColor();
176 ImGui::Text("* Miscellaneous:");
177 ImGui::TextColored(ch->doNote?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> Do Note");
178 ImGui::TextColored(ch->legato?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> Legato");
179 ImGui::TextColored(ch->portaStop?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> PortaStop");
180 ImGui::TextColored(ch->keyOn?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> Key On");
181 ImGui::TextColored(ch->keyOff?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> Key Off");
182 ImGui::TextColored(ch->nowYouCanStop?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> NowYouCanStop");
183 ImGui::TextColored(ch->stopOnOff?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> Stop on Off");
184 ImGui::TextColored(ch->arpYield?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> Arp Yield");
185 ImGui::TextColored(ch->delayLocked?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> DelayLocked");
186 ImGui::TextColored(ch->inPorta?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> InPorta");
187 ImGui::TextColored(ch->scheduledSlideReset?uiColors[GUI_COLOR_MACRO_VOLUME]:uiColors[GUI_COLOR_HEADER],">> SchedSlide");
188 }
189 ImGui::NextColumn();
190 }
191 ImGui::Columns();
192 ImGui::TreePop();
193 }
194 if (ImGui::TreeNode("Playback Status")) {
195 String pdi=e->getPlaybackDebugInfo();
196 ImGui::TextWrapped("%s",pdi.c_str());
197 ImGui::TreePop();
198 }
199 if (ImGui::TreeNode("GUI Status")) {
200 ImGui::Text("patScroll: %f",patScroll);
201 ImGui::TreePop();
202 }
203 if (ImGui::TreeNode("Sample Debug")) {
204 for (int i=0; i<e->song.sampleLen; i++) {
205 DivSample* sample=e->getSample(i);
206 if (sample==NULL) {
207 ImGui::Text("%d: <NULL!>",i);
208 continue;
209 }
210 if (ImGui::TreeNode(fmt::sprintf("%d: %s",i,sample->name).c_str())) {
211 ImGui::Text("rate: %d",sample->rate);
212 ImGui::Text("centerRate: %d",sample->centerRate);
213 ImGui::Text("loopStart: %d",sample->loopStart);
214 ImGui::Text("loopEnd: %d", sample->loopEnd);
215 ImGui::Text(sample->loop?"loop: Enabled":"loop: Disabled");
216 if (sampleLoopModes[sample->loopMode]!=NULL) {
217 ImGui::Text("loopMode: %d (%s)",(unsigned char)sample->loopMode,sampleLoopModes[sample->loopMode]);
218 } else {
219 ImGui::Text("loopMode: %d (<NULL!>)",(unsigned char)sample->loopMode);
220 }
221
222 ImGui::Text("depth: %d",(unsigned char)sample->depth);
223 ImGui::Text("length8: %d",sample->length8);
224 ImGui::Text("length16: %d",sample->length16);
225 ImGui::Text("length1: %d",sample->length1);
226 ImGui::Text("lengthDPCM: %d",sample->lengthDPCM);
227 ImGui::Text("lengthZ: %d",sample->lengthZ);
228 ImGui::Text("lengthQSoundA: %d",sample->lengthQSoundA);
229 ImGui::Text("lengthA: %d",sample->lengthA);
230 ImGui::Text("lengthB: %d",sample->lengthB);
231 ImGui::Text("lengthBRR: %d",sample->lengthBRR);
232 ImGui::Text("lengthVOX: %d",sample->lengthVOX);
233
234 ImGui::Text("samples: %d",sample->samples);
235 ImGui::TreePop();
236 }
237 }
238 ImGui::TreePop();
239 }
240 if (ImGui::TreeNode("Oscilloscope Debug")) {
241 int c=0;
242 ImGui::Checkbox("FFT debug view",&debugFFT);
243 for (int i=0; i<e->song.systemLen; i++) {
244 DivSystem system=e->song.system[i];
245 if (e->getChannelCount(system)>0) {
246 if (ImGui::TreeNode(fmt::sprintf("%d: %s",i,e->getSystemName(system)).c_str())) {
247 if (ImGui::BeginTable("OscilloscopeTable",5,ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) {
248 ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
249 ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthFixed);
250 ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch);
251 ImGui::TableSetupColumn("c3",ImGuiTableColumnFlags_WidthStretch);
252 ImGui::TableSetupColumn("c4",ImGuiTableColumnFlags_WidthStretch);
253
254 ImGui::TableNextRow();
255 ImGui::TableNextColumn();
256 ImGui::Text("Channel");
257 ImGui::TableNextColumn();
258 ImGui::Text("Follow");
259 ImGui::TableNextColumn();
260 ImGui::Text("Needle");
261 ImGui::TableNextColumn();
262 ImGui::Text("Data");
263 ImGui::TableNextColumn();
264 ImGui::Text("I am so bored!");
265
266 for (int j=0; j<e->getChannelCount(system); j++, c++) {
267 DivDispatchOscBuffer* oscBuf=e->getOscBuffer(c);
268 if (oscBuf==NULL) {
269 ImGui::TableNextRow();
270 // channel
271 ImGui::TableNextColumn();
272 ImGui::Text("%d",j);
273 ImGui::TableNextColumn();
274 ImGui::Text("<NULL!>");
275 continue;
276 }
277 ImGui::TableNextRow();
278 // channel
279 ImGui::TableNextColumn();
280 ImGui::Text("%d",j);
281 // follow
282 ImGui::TableNextColumn();
283 ImGui::Checkbox(fmt::sprintf("##%d_OSCFollow_%d",i,c).c_str(),&oscBuf->follow);
284 // address
285 ImGui::TableNextColumn();
286 unsigned int needle=oscBuf->needle;
287 ImGui::Text("%.8x",needle);
288 // data
289 ImGui::TableNextColumn();
290 ImGui::Text("%d",oscBuf->data[needle>>16]);
291 // save
292 ImGui::TableNextColumn();
293 if (ImGui::Button(fmt::sprintf("Help me!##%d_OSCSaveDamnIt",j).c_str())) {
294 FILE* f=fopen("/tmp/oscbuf.bin","wb");
295 if (f==NULL) {
296 showError(fmt::sprintf("screw this bullshit! it FAILED! %s\nnow I am about to be consumed by the tsunami!\nCOME GET ME FAST, my location is [REDACTED] CQD SOS",strerror(errno)));
297 } else {
298 e->synchronized([f,oscBuf]() {
299 fwrite(oscBuf->data,sizeof(short),65536,f);
300 });
301 fclose(f);
302 showError(fmt::sprintf("DATA WRITTEN TO /tmp/oscbuf.bin\nthe needle was at %.8x during operation ((needle>>16)<<1 = %u for its actual position in the file).\n\nnow go inspect the file and find out who's biting on that stupid triangle before\nyou succumb to the tsunami, tildearrow is stabbed by Codename Redacted and the Furnace factory comes to a\nperennial halt. HURRY UP!!!",needle,needle>>16));
303 }
304 }
305 }
306 ImGui::EndTable();
307 }
308 ImGui::TreePop();
309 }
310 } else {
311 ImGui::Text("%d: <NULL!>",i);
312 continue;
313 }
314 }
315 ImGui::TreePop();
316 }
317 if (ImGui::TreeNode("Touch Point Information")) {
318 ImGui::Text("active:");
319 ImGui::Indent();
320 for (TouchPoint& i: activePoints) {
321 ImGui::Text("- %d: %.1f, %.1f (%.2f)",i.id,i.x,i.y,i.x);
322 }
323 ImGui::Unindent();
324 ImGui::Text("pressed:");
325 ImGui::Indent();
326 for (TouchPoint& i: pressedPoints) {
327 ImGui::Text("- %d: %.1f, %.1f (%.2f)",i.id,i.x,i.y,i.x);
328 }
329 ImGui::Unindent();
330 ImGui::Text("released:");
331 ImGui::Indent();
332 for (TouchPoint& i: releasedPoints) {
333 ImGui::Text("- %d: %.1f, %.1f (%.2f)",i.id,i.x,i.y,i.x);
334 }
335 ImGui::Unindent();
336 ImGui::TreePop();
337 }
338 if (ImGui::TreeNode("File Selection Test")) {
339 if (ImGui::Button("Test Open")) {
340 openFileDialog(GUI_FILE_TEST_OPEN);
341 }
342 ImGui::SameLine();
343 if (ImGui::Button("Test Open Multi")) {
344 openFileDialog(GUI_FILE_TEST_OPEN_MULTI);
345 }
346 ImGui::SameLine();
347 if (ImGui::Button("Test Save")) {
348 openFileDialog(GUI_FILE_TEST_SAVE);
349 }
350 ImGui::TreePop();
351 }
352 if (ImGui::TreeNode("Do Action")) {
353 char bindID[1024];
354 for (int j=0; j<GUI_ACTION_MAX; j++) {
355 if (strcmp(guiActions[j].friendlyName,"")==0) continue;
356 if (strstr(guiActions[j].friendlyName,"---")==guiActions[j].friendlyName) {
357 ImGui::TextUnformatted(guiActions[j].friendlyName);
358 } else {
359 snprintf(bindID,1024,"%s##DO_%d",guiActions[j].friendlyName,j);
360 if (ImGui::Button(bindID)) {
361 doAction(j);
362 }
363 }
364 }
365 ImGui::TreePop();
366 }
367 if (ImGui::TreeNode("Scroll Text Test")) {
368 ImGui::ScrollText(ImGui::GetID("scrolltest1"),"Lorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?",ImGui::GetCursorPos());
369 ImGui::ScrollText(ImGui::GetID("scrolltest2"),"quis autem vel eum iure reprehenderit",ImGui::GetCursorPos());
370 ImGui::ScrollText(ImGui::GetID("scrolltest3"),"qui in ea voluptate velit esse",ImGui::GetCursorPos(),ImVec2(100.0f*dpiScale,0),true);
371 ImGui::ScrollText(ImGui::GetID("scrolltest4"),"quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?",ImGui::GetCursorPos(),ImVec2(0,0),true);
372 ImGui::TreePop();
373 }
374 if (ImGui::TreeNode("Pitch Table Calculator")) {
375 ImGui::InputDouble("Clock",&ptcClock);
376 ImGui::InputDouble("Divider/FreqBase",&ptcDivider);
377 ImGui::InputInt("Octave",&ptcOctave);
378 if (ImGui::RadioButton("Frequency",ptcMode==0)) ptcMode=0;
379 ImGui::SameLine();
380 if (ImGui::RadioButton("Period",ptcMode==1)) ptcMode=1;
381 ImGui::SameLine();
382 if (ImGui::RadioButton("FreqNum/Block",ptcMode==2)) ptcMode=2;
383
384 if (ptcMode==2) {
385 if (ImGui::InputInt("FreqNum Bits",&ptcBlockBits)) {
386 if (ptcBlockBits<0) ptcBlockBits=0;
387 if (ptcBlockBits>13) ptcBlockBits=13;
388 }
389 }
390
391 if (ImGui::BeginTable("PitchTable",7)) {
392 ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
393 ImGui::TableNextColumn();
394 ImGui::Text("Note");
395 ImGui::TableNextColumn();
396 ImGui::Text("Pitch");
397
398 ImGui::TableNextColumn();
399 ImGui::Text("Base");
400 ImGui::TableNextColumn();
401 ImGui::Text("Hex");
402
403 ImGui::TableNextColumn();
404 ImGui::Text("Final");
405
406 ImGui::TableNextColumn();
407 ImGui::Text("Hex");
408
409 ImGui::TableNextColumn();
410 ImGui::Text("Delta");
411
412 int lastFinal=0;
413 for (int i=0; i<12; i++) {
414 int note=(12*ptcOctave)+i;
415 int pitch=0;
416
417 int base=e->calcBaseFreq(ptcClock,ptcDivider,note,ptcMode==1);
418 int final=e->calcFreq(base,pitch,ptcMode==1,0,0,ptcClock,ptcDivider,(ptcMode==2)?ptcBlockBits:0);
419
420 ImGui::TableNextRow();
421 ImGui::TableNextColumn();
422 ImGui::Text("%d",note);
423 ImGui::TableNextColumn();
424 ImGui::Text("%d",pitch);
425
426 ImGui::TableNextColumn();
427 ImGui::Text("%d",base);
428 ImGui::TableNextColumn();
429 ImGui::Text("%x",base);
430
431 ImGui::TableNextColumn();
432 ImGui::Text("%d",final);
433 ImGui::TableNextColumn();
434 ImGui::Text("%x",final);
435
436 ImGui::TableNextColumn();
437 ImGui::Text("%d",final-lastFinal);
438
439 lastFinal=final;
440 }
441
442 ImGui::EndTable();
443 }
444 ImGui::TreePop();
445 }
446 if (ImGui::TreeNodeEx("Window Debug",ImGuiTreeNodeFlags_DefaultOpen)) {
447 ImGui::Text("Screen: %dx%d+%d+%d",scrW,scrH,scrX,scrY);
448 ImGui::Text("Screen (Conf): %dx%d+%d+%d",scrConfW,scrConfH,scrConfX,scrConfY);
449 ImGui::Text("Canvas: %dx%d",canvasW,canvasH);
450 ImGui::Text("Maximized: %d",scrMax);
451 ImGui::Text("System Managed Scale: %d",sysManagedScale);
452 ImGui::TreePop();
453 }
454 if (ImGui::TreeNode("Audio Debug")) {
455 TAAudioDesc& audioWant=e->getAudioDescWant();
456 TAAudioDesc& audioGot=e->getAudioDescGot();
457
458 ImGui::Text("want:");
459 ImGui::Text("- name: %s",audioWant.name.c_str());
460 ImGui::Text("- device name: %s",audioWant.deviceName.c_str());
461 ImGui::Text("- rate: %f",audioWant.rate);
462 ImGui::Text("- buffer size: %d",audioWant.bufsize);
463 ImGui::Text("- fragments: %d",audioWant.fragments);
464 ImGui::Text("- inputs: %d",audioWant.inChans);
465 ImGui::Text("- outputs: %d",audioWant.outChans);
466 ImGui::Text("- format: %d",audioWant.outFormat);
467
468 ImGui::Text("got:");
469 ImGui::Text("- name: %s",audioGot.name.c_str());
470 ImGui::Text("- device name: %s",audioGot.deviceName.c_str());
471 ImGui::Text("- rate: %f",audioGot.rate);
472 ImGui::Text("- buffer size: %d",audioGot.bufsize);
473 ImGui::Text("- fragments: %d",audioGot.fragments);
474 ImGui::Text("- inputs: %d",audioGot.inChans);
475 ImGui::Text("- outputs: %d",audioGot.outChans);
476 ImGui::Text("- format: %d",audioGot.outFormat);
477
478 ImGui::Text("last call to nextBuf(): in %d, out %d, size %d",e->lastNBIns,e->lastNBOuts,e->lastNBSize);
479
480 ImGui::TreePop();
481 }
482 if (ImGui::TreeNode("MIDI Debug")) {
483 if (ImGui::Button("Enable Debug (go to log viewer)")) {
484 e->setMidiDebug(true);
485 nextWindow=GUI_WINDOW_LOG;
486 }
487 ImGui::TreePop();
488 }
489 if (ImGui::TreeNode("Visualizer Debug")) {
490 if (ImGui::BeginTable("visX",3,ImGuiTableFlags_Borders)) {
491 ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
492 ImGui::TableNextColumn();
493 ImGui::Text("channel");
494 ImGui::TableNextColumn();
495 ImGui::Text("patChanX");
496 ImGui::TableNextColumn();
497 ImGui::Text("patChanSlideY");
498
499 for (int i=0; i<e->getTotalChannelCount(); i++) {
500 ImGui::TableNextRow();
501 ImGui::TableNextColumn();
502 ImGui::Text("%d",i);
503 ImGui::TableNextColumn();
504 ImGui::Text("%f",patChanX[i]);
505 ImGui::TableNextColumn();
506 ImGui::Text("%f",patChanSlideY[i]);
507 }
508
509 ImGui::EndTable();
510 }
511
512 ImGui::Text("particle count: %d",(int)particles.size());
513
514 ImGui::TreePop();
515 }
516 if (ImGui::TreeNode("Playground")) {
517 if (pgSys<0 || pgSys>=e->song.systemLen) pgSys=0;
518 if (ImGui::BeginCombo("Chip",fmt::sprintf("%d. %s",pgSys+1,e->getSystemName(e->song.system[pgSys])).c_str())) {
519 for (int i=0; i<e->song.systemLen; i++) {
520 if (ImGui::Selectable(fmt::sprintf("%d. %s",i+1,e->getSystemName(e->song.system[i])).c_str())) {
521 pgSys=i;
522 break;
523 }
524 }
525 ImGui::EndCombo();
526 }
527 ImGui::Text("Program");
528 if (pgProgram.empty()) {
529 ImGui::Text("-nothing here-");
530 } else {
531 char id[32];
532 for (size_t index=0; index<pgProgram.size(); index++) {
533 DivRegWrite& i=pgProgram[index];
534 snprintf(id,31,"pgw%d",(int)index);
535 ImGui::PushID(id);
536 ImGui::SetNextItemWidth(100.0f*dpiScale);
537 ImGui::InputScalar("##PAddress",ImGuiDataType_U32,&i.addr,NULL,NULL,"%.2X",ImGuiInputTextFlags_CharsHexadecimal);
538 ImGui::SameLine();
539 ImGui::Text("=");
540 ImGui::SameLine();
541 ImGui::SetNextItemWidth(100.0f*dpiScale);
542 ImGui::InputScalar("##PValue",ImGuiDataType_U16,&i.val,NULL,NULL,"%.2X",ImGuiInputTextFlags_CharsHexadecimal);
543 ImGui::SameLine();
544 if (ImGui::Button(ICON_FA_TIMES "##PRemove")) {
545 pgProgram.erase(pgProgram.begin()+index);
546 index--;
547 }
548 ImGui::PopID();
549 }
550 }
551 if (ImGui::Button("Execute")) {
552 e->poke(pgSys,pgProgram);
553 }
554 ImGui::SameLine();
555 if (ImGui::Button("Clear")) {
556 pgProgram.clear();
557 }
558
559 ImGui::AlignTextToFramePadding();
560 ImGui::Text("Address");
561 ImGui::SameLine();
562 ImGui::SetNextItemWidth(100.0f*dpiScale);
563 ImGui::InputInt("##PAddress",&pgAddr,0,0,ImGuiInputTextFlags_CharsHexadecimal);
564 ImGui::SameLine();
565 ImGui::Text("Value");
566 ImGui::SameLine();
567 ImGui::SetNextItemWidth(100.0f*dpiScale);
568 ImGui::InputInt("##PValue",&pgVal,0,0,ImGuiInputTextFlags_CharsHexadecimal);
569 ImGui::SameLine();
570 if (ImGui::Button("Write")) {
571 e->poke(pgSys,pgAddr,pgVal);
572 }
573 ImGui::SameLine();
574 if (ImGui::Button("Add")) {
575 pgProgram.push_back(DivRegWrite(pgAddr,pgVal));
576 }
577 if (ImGui::TreeNode("Register Cheatsheet")) {
578 const char** sheet=e->getRegisterSheet(pgSys);
579 if (sheet==NULL) {
580 ImGui::Text("no cheatsheet available for this chip.");
581 } else {
582 if (ImGui::BeginTable("RegisterSheet",2,ImGuiTableFlags_SizingFixedSame)) {
583 ImGui::TableNextRow();
584 ImGui::TableNextColumn();
585 ImGui::Text("Name");
586 ImGui::TableNextColumn();
587 ImGui::Text("Address");
588 for (int i=0; sheet[i]!=NULL; i+=2) {
589 ImGui::TableNextRow();
590 ImGui::TableNextColumn();
591 ImGui::Text("%s",sheet[i]);
592 ImGui::TableNextColumn();
593 ImGui::Text("$%s",sheet[i+1]);
594 }
595 ImGui::EndTable();
596 }
597 }
598 ImGui::TreePop();
599 }
600 ImGui::TreePop();
601 }
602 if (ImGui::TreeNode("ADSR Test Area")) {
603 static int tl, ar, dr, d2r, sl, rr, sus, egt, algOrGlobalSus, instType;
604 static float maxArDr, maxTl, maxRr;
605 ImGui::Text("This window was done out of frustration");
606 drawFMEnv(tl,ar,dr,d2r,rr,sl,sus,egt,algOrGlobalSus,maxTl,maxArDr,maxRr,ImVec2(200.0f*dpiScale,100.0f*dpiScale),instType);
607
608 ImGui::InputInt("tl",&tl);
609 ImGui::InputInt("ar",&ar);
610 ImGui::InputInt("dr",&dr);
611 ImGui::InputInt("d2r",&d2r);
612 ImGui::InputInt("sl",&sl);
613 ImGui::InputInt("rr",&rr);
614 ImGui::InputInt("sus",&sus);
615 ImGui::InputInt("egt",&egt);
616 ImGui::InputInt("algOrGlobalSus",&algOrGlobalSus);
617 ImGui::InputInt("instType",&instType);
618 ImGui::InputFloat("maxArDr",&maxArDr);
619 ImGui::InputFloat("maxTl",&maxTl);
620 ImGui::InputFloat("maxRr",&maxRr);
621 ImGui::TreePop();
622 }
623 if (ImGui::TreeNode("FM Preview")) {
624 float asFloat[FM_PREVIEW_SIZE];
625 for (int i=0; i<FM_PREVIEW_SIZE; i++) {
626 asFloat[i]=(float)fmPreview[i]/8192.0f;
627 }
628 ImGui::PlotLines("##DebugFMPreview",asFloat,FM_PREVIEW_SIZE,0,"Preview",-1.0,1.0,ImVec2(300.0f*dpiScale,150.0f*dpiScale));
629 ImGui::TreePop();
630 }
631 if (ImGui::TreeNode("Recent Files")) {
632 ImGui::Text("Items: %d - Max: %d",(int)recentFile.size(),settings.maxRecentFile);
633 ImGui::Text("readPos: %d - writePos: %d",(int)recentFile.readPos,(int)recentFile.writePos);
634 ImGui::Indent();
635 for (size_t i=0; i<recentFile.size(); i++) {
636 ImGui::Text("%d: %s",(int)i,recentFile[i].c_str());
637 }
638 ImGui::Unindent();
639 ImGui::TreePop();
640 }
641 if (ImGui::TreeNode("Texture Test")) {
642 ImGui::Text("Create and Destroy 128 Textures");
643 if (ImGui::Button("No Write")) {
644 for (int i=0; i<128; i++) {
645 FurnaceGUITexture* t=rend->createTexture(false,2048,2048,true,bestTexFormat);
646 if (t==NULL) {
647 showError(fmt::sprintf("Failure! %d",i));
648 break;
649 }
650 rend->destroyTexture(t);
651 }
652 }
653 if (ImGui::Button("Write (update)")) {
654 unsigned char* data=new unsigned char[2048*2048*4];
655 for (int i=0; i<2048*2048*4; i++) {
656 data[i]=rand();
657 }
658 for (int i=0; i<128; i++) {
659 FurnaceGUITexture* t=rend->createTexture(false,2048,2048,true,bestTexFormat);
660 if (t==NULL) {
661 showError(fmt::sprintf("Failure! %d",i));
662 break;
663 }
664 rend->updateTexture(t,data,2048*4);
665 rend->destroyTexture(t);
666 }
667 delete[] data;
668 }
669 if (ImGui::Button("Write (lock)")) {
670 unsigned char* data=NULL;
671 int pitch=0;
672 for (int i=0; i<128; i++) {
673 FurnaceGUITexture* t=rend->createTexture(false,2048,2048,true,bestTexFormat);
674 if (t==NULL) {
675 showError(fmt::sprintf("Failure! %d",i));
676 break;
677 }
678 if (rend->lockTexture(t,(void**)&data,&pitch)) {
679 for (int i=0; i<2048*2048*4; i++) {
680 data[i]=rand();
681 }
682 rend->unlockTexture(t);
683 }
684 rend->destroyTexture(t);
685 }
686 }
687 ImGui::TreePop();
688 }
689 if (ImGui::TreeNode("Locale Test")) {
690 ImGui::TextUnformatted(_("This is a language test."));
691 ImGui::TextUnformatted(_("This is another language test."));
692 ImGui::TreePop();
693 }
694 if (ImGui::TreeNode("Osc Render Test")) {
695 ImGui::InputInt("Length",&oscDebugLen);
696 ImGui::InputInt("Height",&oscDebugHeight);
697 ImGui::InputFloat("Line Size",&oscDebugLineSize);
698 ImGui::InputFloat("Min",&oscDebugMin);
699 ImGui::InputFloat("Max",&oscDebugMax);
700 ImGui::InputFloat("Power",&oscDebugPower);
701 ImGui::InputInt("Repeat",&oscDebugRepeat);
702
703 if (oscDebugLen<1) oscDebugLen=1;
704 if (oscDebugLen>2048) oscDebugLen=2048;
705
706 if (oscDebugHeight<1) oscDebugHeight=1;
707 if (oscDebugHeight>2048) oscDebugHeight=2048;
708
709 memset(oscDebugData,0,2048*sizeof(float));
710 for (int i=0; i<oscDebugLen; i++) {
711 oscDebugData[i]=oscDebugMin+(oscDebugMax-oscDebugMin)*pow((float)((i*oscDebugRepeat)%oscDebugLen)/(float)oscDebugLen,oscDebugPower);
712 }
713
714 if (rend->supportsDrawOsc()) {
715 ImDrawList* dl=ImGui::GetWindowDrawList();
716 ImGuiWindow* window=ImGui::GetCurrentWindow();
717
718 ImVec2 size=ImVec2(oscDebugLen,oscDebugHeight);
719 ImVec2 minArea=window->DC.CursorPos;
720 ImVec2 maxArea=ImVec2(
721 minArea.x+size.x,
722 minArea.y+size.y
723 );
724 ImRect rect=ImRect(minArea,maxArea);
725 ImGuiStyle& style=ImGui::GetStyle();
726 ImGui::ItemSize(size,style.FramePadding.y);
727 if (ImGui::ItemAdd(rect,ImGui::GetID("debugOsc"))) {
728 _debugDo.gui=this;
729 _debugDo.data=oscDebugData;
730 _debugDo.len=oscDebugLen;
731 _debugDo.pos0=rect.Min;
732 _debugDo.pos1=rect.Max;
733 _debugDo.color=ImVec4(1.0,1.0,1.0,1.0);
734 _debugDo.lineSize=dpiScale*oscDebugLineSize;
735
736 dl->AddCallback(_drawOsc,&_debugDo);
737 dl->AddCallback(ImDrawCallback_ResetRenderState,NULL);
738 }
739 } else {
740 ImGui::Text("Render Backend does not support osc rendering.");
741 }
742 ImGui::TreePop();
743 }
744 #ifdef HAVE_LOCALE
745 if (ImGui::TreeNode("Plural Form Test")) {
746 ImGui::InputInt("Number",&numApples);
747 ImGui::Text(ngettext("%d apple","%d apples",numApples),numApples);
748 ImGui::TreePop();
749 }
750 #endif
751 if (ImGui::TreeNode("Get Gain Test")) {
752 float realVol=e->getGain(getGainChan,getGainVol);
753 ImGui::InputInt("Chan",&getGainChan);
754 ImGui::InputInt("Vol",&getGainVol);
755 ImGui::Text("result: %.0f%%",realVol*100.0f);
756 ImGui::TreePop();
757 }
758 if (ImGui::TreeNode("Cursor Undo Debug")) {
759 auto DrawSpot=[&](const CursorJumpPoint& spot) {
760 ImGui::Text("[%d:%d] <%d:%d, %d>", spot.subSong, spot.order, spot.point.xCoarse, spot.point.xFine, spot.point.y);
761 };
762 if (ImGui::BeginChild("##CursorUndoDebugChild", ImVec2(0, 300), ImGuiChildFlags_Border)) {
763 if (ImGui::BeginTable("##CursorUndoDebug", 2, ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) {
764 for (size_t row=0; row<MAX(cursorUndoHist.size(),cursorRedoHist.size()); ++row) {
765 ImGui::TableNextRow();
766 ImGui::TableNextColumn();
767 if (row<cursorUndoHist.size()) DrawSpot(cursorUndoHist[cursorUndoHist.size()-row-1]);
768 ImGui::TableNextColumn();
769 if (row<cursorRedoHist.size()) DrawSpot(cursorRedoHist[cursorRedoHist.size()-row-1]);
770 }
771 ImGui::EndTable();
772 }
773 }
774 ImGui::EndChild();
775 ImGui::TreePop();
776 }
777 if (ImGui::TreeNode("User Interface")) {
778 if (ImGui::Button("Inspect")) {
779 inspectorOpen=!inspectorOpen;
780 }
781 if (ImGui::Button("Spoiler")) {
782 spoilerOpen=!spoilerOpen;
783 }
784 if (ImGui::Button("Kill Graphics")) {
785 killGraphics=true;
786 }
787 ImGui::TreePop();
788 }
789 if (ImGui::TreeNode("Performance")) {
790 double perfFreq=SDL_GetPerformanceFrequency()/1000000.0;
791 int lastProcTime=(int)e->processTime/1000;
792 TAAudioDesc& audioGot=e->getAudioDescGot();
793
794 ImGui::Text("video frame: %.0fµs",ImGui::GetIO().DeltaTime*1000000.0);
795 ImGui::Text("audio frame: %.0fµs",1000000.0*(double)audioGot.bufsize/(double)audioGot.rate);
796 ImGui::Separator();
797
798 ImGui::Text("audio: %dµs",lastProcTime);
799 ImGui::Text("render: %.0fµs",(double)renderTimeDelta/perfFreq);
800 ImGui::Text("draw: %.0fµs",(double)drawTimeDelta/perfFreq);
801 ImGui::Text("swap: %.0fµs",(double)swapTimeDelta/perfFreq);
802 ImGui::Text("layout: %.0fµs",(double)layoutTimeDelta/perfFreq);
803 ImGui::Text("event: %.0fµs",(double)eventTimeDelta/perfFreq);
804 ImGui::Separator();
805
806 ImGui::Text("details:");
807 for (int i=0; i<perfMetricsLastLen; i++) {
808 ImGui::Text("%s: %.0fµs",perfMetricsLast[i].name,(double)perfMetricsLast[i].elapsed/perfFreq);
809 }
810 ImGui::TreePop();
811 }
812 if (ImGui::TreeNode("Settings")) {
813 if (ImGui::Button("Sync")) syncSettings();
814 ImGui::SameLine();
815 if (ImGui::Button("Commit")) willCommit=true;
816 ImGui::SameLine();
817 if (ImGui::Button("Force Load")) e->loadConf();
818 ImGui::SameLine();
819 if (ImGui::Button("Force Save")) e->saveConf();
820 ImGui::TreePop();
821 }
822 ImGui::Text("Song format version %d",e->song.version);
823 ImGui::Text("Furnace version " DIV_VERSION " (%d)",DIV_ENGINE_VERSION);
824 }
825 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_DEBUG;
826 ImGui::End();
827 }