Debian Codegraph @

src/gui/pattern.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 // for suck's fake Clang extension!
21 #define _USE_MATH_DEFINES
22 #include "gui.h"
23 #include "../ta-log.h"
24 #include "imgui_internal.h"
25 #include "IconsFontAwesome4.h"
26 #include "furIcons.h"
27 #include "misc/cpp/imgui_stdlib.h"
28 #include "guiConst.h"
29 #include "../utfutils.h"
30 #include <fmt/printf.h>
31
32 struct DelayedLabel {
33 float posCenter, posY;
34 ImVec2 textSize;
35 const char* label;
36 DelayedLabel(float pc, float py, ImVec2 ts, const char* l):
37 posCenter(pc),
38 posY(py),
39 textSize(ts),
40 label(l) {}
41 };
42
43 inline float randRange(float min, float max) {
44 return min+((float)rand()/(float)RAND_MAX)*(max-min);
45 }
46
47 void _pushPartBlend(const ImDrawList* drawList, const ImDrawCmd* cmd) {
48 if (cmd!=NULL) {
49 if (cmd->UserCallbackData!=NULL) {
50 ((FurnaceGUI*)cmd->UserCallbackData)->pushPartBlend();
51 }
52 }
53 }
54
55 void _popPartBlend(const ImDrawList* drawList, const ImDrawCmd* cmd) {
56 if (cmd!=NULL) {
57 if (cmd->UserCallbackData!=NULL) {
58 ((FurnaceGUI*)cmd->UserCallbackData)->popPartBlend();
59 }
60 }
61 }
62
63 void FurnaceGUI::pushPartBlend() {
64 rend->setBlendMode(GUI_BLEND_MODE_ADD);
65 }
66
67 void FurnaceGUI::popPartBlend() {
68 rend->setBlendMode(GUI_BLEND_MODE_BLEND);
69 }
70
71 // draw a pattern row
72 inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord, const DivPattern** patCache, bool inhibitSel) {
73 static char id[64];
74 bool selectedRow=(
75 !inhibitSel &&
76 (ord>sel1.order || (ord==sel1.order && i>=sel1.y)) &&
77 (ord<sel2.order || (ord==sel2.order && i<=sel2.y))
78 );
79 ImGui::TableNextRow(0,lineHeight);
80 ImGui::TableNextColumn();
81 float cursorPosY=ImGui::GetCursorPos().y-ImGui::GetScrollY();
82 // store playhead position on the screen
83 if (ord==playOrder && oldRow==i) {
84 playheadY=ImGui::GetCursorScreenPos().y;
85 }
86 // check if the row is visible
87 if (cursorPosY<-lineHeight || cursorPosY>ImGui::GetWindowSize().y) {
88 return;
89 }
90 // check if we are in range
91 if (ord<0 || ord>=e->curSubSong->ordersLen) {
92 return;
93 }
94 if (i<0 || i>=e->curSubSong->patLen) {
95 return;
96 }
97 // set the top-most and bottom-most Y positions
98 if (topMostOrder==-1) {
99 topMostOrder=ord;
100 }
101 if (topMostRow==-1) {
102 topMostRow=i;
103 }
104 bottomMostOrder=ord;
105 bottomMostRow=i;
106 // stuff
107 bool isPushing=false;
108 ImVec4 activeColor=uiColors[GUI_COLOR_PATTERN_ACTIVE];
109 ImVec4 inactiveColor=uiColors[GUI_COLOR_PATTERN_INACTIVE];
110 ImVec4 rowIndexColor=uiColors[GUI_COLOR_PATTERN_ROW_INDEX];
111 if (e->curSubSong->hilightB>0 && !(i%e->curSubSong->hilightB)) {
112 activeColor=uiColors[GUI_COLOR_PATTERN_ACTIVE_HI2];
113 inactiveColor=uiColors[GUI_COLOR_PATTERN_INACTIVE_HI2];
114 rowIndexColor=uiColors[GUI_COLOR_PATTERN_ROW_INDEX_HI2];
115 } else if (e->curSubSong->hilightA>0 && !(i%e->curSubSong->hilightA)) {
116 activeColor=uiColors[GUI_COLOR_PATTERN_ACTIVE_HI1];
117 inactiveColor=uiColors[GUI_COLOR_PATTERN_INACTIVE_HI1];
118 rowIndexColor=uiColors[GUI_COLOR_PATTERN_ROW_INDEX_HI1];
119 }
120 // check overflow highlight
121 if (settings.overflowHighlight) {
122 if (edit && cursor.y==i && cursor.order==ord && curWindowLast==GUI_WINDOW_PATTERN) {
123 if (editClone && !isPatUnique && secondTimer<0.5) {
124 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING_CLONE]));
125 } else {
126 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING]));
127 }
128 } else if (isPlaying && oldRow==i && ord==playOrder) {
129 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PLAY_HEAD]));
130 } else if (e->curSubSong->hilightB>0 && !(i%e->curSubSong->hilightB)) {
131 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_2]));
132 } else if (e->curSubSong->hilightA>0 && !(i%e->curSubSong->hilightA)) {
133 ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_1]));
134 }
135 } else {
136 isPushing=true;
137 if (edit && cursor.y==i && cursor.order==ord && curWindowLast==GUI_WINDOW_PATTERN) {
138 if (editClone && !isPatUnique && secondTimer<0.5) {
139 ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING_CLONE]));
140 } else {
141 ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING]));
142 }
143 } else if (isPlaying && oldRow==i && ord==playOrder) {
144 ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PLAY_HEAD]));
145 } else if (e->curSubSong->hilightB>0 && !(i%e->curSubSong->hilightB)) {
146 ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_2]));
147 } else if (e->curSubSong->hilightA>0 && !(i%e->curSubSong->hilightA)) {
148 ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_1]));
149 } else {
150 isPushing=false;
151 }
152 }
153 // row number
154 ImGui::PushStyleColor(ImGuiCol_Text,rowIndexColor);
155
156 if (settings.patRowsBase==1) {
157 snprintf(id,63," %.2X ###PR_%d",i,i);
158 } else {
159 snprintf(id,63,"%3d ###PR_%d",i,i);
160 }
161 ImGui::Selectable(id,false,ImGuiSelectableFlags_NoPadWithHalfSpacing,fourChars);
162 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
163 updateSelection(0,0,i,ord,true);
164 }
165 if (ImGui::IsItemClicked()) {
166 startSelection(0,0,i,ord,true);
167 }
168 if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
169 ImGui::InhibitInertialScroll();
170 NOTIFY_LONG_HOLD;
171 mobilePatSel=true;
172 }
173 ImGui::PopStyleColor();
174 // for each column
175 int mustSetXOf=0;
176 for (int j=0; j<chans; j++) {
177 // check if channel is not hidden
178 if (!e->curSubSong->chanShow[j]) {
179 continue;
180 }
181 int chanVolMax=e->getMaxVolumeChan(j);
182 if (chanVolMax<1) chanVolMax=1;
183 const DivPattern* pat=patCache[j];
184 if (!ImGui::TableNextColumn()) {
185 continue;
186 }
187 for (int k=mustSetXOf; k<=j; k++) {
188 patChanX[k]=ImGui::GetCursorScreenPos().x;
189 }
190 mustSetXOf=j+1;
191
192 // selection highlight flags
193 int sel1XSum=sel1.xCoarse*32+sel1.xFine;
194 int sel2XSum=sel2.xCoarse*32+sel2.xFine;
195 int j32=j*32;
196 bool selectedNote=selectedRow && (j32>=sel1XSum && j32<=sel2XSum);
197 bool selectedIns=selectedRow && (j32+1>=sel1XSum && j32+1<=sel2XSum);
198 bool selectedVol=selectedRow && (j32+2>=sel1XSum && j32+2<=sel2XSum);
199 bool cursorNote=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==0 && curWindowLast==GUI_WINDOW_PATTERN);
200 bool cursorIns=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==1 && curWindowLast==GUI_WINDOW_PATTERN);
201 bool cursorVol=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==2 && curWindowLast==GUI_WINDOW_PATTERN);
202
203 // note
204 snprintf(id,63,"%.31s###PN_%d_%d",noteName(pat->data[i][0],pat->data[i][1]),i,j);
205 if (pat->data[i][0]==0 && pat->data[i][1]==0) {
206 ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
207 } else {
208 ImGui::PushStyleColor(ImGuiCol_Text,activeColor);
209 }
210 if (cursorNote) {
211 ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
212 ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
213 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
214 ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,noteCellSize);
215 ImGui::PopStyleColor(3);
216 } else {
217 if (selectedNote) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
218 ImGui::Selectable(id,isPushing || selectedNote,ImGuiSelectableFlags_NoPadWithHalfSpacing,noteCellSize);
219 if (selectedNote) ImGui::PopStyleColor();
220 }
221 if (ImGui::IsItemClicked()) {
222 startSelection(j,0,i,ord);
223 }
224 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
225 updateSelection(j,0,i,ord);
226 }
227 if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
228 ImGui::InhibitInertialScroll();
229 NOTIFY_LONG_HOLD;
230 mobilePatSel=true;
231 }
232 ImGui::PopStyleColor();
233
234 // the following is only visible when the channel is not collapsed
235 if (e->curSubSong->chanCollapse[j]<3) {
236 // instrument
237 if (pat->data[i][2]==-1) {
238 ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
239 snprintf(id,63,"%.31s###PI_%d_%d",emptyLabel2,i,j);
240 } else {
241 if (pat->data[i][2]<0 || pat->data[i][2]>=e->song.insLen) {
242 ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS_ERROR]);
243 } else {
244 DivInstrumentType t=e->song.ins[pat->data[i][2]]->type;
245 if (t!=DIV_INS_AMIGA && t!=e->getPreferInsType(j)) {
246 ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS_WARN]);
247 } else {
248 ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS]);
249 }
250 }
251 snprintf(id,63,"%.2X###PI_%d_%d",pat->data[i][2],i,j);
252 }
253 ImGui::SameLine(0.0f,0.0f);
254 if (cursorIns) {
255 ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
256 ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
257 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
258 ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,insCellSize);
259 ImGui::PopStyleColor(3);
260 } else {
261 if (selectedIns) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
262 ImGui::Selectable(id,isPushing || selectedIns,ImGuiSelectableFlags_NoPadWithHalfSpacing,insCellSize);
263 if (selectedIns) ImGui::PopStyleColor();
264 }
265 if (ImGui::IsItemClicked()) {
266 startSelection(j,1,i,ord);
267 }
268 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
269 updateSelection(j,1,i,ord);
270 }
271 if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
272 ImGui::InhibitInertialScroll();
273 NOTIFY_LONG_HOLD;
274 mobilePatSel=true;
275 }
276 ImGui::PopStyleColor();
277 }
278
279 if (e->curSubSong->chanCollapse[j]<2) {
280 // volume
281 if (pat->data[i][3]==-1) {
282 snprintf(id,63,"%.31s###PV_%d_%d",emptyLabel2,i,j);
283 ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
284 } else {
285 int volColor=(pat->data[i][3]*127)/chanVolMax;
286 if (volColor>127) volColor=127;
287 if (volColor<0) volColor=0;
288 snprintf(id,63,"%.2X###PV_%d_%d",pat->data[i][3],i,j);
289 ImGui::PushStyleColor(ImGuiCol_Text,volColors[volColor]);
290 }
291 ImGui::SameLine(0.0f,0.0f);
292 if (cursorVol) {
293 ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
294 ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
295 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
296 ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,volCellSize);
297 ImGui::PopStyleColor(3);
298 } else {
299 if (selectedVol) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
300 ImGui::Selectable(id,isPushing || selectedVol,ImGuiSelectableFlags_NoPadWithHalfSpacing,volCellSize);
301 if (selectedVol) ImGui::PopStyleColor();
302 }
303 if (ImGui::IsItemClicked()) {
304 startSelection(j,2,i,ord);
305 }
306 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
307 updateSelection(j,2,i,ord);
308 }
309 if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
310 ImGui::InhibitInertialScroll();
311 NOTIFY_LONG_HOLD;
312 mobilePatSel=true;
313 }
314 ImGui::PopStyleColor();
315 }
316
317 if (e->curSubSong->chanCollapse[j]<1) {
318 // effects
319 for (int k=0; k<e->curPat[j].effectCols; k++) {
320 int index=4+(k<<1);
321 bool selectedEffect=selectedRow && (j32+index-1>=sel1XSum && j32+index-1<=sel2XSum);
322 bool selectedEffectVal=selectedRow && (j32+index>=sel1XSum && j32+index<=sel2XSum);
323 bool cursorEffect=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==index-1 && curWindowLast==GUI_WINDOW_PATTERN);
324 bool cursorEffectVal=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==index && curWindowLast==GUI_WINDOW_PATTERN);
325
326 // effect
327 if (pat->data[i][index]==-1) {
328 snprintf(id,63,"%.31s###PE%d_%d_%d",emptyLabel2,k,i,j);
329 ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
330 } else {
331 if (pat->data[i][index]>0xff) {
332 snprintf(id,63,"??###PE%d_%d_%d",k,i,j);
333 ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_EFFECT_INVALID]);
334 } else if (pat->data[i][index]>=0x10 || settings.oneDigitEffects==0) {
335 const unsigned char data=pat->data[i][index];
336 snprintf(id,63,"%.2X###PE%d_%d_%d",data,k,i,j);
337 ImGui::PushStyleColor(ImGuiCol_Text,uiColors[fxColors[data]]);
338 } else {
339 const unsigned char data=pat->data[i][index];
340 snprintf(id,63," %.1X###PE%d_%d_%d",data,k,i,j);
341 ImGui::PushStyleColor(ImGuiCol_Text,uiColors[fxColors[data]]);
342 }
343 }
344 ImGui::SameLine(0.0f,0.0f);
345 if (cursorEffect) {
346 ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
347 ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
348 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
349 ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectCellSize);
350 ImGui::PopStyleColor(3);
351 } else {
352 if (selectedEffect) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
353 ImGui::Selectable(id,isPushing || selectedEffect,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectCellSize);
354 if (selectedEffect) ImGui::PopStyleColor();
355 }
356 if (ImGui::IsItemClicked()) {
357 startSelection(j,index-1,i,ord);
358 }
359 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
360 updateSelection(j,index-1,i,ord);
361 }
362 if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
363 ImGui::InhibitInertialScroll();
364 NOTIFY_LONG_HOLD;
365 mobilePatSel=true;
366 }
367
368 // effect value
369 if (pat->data[i][index+1]==-1) {
370 snprintf(id,63,"%.31s###PF%d_%d_%d",emptyLabel2,k,i,j);
371 } else {
372 snprintf(id,63,"%.2X###PF%d_%d_%d",pat->data[i][index+1],k,i,j);
373 }
374 ImGui::SameLine(0.0f,0.0f);
375 if (cursorEffectVal) {
376 ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
377 ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
378 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
379 ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectValCellSize);
380 ImGui::PopStyleColor(3);
381 } else {
382 if (selectedEffectVal) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
383 ImGui::Selectable(id,isPushing || selectedEffectVal,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectValCellSize);
384 if (selectedEffectVal) ImGui::PopStyleColor();
385 }
386 if (ImGui::IsItemClicked()) {
387 startSelection(j,index,i,ord);
388 }
389 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
390 updateSelection(j,index,i,ord);
391 }
392 if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
393 ImGui::InhibitInertialScroll();
394 NOTIFY_LONG_HOLD;
395 mobilePatSel=true;
396 }
397 ImGui::PopStyleColor();
398 }
399 }
400 }
401 if (isPushing) {
402 ImGui::PopStyleColor();
403 }
404 ImGui::TableNextColumn();
405 for (int k=mustSetXOf; k<=chans; k++) {
406 patChanX[k]=ImGui::GetCursorScreenPos().x;
407 }
408 }
409
410 void FurnaceGUI::drawPattern() {
411 //int delta0=SDL_GetPerformanceCounter();
412 if (nextWindow==GUI_WINDOW_PATTERN) {
413 patternOpen=true;
414 ImGui::SetNextWindowFocus();
415 nextWindow=GUI_WINDOW_NOTHING;
416 }
417 if (!patternOpen) return;
418
419 bool inhibitMenu=false;
420
421 if (e->isPlaying() && followPattern) {
422 if (oldRowChanged || !e->isStepping()) {
423 if (e->isStepping()) pendingStepUpdate=1;
424 cursor.y=oldRow;
425 cursor.order=curOrder;
426 if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && selStart.order==selEnd.order && !selecting) {
427 selStart=cursor;
428 selEnd=cursor;
429 }
430 }
431 }
432 sel1=selStart;
433 sel2=selEnd;
434 if (sel2.order<sel1.order) {
435 sel2.order^=sel1.order;
436 sel1.order^=sel2.order;
437 sel2.order^=sel1.order;
438 sel2.y^=sel1.y;
439 sel1.y^=sel2.y;
440 sel2.y^=sel1.y;
441 } else if (sel2.order==sel1.order && sel2.y<sel1.y) {
442 sel2.y^=sel1.y;
443 sel1.y^=sel2.y;
444 sel2.y^=sel1.y;
445 }
446 if (sel2.xCoarse<sel1.xCoarse) {
447 sel2.xCoarse^=sel1.xCoarse;
448 sel1.xCoarse^=sel2.xCoarse;
449 sel2.xCoarse^=sel1.xCoarse;
450
451 sel2.xFine^=sel1.xFine;
452 sel1.xFine^=sel2.xFine;
453 sel2.xFine^=sel1.xFine;
454 } else if (sel2.xCoarse==sel1.xCoarse && sel2.xFine<sel1.xFine) {
455 sel2.xFine^=sel1.xFine;
456 sel1.xFine^=sel2.xFine;
457 sel2.xFine^=sel1.xFine;
458 }
459
460 /*
461 topMostOrder=-1;
462 topMostRow=-1;
463 bottomMostOrder=-1;
464 bottomMostRow=-1;
465 */
466
467 ImVec2 origWinPadding=ImGui::GetStyle().WindowPadding;
468 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0.0f,0.0f));
469 if (mobileUI) {
470 patWindowPos=(portrait?ImVec2(0.0f,(mobileMenuPos*-0.65*canvasH)+(0.12*canvasW)):ImVec2((0.16*canvasH)+0.5*canvasW*mobileMenuPos,0.0f));
471 patWindowSize=(portrait?ImVec2(canvasW,canvasH-(0.16*canvasW)-(0.12*canvasW)-(pianoOpen?(0.4*canvasW):0.0f)):ImVec2(canvasW-(0.16*canvasH),canvasH-(pianoOpen?(0.3*canvasH):0.0f)));
472 ImGui::SetNextWindowPos(patWindowPos);
473 ImGui::SetNextWindowSize(patWindowSize);
474 }
475 if (ImGui::Begin("Pattern",&patternOpen,globalWinFlags|(settings.avoidRaisingPattern?ImGuiWindowFlags_NoBringToFrontOnFocus:0)|((settings.cursorFollowsWheel && !selecting)?ImGuiWindowFlags_NoScrollWithMouse:0),_("Pattern"))) {
476 if (!mobileUI) {
477 patWindowPos=ImGui::GetWindowPos();
478 patWindowSize=ImGui::GetWindowSize();
479 }
480 //char id[32];
481 ImGui::PushFont(patFont);
482 int ord=curOrder;
483 int chans=e->getTotalChannelCount();
484 int displayChans=0;
485 float chanHeadBottom=0.0f;
486 const DivPattern* patCache[DIV_MAX_CHANS];
487 for (int i=0; i<chans; i++) {
488 if (e->curSubSong->chanShow[i]) displayChans++;
489 }
490 ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(0.0f,0.0f));
491 ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
492 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_SELECTION_HOVER]);
493 ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_SELECTION_ACTIVE]);
494 if (settings.centerPattern) {
495 float centerOff=(ImGui::GetContentRegionAvail().x-lastPatternWidth)*0.5;
496 if (centerOff>0.0f) {
497 ImGui::SetCursorPosX(ImGui::GetCursorPosX()+centerOff);
498 }
499 }
500 if (e->isPlaying() && followPattern && (!e->isStepping() || pendingStepUpdate)) updateScroll(oldRow);
501 if (--pendingStepUpdate<0) pendingStepUpdate=0;
502 if (nextScroll>-0.5f) {
503 ImGui::SetNextWindowScroll(ImVec2(-1.0f,nextScroll));
504 nextScroll=-1.0f;
505 nextAddScroll=0.0f;
506 nextAddScrollX=0.0f;
507 }
508 ImDrawList* tdl=NULL;
509
510 if (chans<1) {
511 ImGui::Text(_("there aren't any channels to show."));
512 } else if (ImGui::BeginTable("PatternView",displayChans+2,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_ScrollX|ImGuiTableFlags_ScrollY|ImGuiTableFlags_NoPadInnerX|ImGuiTableFlags_NoBordersInFrozenArea|(((settings.cursorFollowsWheel && !selecting) || wheelCalmDown)?ImGuiTableFlags_NoScrollWithMouse:0))) {
513 char chanID[2048];
514 float lineHeight=(ImGui::GetTextLineHeight()+2*dpiScale);
515
516 // this could be moved somewhere else for performance...
517 float oneCharSize=ImGui::CalcTextSize("A").x;
518 fourChars=ImVec2(oneCharSize*4.0f,lineHeight);
519 threeChars=ImVec2(oneCharSize*3.0f,lineHeight);
520 twoChars=ImVec2(oneCharSize*2.0f,lineHeight);
521 oneChar=ImVec2(oneCharSize,lineHeight);
522
523 noteCellSize=threeChars;
524 noteCellSize.x+=(float)settings.noteCellSpacing*dpiScale;
525 insCellSize=twoChars;
526 insCellSize.x+=(float)settings.insCellSpacing*dpiScale;
527 volCellSize=twoChars;
528 volCellSize.x+=(float)settings.volCellSpacing*dpiScale;
529 effectCellSize=twoChars;
530 effectCellSize.x+=(float)settings.effectCellSpacing*dpiScale;
531 effectValCellSize=twoChars;
532 effectValCellSize.x+=(float)settings.effectValCellSpacing*dpiScale;
533
534 // and now set things up
535 ImGui::TableSetupColumn("pos",ImGuiTableColumnFlags_WidthFixed,fourChars.x);
536
537 if (nextAddScroll!=0.0f) {
538 float newScroll=ImGui::GetScrollY()+nextAddScroll;
539 // wrap around and go to previous/next pattern if we're about to go beyond the view
540 if (newScroll<0.0f && curOrder>0) {
541 ImGui::SetScrollY(ImGui::GetScrollMaxY()+newScroll);
542 if (!e->isPlaying() || !followPattern) setOrder(curOrder-1);
543 } else if (newScroll>ImGui::GetScrollMaxY() && curOrder<(e->curSubSong->ordersLen-1)) {
544 ImGui::SetScrollY(newScroll-ImGui::GetScrollMaxY());
545 if (!e->isPlaying() || !followPattern) setOrder(curOrder+1);
546 } else {
547 ImGui::SetScrollY(newScroll);
548 }
549
550 // select in empty space
551 if (nextAddScroll>0.0f) {
552 updateSelection(selEnd.xCoarse,selEnd.xFine,bottomMostRow,bottomMostOrder);
553 } else {
554 updateSelection(selEnd.xCoarse,selEnd.xFine,topMostRow,topMostOrder);
555 }
556
557 nextScroll=-1.0f;
558 nextAddScroll=0.0f;
559 }
560 if (nextAddScrollX!=0.0f) {
561 ImGui::SetScrollX(ImGui::GetScrollX()+nextAddScrollX);
562 nextAddScrollX=0.0f;
563 }
564
565 ImGui::TableSetupScrollFreeze(1,1);
566 for (int i=0; i<chans; i++) {
567 if (!e->curSubSong->chanShow[i]) continue;
568 float chanWidth=noteCellSize.x;
569 if (e->curSubSong->chanCollapse[i]<3) {
570 chanWidth+=insCellSize.x;
571 }
572 if (e->curSubSong->chanCollapse[i]<2) {
573 chanWidth+=volCellSize.x;
574 }
575 if (e->curSubSong->chanCollapse[i]<1) {
576 chanWidth+=(effectCellSize.x+effectValCellSize.x)*e->curPat[i].effectCols;
577 }
578
579 ImGui::TableSetupColumn(fmt::sprintf("c%d",i).c_str(),ImGuiTableColumnFlags_WidthFixed,chanWidth);
580 }
581 ImGui::TableNextRow();
582 ImGui::TableNextColumn();
583 float lpwStart=ImGui::GetCursorPosX();
584 if (ImGui::Selectable(" ++###ExtraChannelButtons",false,ImGuiSelectableFlags_NoPadWithHalfSpacing,ImVec2(0.0f,lineHeight+1.0f*dpiScale))) {
585 ImGui::OpenPopup("PatternOpt");
586 }
587 if (ImGui::IsItemHovered() && !mobileUI) {
588 ImGui::SetTooltip(_("click for pattern options (effect columns/pattern names/visualizer)"));
589 }
590 if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
591 fancyPattern=!fancyPattern;
592 inhibitMenu=true;
593 e->enableCommandStream(fancyPattern);
594 e->getCommandStream(cmdStream);
595 cmdStream.clear();
596 }
597 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,origWinPadding);
598 ImGui::PushFont(mainFont);
599 if (ImGui::BeginPopup("PatternOpt",ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings)) {
600 ImGui::Text(_("Options:"));
601 ImGui::Indent();
602 ImGui::Checkbox(_("Effect columns/collapse"),&patExtraButtons);
603 ImGui::Checkbox(_("Pattern names"),&patChannelNames);
604 ImGui::Checkbox(_("Channel group hints"),&patChannelPairs);
605 if (ImGui::Checkbox(_("Visualizer"),&fancyPattern)) {
606 inhibitMenu=true;
607 e->enableCommandStream(fancyPattern);
608 e->getCommandStream(cmdStream);
609 cmdStream.clear();
610 }
611 ImGui::Unindent();
612
613 ImGui::Text(_("Channel status:"));
614 ImGui::Indent();
615 if (ImGui::RadioButton(_("No###_PCS0"),patChannelHints==0)) {
616 patChannelHints=0;
617 }
618 if (ImGui::RadioButton(_("Yes###_PCS1"),patChannelHints==1)) {
619 patChannelHints=1;
620 }
621 /*
622 if (ImGui::RadioButton(_("Regular###_PCS2"),patChannelHints==2)) {
623 patChannelHints=2;
624 }
625 if (ImGui::RadioButton(_("Detailed###_PCS3"),patChannelHints==3)) {
626 patChannelHints=3;
627 }*/
628 ImGui::Unindent();
629 ImGui::EndPopup();
630 }
631 ImGui::PopFont();
632 ImGui::PopStyleVar();
633 for (int i=0; i<chans; i++) {
634 if (!e->curSubSong->chanShow[i]) continue;
635 ImGui::TableNextColumn();
636 bool displayTooltip=false;
637
638 bool muted=e->isChannelMuted(i);
639 ImVec4 chanHead=muted?uiColors[GUI_COLOR_CHANNEL_MUTED]:channelColor(i);
640 ImVec4 chanHeadActive=chanHead;
641 ImVec4 chanHeadHover=chanHead;
642 ImVec4 chanHeadBase=chanHead;
643
644 if (e->keyHit[i]) {
645 keyHit1[i]=1.0f;
646
647 if (chanOscRandomPhase) {
648 chanOscChan[i].phaseOff=(float)rand()/(float)RAND_MAX;
649 } else {
650 chanOscChan[i].phaseOff=0.0f;
651 }
652
653 if (settings.channelFeedbackStyle==1) {
654 keyHit[i]=0.2;
655 if (!muted) {
656 int note=e->getChanState(i)->note+60;
657 if (note>=0 && note<180) {
658 pianoKeyHit[note]=1.0;
659 }
660 }
661 }
662 e->keyHit[i]=false;
663 }
664 if (settings.channelFeedbackStyle==2 && e->isRunning()) {
665 float amount=((float)(e->getChanState(i)->volume>>8)/(float)e->getMaxVolumeChan(i));
666 if (!e->getChanState(i)->keyOn) amount=0.0f;
667 keyHit[i]=amount*0.2f;
668 if (!muted) {
669 int note=e->getChanState(i)->note+60;
670 if (note>=0 && note<180) {
671 pianoKeyHit[note]=amount;
672 }
673 }
674 } else if (settings.channelFeedbackStyle==3 && e->isRunning()) {
675 bool active=e->getChanState(i)->keyOn;
676 keyHit[i]=active?0.2f:0.0f;
677 if (!muted) {
678 int note=e->getChanState(i)->note+60;
679 if (note>=0 && note<180) {
680 pianoKeyHit[note]=active?1.0f:0.0f;
681 }
682 }
683 }
684 if (settings.guiColorsBase) {
685 chanHead.x*=1.0-keyHit[i]; chanHead.y*=1.0-keyHit[i]; chanHead.z*=1.0-keyHit[i];
686 chanHeadActive.x*=0.5; chanHeadActive.y*=0.5; chanHeadActive.z*=0.5;
687 chanHeadHover.x*=0.9-keyHit[i]; chanHeadHover.y*=0.9-keyHit[i]; chanHeadHover.z*=0.9-keyHit[i];
688 } else {
689 chanHead.x*=0.25+keyHit[i]; chanHead.y*=0.25+keyHit[i]; chanHead.z*=0.25+keyHit[i];
690 chanHeadActive.x*=0.8; chanHeadActive.y*=0.8; chanHeadActive.z*=0.8;
691 chanHeadHover.x*=0.4+keyHit[i]; chanHeadHover.y*=0.4+keyHit[i]; chanHeadHover.z*=0.4+keyHit[i];
692 }
693 keyHit[i]-=((settings.channelStyle==0)?0.02:0.01)*60.0*ImGui::GetIO().DeltaTime;
694 if (keyHit[i]<0) keyHit[i]=0;
695 ImGui::PushStyleColor(ImGuiCol_Header,chanHead);
696 ImGui::PushStyleColor(ImGuiCol_HeaderActive,chanHeadActive);
697 ImGui::PushStyleColor(ImGuiCol_HeaderHovered,chanHeadHover);
698 ImGui::PushStyleColor(ImGuiCol_Text,ImGui::GetColorU32(channelTextColor(i)));
699 if (settings.channelStyle==0) ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg,ImGui::GetColorU32(chanHead));
700 if (muted) ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_CHANNEL_MUTED]);
701 if (settings.channelFont==0) ImGui::PushFont(mainFont);
702
703 // TODO: appearance
704 ImGuiWindow* window=ImGui::GetCurrentWindow();
705 ImVec2 size=ImVec2(
706 1.0f,
707 lineHeight+1.0f*dpiScale
708 );
709 ImDrawList* dl=ImGui::GetWindowDrawList();
710
711 if (settings.channelStyle!=0) {
712 size.y+=6.0f*dpiScale;
713 }
714
715 if (settings.channelStyle==2) {
716 size.y+=6.0f*dpiScale;
717 }
718
719 ImVec2 minArea=window->DC.CursorPos;
720 ImVec2 maxArea=ImVec2(
721 minArea.x+window->WorkRect.Max.x-window->WorkRect.Min.x,
722 minArea.y+size.y
723 );
724 ImRect rect=ImRect(minArea,maxArea);
725 float padding=ImGui::CalcTextSize("A").x;
726
727 ImVec2 minLabelArea=minArea;
728 ImVec2 maxLabelArea=maxArea;
729
730 if (e->curSubSong->chanCollapse[i]) {
731 const char* chName=e->getChannelShortName(i);
732 if (strlen(chName)>3) {
733 snprintf(chanID,2048,"...");
734 } else {
735 snprintf(chanID,2048,"%s",chName);
736 }
737 displayTooltip=true;
738 } else {
739 minLabelArea.x+=padding;
740 maxLabelArea.x-=padding;
741 if (settings.channelStyle==3) { // split button
742 maxLabelArea.x-=ImGui::GetFrameHeightWithSpacing();
743 }
744 const char* chName=e->getChannelName(i);
745 float chNameLimit=maxLabelArea.x-minLabelArea.x;
746 if (ImGui::CalcTextSize(chName).x>chNameLimit) {
747 String shortChName;
748 float totalAdvanced=0.0f;
749 float ellipsisSize=ImGui::CalcTextSize("...").x;
750 for (const char* j=chName; *j;) {
751 signed char l;
752 int ch=decodeUTF8((const unsigned char*)j,l);
753
754 // TODO: eliminate use of GetFontBaked()?
755 totalAdvanced+=ImGui::GetFontBaked()->GetCharAdvance(ch);
756 if (totalAdvanced>(chNameLimit-ellipsisSize)) break;
757
758 for (int k=0; k<l; k++) {
759 shortChName+=j[k];
760 }
761
762 j+=l;
763 }
764 shortChName+="...";
765 snprintf(chanID,2048,"%s",shortChName.c_str());
766 displayTooltip=true;
767 } else {
768 snprintf(chanID,2048,"%s",chName);
769 }
770 }
771
772 if (settings.channelTextCenter) {
773 minLabelArea.x+=0.5f*(maxLabelArea.x-minLabelArea.x-ImGui::CalcTextSize(chanID).x);
774 }
775
776 if ((!patExtraButtons && !patChannelNames && !patChannelHints) || settings.channelVolStyle!=0) ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(0.0f,0.0f));
777
778 ImGui::PushID(2048+i);
779 switch (settings.channelStyle) {
780 case 0: // classic
781 ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
782 if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
783 bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
784 ImU32 col=(hovered || (mobileUI && ImGui::IsMouseDown(ImGuiMouseButton_Left)))?ImGui::GetColorU32(ImGuiCol_HeaderHovered):ImGui::GetColorU32(ImGuiCol_Header);
785 dl->AddRectFilled(rect.Min,rect.Max,col);
786 dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y),ImGui::GetColorU32(channelTextColor(i)),chanID);
787 }
788 break;
789 case 1: { // line
790 ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
791 if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
792 bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
793 ImU32 fadeCol0=ImGui::GetColorU32(ImVec4(
794 chanHeadBase.x,
795 chanHeadBase.y,
796 chanHeadBase.z,
797 (hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.25f:0.0f
798 ));
799 ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
800 chanHeadBase.x,
801 chanHeadBase.y,
802 chanHeadBase.z,
803 (hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.5f:MIN(1.0f,chanHeadBase.w*keyHit[i]*4.0f)
804 ));
805 dl->AddRectFilledMultiColor(rect.Min,rect.Max,fadeCol0,fadeCol0,fadeCol,fadeCol);
806 dl->AddLine(ImVec2(rect.Min.x,rect.Max.y),ImVec2(rect.Max.x,rect.Max.y),ImGui::GetColorU32(chanHeadBase),2.0f*dpiScale);
807 dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
808 }
809 break;
810 }
811 case 2: { // round
812 ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
813 if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
814 bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
815 ImU32 fadeCol0=ImGui::GetColorU32(ImVec4(
816 chanHeadBase.x,
817 chanHeadBase.y,
818 chanHeadBase.z,
819 (hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.5f:MIN(1.0f,0.3f+chanHeadBase.w*keyHit[i]*1.5f)
820 ));
821 ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
822 chanHeadBase.x,
823 chanHeadBase.y,
824 chanHeadBase.z,
825 (hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.3f:MIN(1.0f,0.2f+chanHeadBase.w*keyHit[i]*1.2f)
826 ));
827 ImVec2 rMin=rect.Min;
828 ImVec2 rMax=rect.Max;
829 rMin.x+=3.0f*dpiScale;
830 rMin.y+=6.0f*dpiScale;
831 rMax.x-=3.0f*dpiScale;
832 rMax.y-=6.0f*dpiScale;
833 dl->AddRectFilledMultiColor(rMin,rMax,fadeCol0,fadeCol0,fadeCol,fadeCol,4.0f*dpiScale);
834 dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+6.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
835 }
836 break;
837 }
838 case 3: // split button
839 ImGui::Dummy(ImVec2(1.0f,2.0f*dpiScale));
840 //ImGui::SetCursorPosX(minLabelArea.x);
841 ImGui::TextNoHashHide("%s",chanID);
842 ImGui::SameLine();
843 ImGui::PushFont(mainFont);
844 ImGui::SmallButton(muted?ICON_FA_VOLUME_OFF:ICON_FA_VOLUME_UP);
845 ImGui::PopFont();
846 break;
847 case 4: { // square border
848 ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
849 if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
850 bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
851 ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
852 chanHeadBase.x,
853 chanHeadBase.y,
854 chanHeadBase.z,
855 (hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?1.0f:MIN(1.0f,0.2f+chanHeadBase.w*keyHit[i]*4.0f)
856 ));
857 ImVec2 rMin=rect.Min;
858 ImVec2 rMax=rect.Max;
859 rMin.x+=2.0f*dpiScale;
860 rMin.y+=3.0f*dpiScale;
861 rMax.x-=3.0f*dpiScale;
862 rMax.y-=3.0f*dpiScale;
863 dl->AddRect(rMin,rMax,fadeCol,0.0f,2.0*dpiScale);
864 dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
865 }
866 break;
867 }
868 case 5: { // round border
869 ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
870 if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
871 bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
872 ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
873 chanHeadBase.x,
874 chanHeadBase.y,
875 chanHeadBase.z,
876 (hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?1.0f:MIN(1.0f,0.2f+chanHeadBase.w*keyHit[i]*4.0f)
877 ));
878 ImVec2 rMin=rect.Min;
879 ImVec2 rMax=rect.Max;
880 rMin.x+=2.0f*dpiScale;
881 rMin.y+=3.0f*dpiScale;
882 rMax.x-=3.0f*dpiScale;
883 rMax.y-=3.0f*dpiScale;
884 dl->AddRect(rMin,rMax,fadeCol,4.0f*dpiScale,ImDrawFlags_RoundCornersAll,2.0*dpiScale);
885 dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
886 }
887 break;
888 }
889 }
890 ImGui::PopID();
891
892 if ((!patExtraButtons && !patChannelNames && !patChannelHints) || settings.channelVolStyle!=0) ImGui::PopStyleVar();
893
894 if (displayTooltip && ImGui::IsItemHovered() && !mobileUI) {
895 ImGui::SetTooltip("%s",e->getChannelName(i));
896 }
897 if (settings.channelFont==0) ImGui::PopFont();
898 if (mobileUI) {
899 if (ImGui::IsItemHovered()) {
900 if (CHECK_LONG_HOLD) {
901 NOTIFY_LONG_HOLD;
902 e->toggleSolo(i);
903 soloChan=i;
904 }
905 if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::WasInertialScroll()) {
906 if (soloChan!=i) {
907 e->toggleMute(i);
908 } else {
909 soloChan=-1;
910 }
911 }
912 }
913 } else {
914 if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
915 if (settings.soloAction!=1 && soloTimeout>0 && soloChan==i) {
916 e->toggleSolo(i);
917 soloTimeout=0;
918 } else {
919 e->toggleMute(i);
920 soloTimeout=settings.doubleClickTime;
921 soloChan=i;
922 }
923 }
924 }
925 if (muted) ImGui::PopStyleColor();
926 ImGui::PopStyleColor(4);
927 if (settings.soloAction!=2 && !mobileUI) if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
928 inhibitMenu=true;
929 e->toggleSolo(i);
930 }
931
932 if (settings.channelStyle==3) {
933 ImGui::Dummy(ImVec2(1.0f,2.0f*dpiScale));
934 }
935
936 // volume bar
937 if (settings.channelVolStyle!=0) {
938 ImVec2 sizeV=ImVec2(
939 1.0f,
940 6.0*dpiScale
941 );
942 ImVec2 minAreaV=window->DC.CursorPos;
943 ImVec2 maxAreaV=ImVec2(
944 minAreaV.x+window->WorkRect.Max.x-window->WorkRect.Min.x,
945 minAreaV.y+sizeV.y
946 );
947 ImRect rectV=ImRect(minAreaV,maxAreaV);
948 ImGui::ItemSize(sizeV,ImGui::GetStyle().FramePadding.y);
949 if (ImGui::ItemAdd(rectV,ImGui::GetID(chanID))) {
950 float xLeft=0.0f;
951 float xRight=1.0f;
952
953 if (e->keyHit[i]) {
954 keyHit1[i]=1.0f;
955 e->keyHit[i]=false;
956 }
957
958 if (e->isRunning()) {
959 DivChannelState* cs=e->getChanState(i);
960 unsigned short chanPan=e->getChanPan(i);
961 float stereoPan=(float)(e->convertPanSplitToLinear(chanPan,8,256)-128)/128.0;
962 switch (settings.channelVolStyle) {
963 case 1: // simple
964 xRight=((float)(cs->volume>>8)/(float)e->getMaxVolumeChan(i))*0.9+(keyHit1[i]*0.1f);
965 break;
966 case 2: { // stereo
967 float amount=((float)(cs->volume>>8)/(float)e->getMaxVolumeChan(i))*0.4+(keyHit1[i]*0.1f);
968 xRight=0.5+amount*(1.0+MIN(0.0,stereoPan));
969 xLeft=0.5-amount*(1.0-MAX(0.0,stereoPan));
970 break;
971 }
972 case 3: // real
973 xRight=chanOscVol[i];
974 break;
975 case 4: // real (stereo)
976 xRight=0.5+chanOscVol[i]*0.5*(1.0+MIN(0.0,stereoPan));
977 xLeft=0.5-chanOscVol[i]*0.5*(1.0-MAX(0.0,stereoPan));
978 break;
979 }
980
981 if (xLeft<0.0f) xLeft=0.0f;
982 if (xLeft>1.0f) xLeft=1.0f;
983 if (xRight<0.0f) xRight=0.0f;
984 if (xRight>1.0f) xRight=1.0f;
985
986 dl->AddRectFilled(
987 ImLerp(rectV.Min,rectV.Max,ImVec2(xLeft,0.0f)),
988 ImLerp(rectV.Min,rectV.Max,ImVec2(xRight,1.0f)),
989 ImGui::GetColorU32(chanHeadBase)
990 );
991 }
992 }
993 }
994
995 // extra buttons
996 if (patExtraButtons) {
997 snprintf(chanID,2048,"%c###_HCH%d",e->curSubSong->chanCollapse[i]?'+':'-',i);
998 ImGui::SetCursorPosX(ImGui::GetCursorPosX()+4.0f*dpiScale);
999 if (ImGui::SmallButton(chanID)) {
1000 if (e->curSubSong->chanCollapse[i]==0) {
1001 e->curSubSong->chanCollapse[i]=3;
1002 } else if (e->curSubSong->chanCollapse[i]>0) {
1003 e->curSubSong->chanCollapse[i]--;
1004 }
1005 finishSelection();
1006 }
1007 if (!e->curSubSong->chanCollapse[i]) {
1008 ImGui::SameLine();
1009 snprintf(chanID,2048,"<###_LCH%d",i);
1010 ImGui::BeginDisabled(e->curPat[i].effectCols<=1);
1011 if (ImGui::SmallButton(chanID)) {
1012 e->curPat[i].effectCols--;
1013 if (e->curPat[i].effectCols<1) e->curPat[i].effectCols=1;
1014 finishSelection();
1015 }
1016 ImGui::EndDisabled();
1017 ImGui::SameLine();
1018 ImGui::BeginDisabled(e->curPat[i].effectCols>=DIV_MAX_EFFECTS);
1019 snprintf(chanID,2048,">###_RCH%d",i);
1020 if (ImGui::SmallButton(chanID)) {
1021 e->curPat[i].effectCols++;
1022 if (e->curPat[i].effectCols>DIV_MAX_EFFECTS) e->curPat[i].effectCols=DIV_MAX_EFFECTS;
1023 finishSelection();
1024 }
1025 ImGui::EndDisabled();
1026 }
1027 ImGui::Spacing();
1028 }
1029
1030 if (patChannelNames) {
1031 DivPattern* pat=e->curPat[i].getPattern(e->curOrders->ord[i][ord],true);
1032 ImGui::PushFont(mainFont);
1033 snprintf(chanID,2048," %s###PatName%d",pat->name.c_str(),i);
1034 if (ImGui::Selectable(chanID,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,ImVec2(0.0f,lineHeight+1.0f*dpiScale))) {
1035 editStr(&pat->name);
1036 }
1037 ImGui::PopFont();
1038 }
1039
1040 if (patChannelHints) {
1041 ImGuiWindow* win=ImGui::GetCurrentWindow();
1042 ImVec2 posMin=win->DC.CursorPos;
1043 ImGui::Dummy(ImVec2(dpiScale,settings.iconSize*dpiScale));
1044 ImVec2 posMax=ImVec2(win->WorkRect.Max.x,win->WorkRect.Max.y);
1045 posMin.y-=ImGui::GetStyle().ItemSpacing.y*0.5;
1046 ImDrawList* dl=ImGui::GetWindowDrawList();
1047 ImVec2 iconPos[6];
1048 DivChannelState* cs=e->getChanState(i);
1049 if (cs!=NULL) {
1050 DivChannelModeHints hints=e->getChanModeHints(i);
1051 if (hints.count>4) hints.count=4;
1052 int hintCount=3+hints.count;
1053
1054 // calculate icon size
1055 for (int i=0; i<hintCount; i++) {
1056 iconPos[i]=ImLerp(posMin,posMax,ImVec2((float)(2*i+1)/(float)(hintCount*2),0.0f));
1057 }
1058
1059 // 1. ON/OFF
1060 ImVec4 onOffColor;
1061 if (cs->keyOn) {
1062 if (cs->releasing) {
1063 onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_REL_ON];
1064 } else {
1065 onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_ON];
1066 }
1067 } else {
1068 if (cs->releasing) {
1069 onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_REL];
1070 } else {
1071 onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
1072 }
1073 }
1074 iconPos[0].x-=mainFont->CalcTextSizeA(MAIN_FONT_SIZE,FLT_MAX,0.0f,ICON_FA_SQUARE).x*0.5f;
1075 dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[0],ImGui::GetColorU32(onOffColor),ICON_FA_SQUARE);
1076
1077 // 2. PITCH SLIDE/VIBRATO
1078 ImVec4 pitchColor;
1079 const char* pitchIcon=ICON_FUR_SINE;
1080 if (cs->inPorta) {
1081 pitchIcon=ICON_FA_SHARE;
1082 pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
1083 } else if (cs->portaSpeed>0) {
1084 if (cs->portaNote>=60) {
1085 pitchIcon=ICON_FA_CHEVRON_UP;
1086 } else {
1087 pitchIcon=ICON_FA_CHEVRON_DOWN;
1088 }
1089 pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
1090 } else if (cs->vibratoDepth>0) {
1091 pitchIcon=ICON_FUR_SINE;
1092 pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
1093 } else if (cs->arp) {
1094 pitchIcon=ICON_FA_BARS;
1095 pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_NOTE];
1096 } else {
1097 pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
1098 }
1099 iconPos[1].x-=mainFont->CalcTextSizeA(MAIN_FONT_SIZE,FLT_MAX,0.0f,pitchIcon).x*0.5f;
1100 dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[1],ImGui::GetColorU32(pitchColor),pitchIcon);
1101
1102
1103 // 3. VOLUME
1104 ImVec4 volColor;
1105 const char* volIcon=ICON_FA_MINUS;
1106 if (cs->tremoloDepth>0) {
1107 volIcon=ICON_FUR_SINE;
1108 volColor=uiColors[GUI_COLOR_PATTERN_STATUS_VOLUME];
1109 } else if (cs->volSpeed) {
1110 if (cs->volSpeed>0) {
1111 volIcon=ICON_FA_CHEVRON_UP;
1112 } else {
1113 volIcon=ICON_FA_CHEVRON_DOWN;
1114 }
1115 volColor=uiColors[GUI_COLOR_PATTERN_STATUS_VOLUME];
1116 } else {
1117 volColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
1118 }
1119 iconPos[2].x-=mainFont->CalcTextSizeA(MAIN_FONT_SIZE,FLT_MAX,0.0f,volIcon).x*0.5f;
1120 dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[2],ImGui::GetColorU32(volColor),volIcon);
1121
1122 // 4. OTHER
1123 for (int i=0; i<hints.count; i++) {
1124 if (hints.hint[i]==NULL) continue;
1125 ImVec4 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
1126 switch (hints.type[i]) {
1127 case 0:
1128 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
1129 break;
1130 case 1:
1131 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_VOLUME];
1132 break;
1133 case 2:
1134 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
1135 break;
1136 case 3:
1137 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_PANNING];
1138 break;
1139 case 4:
1140 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_SYS1];
1141 break;
1142 case 5:
1143 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_SYS2];
1144 break;
1145 case 6:
1146 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MIXING];
1147 break;
1148 case 7:
1149 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DSP];
1150 break;
1151 case 8:
1152 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_NOTE];
1153 break;
1154 case 9:
1155 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MISC1];
1156 break;
1157 case 10:
1158 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MISC2];
1159 break;
1160 case 11:
1161 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MISC3];
1162 break;
1163 case 12:
1164 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_ATTACK];
1165 break;
1166 case 13:
1167 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DECAY];
1168 break;
1169 case 14:
1170 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_SUSTAIN];
1171 break;
1172 case 15:
1173 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_RELEASE];
1174 break;
1175 case 16:
1176 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DEC_LINEAR];
1177 break;
1178 case 17:
1179 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DEC_EXP];
1180 break;
1181 case 18:
1182 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_INC];
1183 break;
1184 case 19:
1185 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_BENT];
1186 break;
1187 case 20:
1188 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DIRECT];
1189 break;
1190 case 21:
1191 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_WARNING];
1192 break;
1193 case 22:
1194 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_ERROR];
1195 break;
1196 default:
1197 hintColor=uiColors[GUI_COLOR_TEXT];
1198 break;
1199 }
1200 iconPos[i+3].x-=mainFont->CalcTextSizeA(MAIN_FONT_SIZE,FLT_MAX,0.0f,hints.hint[i]).x*0.5f;
1201 dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[i+3],ImGui::GetColorU32(hintColor),hints.hint[i]);
1202 }
1203 }
1204 }
1205 chanHeadBottom=ImGui::GetCursorScreenPos().y-ImGui::GetStyle().ItemSpacing.y;
1206 }
1207 ImGui::TableNextColumn();
1208 lastPatternWidth=ImGui::GetCursorPosX()-lpwStart+ImGui::GetStyle().ScrollbarSize;
1209 if (e->hasExtValue()) {
1210 ImGui::TextColored(uiColors[GUI_COLOR_EE_VALUE]," %.2X",e->getExtValue());
1211 }
1212
1213 dummyRows=(ImGui::GetWindowSize().y/lineHeight)/2;
1214
1215 topMostOrder=-1;
1216 topMostRow=-1;
1217
1218 // オップナー2608 i owe you one more for this horrible code
1219 // previous pattern
1220 ImGui::PushStyleVar(ImGuiStyleVar_FrameShading,0.0f);
1221 if (settings.viewPrevPattern) {
1222 int viewOrder=ord;
1223 int viewRow=-dummyRows+1;
1224 while (viewRow<0) {
1225 viewOrder--;
1226 viewRow+=e->curSubSong->patLen;
1227 }
1228 if (viewOrder>=0 && viewOrder<e->curSubSong->ordersLen) for (int i=0; i<chans; i++) {
1229 patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][viewOrder],false);
1230 }
1231 if (orderLock) {
1232 ImGui::BeginDisabled();
1233 } else {
1234 ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*ImGui::GetStyle().DisabledAlpha);
1235 }
1236 ImGui::PushID("prevPatterns");
1237 for (int i=0; i<dummyRows-1; i++) {
1238 ImGui::PushID(i);
1239 patternRow(viewRow,e->isPlaying(),lineHeight,chans,viewOrder,patCache,orderLock);
1240 if (++viewRow>=e->curSubSong->patLen) {
1241 viewRow=0;
1242 viewOrder++;
1243 if (viewOrder>=0 && viewOrder<e->curSubSong->ordersLen) for (int j=0; j<chans; j++) {
1244 patCache[j]=e->curPat[j].getPattern(e->curOrders->ord[j][viewOrder],false);
1245 }
1246 }
1247 ImGui::PopID();
1248 }
1249 ImGui::PopID();
1250 if (orderLock) {
1251 ImGui::EndDisabled();
1252 } else {
1253 ImGui::PopStyleVar();
1254 }
1255 } else {
1256 for (int i=0; i<dummyRows-1; i++) {
1257 ImGui::TableNextRow(0,lineHeight);
1258 ImGui::TableNextColumn();
1259 }
1260 }
1261 // active area
1262 for (int i=0; i<chans; i++) {
1263 patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord],true);
1264 }
1265 for (int i=0; i<e->curSubSong->patLen; i++) {
1266 patternRow(i,e->isPlaying(),lineHeight,chans,ord,patCache,false);
1267 }
1268 // next pattern
1269 if (settings.viewPrevPattern) {
1270 int viewOrder=ord+1;
1271 int viewRow=0;
1272 if (viewOrder<e->curSubSong->ordersLen) for (int i=0; i<chans; i++) {
1273 patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord+1],true);
1274 }
1275 if (orderLock) {
1276 ImGui::BeginDisabled();
1277 } else {
1278 ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*ImGui::GetStyle().DisabledAlpha);
1279 }
1280 ImGui::PushID("nextPatterns");
1281 for (int i=0; i<=dummyRows; i++) {
1282 ImGui::PushID(i);
1283 patternRow(viewRow,e->isPlaying(),lineHeight,chans,viewOrder,patCache,orderLock);
1284 if (++viewRow>=e->curSubSong->patLen) {
1285 viewRow=0;
1286 viewOrder++;
1287 if (viewOrder>=0 && viewOrder<e->curSubSong->ordersLen) for (int j=0; j<chans; j++) {
1288 patCache[j]=e->curPat[j].getPattern(e->curOrders->ord[j][viewOrder],false);
1289 }
1290 }
1291 ImGui::PopID();
1292 }
1293 ImGui::PopID();
1294 if (orderLock) {
1295 ImGui::EndDisabled();
1296 } else {
1297 ImGui::PopStyleVar();
1298 }
1299 } else {
1300 for (int i=0; i<=dummyRows; i++) {
1301 ImGui::TableNextRow(0,lineHeight);
1302 ImGui::TableNextColumn();
1303 }
1304 }
1305
1306 ImGui::PopStyleVar();
1307 if (demandScrollX) {
1308 float finalX=-fourChars.x;
1309 // manually calculate X scroll
1310 for (int i=0; i<=cursor.xCoarse; i++) {
1311 int fine=(i==cursor.xCoarse)?cursor.xFine:9999;
1312 if (!e->curSubSong->chanShow[i]) continue;
1313
1314 finalX+=noteCellSize.x;
1315 // ins
1316 if (fine==0) break;
1317 if (e->curSubSong->chanCollapse[i]<3) {
1318 finalX+=insCellSize.x;
1319 }
1320 // vol
1321 if (fine==1) break;
1322 if (e->curSubSong->chanCollapse[i]<2) {
1323 finalX+=volCellSize.x;
1324 }
1325 // effects
1326 if (fine==2) break;
1327 if (e->curSubSong->chanCollapse[i]<1) {
1328 for (int j=0; j<MIN(fine-2,e->curPat[i].effectCols*2); j++) {
1329 if (j&1) {
1330 finalX+=effectValCellSize.x;
1331 } else {
1332 finalX+=effectCellSize.x;
1333 }
1334 }
1335 }
1336 }
1337 float totalDemand=finalX-ImGui::GetScrollX();
1338 float availWidth=ImGui::GetWindowWidth();
1339 if (totalDemand<(availWidth*0.25f)) {
1340 ImGui::SetScrollX(finalX-availWidth*0.25f);
1341 } else if (totalDemand>(availWidth*0.7f)) {
1342 ImGui::SetScrollX(finalX-availWidth*0.7f);
1343 }
1344 demandScrollX=false;
1345 }
1346
1347 // cursor follows wheel
1348 if (settings.cursorFollowsWheel && (!e->isPlaying() || !followPattern || selecting) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) {
1349 if (wheelX!=0 || wheelY!=0) {
1350 int xAmount=wheelX;
1351 int yAmount=(settings.cursorFollowsWheel==2)?wheelY:-wheelY;
1352 if (settings.cursorWheelStep==1) {
1353 xAmount*=MAX(1,editStep);
1354 yAmount*=MAX(1,editStep);
1355 }
1356 if (settings.cursorWheelStep==2) {
1357 xAmount*=MAX(1,editStepCoarse);
1358 yAmount*=MAX(1,editStepCoarse);
1359 }
1360 moveCursor(xAmount,yAmount,false);
1361 }
1362 }
1363
1364 // overflow changes order
1365 if (--wheelCalmDown<0) wheelCalmDown=0;
1366 if (settings.scrollChangesOrder && (!e->isPlaying() || !followPattern) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && !settings.cursorFollowsWheel && !wheelCalmDown) {
1367 if (wheelY!=0) {
1368 if (wheelY>0) {
1369 if (ImGui::GetScrollY()<=0) {
1370 if (haveHitBounds) {
1371 if (curOrder>0) {
1372 setOrder(curOrder-1);
1373 ImGui::SetScrollY(ImGui::GetScrollMaxY());
1374 updateScroll(e->curSubSong->patLen);
1375 wheelCalmDown=2;
1376 } else if (settings.scrollChangesOrder==2) {
1377 setOrder(e->curSubSong->ordersLen-1);
1378 ImGui::SetScrollY(ImGui::GetScrollMaxY());
1379 updateScroll(e->curSubSong->patLen);
1380 wheelCalmDown=2;
1381 }
1382 haveHitBounds=false;
1383 } else {
1384 haveHitBounds=true;
1385 }
1386 } else {
1387 haveHitBounds=false;
1388 }
1389 } else {
1390 if (ImGui::GetScrollY()>=ImGui::GetScrollMaxY()) {
1391 if (haveHitBounds) {
1392 if (curOrder<(e->curSubSong->ordersLen-1)) {
1393 setOrder(curOrder+1);
1394 ImGui::SetScrollY(0);
1395 updateScroll(0);
1396 wheelCalmDown=2;
1397 } else if (settings.scrollChangesOrder==2) {
1398 setOrder(0);
1399 ImGui::SetScrollY(0);
1400 updateScroll(0);
1401 wheelCalmDown=2;
1402 }
1403 haveHitBounds=false;
1404 } else {
1405 haveHitBounds=true;
1406 }
1407 } else {
1408 haveHitBounds=false;
1409 }
1410 }
1411 }
1412 }
1413 // HACK: we need to capture the last scroll position in order to restore it during undo/redo
1414 patScroll=ImGui::GetScrollY();
1415 // HACK: rendering here would cause the pairs to be drawn behind the pattern for some reason...
1416 // ...so we capture the table's window draw list...
1417 tdl=ImGui::GetWindowDrawList();
1418 ImGui::EndTable();
1419 }
1420
1421 // ...and then use it here
1422 ImGui::PushFont(mainFont);
1423 if (patChannelPairs && e->isRunning() && tdl!=NULL) { // pair hints
1424 float pos=0.0f;
1425 float posCenter=0.0f;
1426 float posMin=FLT_MAX;
1427 float posMax=-FLT_MAX;
1428 ImVec2 textSize;
1429 unsigned int floors[4][4]; // bit array
1430 std::vector<DelayedLabel> delayedLabels;
1431
1432 memset(floors,0,4*4*sizeof(unsigned int));
1433
1434 for (int i=0; i<chans; i++) {
1435 std::vector<DivChannelPair> pairs;
1436 e->getChanPaired(i,pairs);
1437
1438 for (DivChannelPair pair: pairs) {
1439 bool isPaired=false;
1440 int numPairs=0;
1441 unsigned int pairMin=i;
1442 unsigned int pairMax=i;
1443 unsigned char curFloor=0;
1444 if (!e->curSubSong->chanShow[i]) {
1445 continue;
1446 }
1447
1448 for (int j=0; j<8; j++) {
1449 if (pair.pairs[j]==-1) continue;
1450 int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
1451 if (!e->curSubSong->chanShow[pairCh]) {
1452 continue;
1453 }
1454 isPaired=true;
1455 if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
1456 if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
1457 }
1458
1459 if (!isPaired) continue;
1460
1461 float posY=chanHeadBottom;
1462
1463 // find a free floor
1464 while (curFloor<4) {
1465 bool free=true;
1466 for (unsigned int j=pairMin; j<=pairMax; j++) {
1467 const unsigned int j0=j>>5;
1468 const unsigned int j1=1U<<(j&31);
1469 if (floors[curFloor][j0]&j1) {
1470 free=false;
1471 break;
1472 }
1473 }
1474 if (free) break;
1475 curFloor++;
1476 }
1477 if (curFloor<4) {
1478 // occupy floor
1479 floors[curFloor][pairMin>>5]|=1U<<(pairMin&31);
1480 floors[curFloor][pairMax>>5]|=1U<<(pairMax&31);
1481 }
1482
1483 pos=(patChanX[i+1]+patChanX[i])*0.5;
1484 posCenter=pos;
1485 posMin=pos;
1486 posMax=pos;
1487 numPairs++;
1488
1489 if (pair.label==NULL) {
1490 textSize=ImGui::CalcTextSize("???");
1491 } else {
1492 textSize=ImGui::CalcTextSize(pair.label);
1493 }
1494
1495 posY+=(textSize.y+ImGui::GetStyle().ItemSpacing.y)*curFloor;
1496
1497 tdl->AddLine(
1498 ImVec2(pos,chanHeadBottom),
1499 ImVec2(pos,posY+textSize.y),
1500 ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
1501 2.0f*dpiScale
1502 );
1503
1504 for (int j=0; j<8; j++) {
1505 if (pair.pairs[j]==-1) continue;
1506 int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
1507 if (!e->curSubSong->chanShow[pairCh]) {
1508 continue;
1509 }
1510
1511 pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5;
1512 posCenter+=pos;
1513 numPairs++;
1514 if (pos<posMin) posMin=pos;
1515 if (pos>posMax) posMax=pos;
1516 tdl->AddLine(
1517 ImVec2(pos,chanHeadBottom),
1518 ImVec2(pos,posY+textSize.y),
1519 ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
1520 2.0f*dpiScale
1521 );
1522 }
1523
1524 posCenter/=numPairs;
1525
1526 if (pair.label==NULL) {
1527 tdl->AddLine(
1528 ImVec2(posMin,posY+textSize.y),
1529 ImVec2(posMax,posY+textSize.y),
1530 ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
1531 2.0f*dpiScale
1532 );
1533 } else {
1534 tdl->AddLine(
1535 ImVec2(posMin,posY+textSize.y),
1536 ImVec2(posCenter-textSize.x*0.5-6.0f*dpiScale,posY+textSize.y),
1537 ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
1538 2.0f*dpiScale
1539 );
1540 tdl->AddLine(
1541 ImVec2(posCenter+textSize.x*0.5+6.0f*dpiScale,posY+textSize.y),
1542 ImVec2(posMax,posY+textSize.y),
1543 ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
1544 2.0f*dpiScale
1545 );
1546
1547 delayedLabels.push_back(DelayedLabel(posCenter,posY,textSize,pair.label));
1548 }
1549 }
1550 }
1551
1552 for (DelayedLabel& i: delayedLabels) {
1553 ImGui::RenderFrameDrawList(
1554 tdl,
1555 ImVec2(i.posCenter-i.textSize.x*0.5-6.0f*dpiScale,i.posY+i.textSize.y*0.5-3.0f*dpiScale),
1556 ImVec2(i.posCenter+i.textSize.x*0.5+6.0f*dpiScale,i.posY+i.textSize.y*1.5+3.0f*dpiScale),
1557 ImGui::GetColorU32(ImGuiCol_FrameBg),
1558 true,
1559 ImGui::GetStyle().FrameRounding
1560 );
1561
1562 tdl->AddText(
1563 ImVec2(i.posCenter-i.textSize.x*0.5,i.posY+i.textSize.y*0.5),
1564 ImGui::GetColorU32(ImGuiCol_Text),
1565 i.label
1566 );
1567 }
1568 }
1569
1570 // also let's draw a warning if the instrument cannot be previewed
1571 if (tdl!=NULL && failedNoteOn) {
1572 ImVec2 winCenter=ImGui::GetWindowPos()+ImGui::GetWindowSize()*0.5f;
1573 ImGui::PushFont(bigFont);
1574 ImVec2 warnHeadSize=ImGui::CalcTextSize(_("WARNING!!"));
1575 ImGui::PopFont();
1576 ImVec2 warnTextSize1=ImGui::CalcTextSize(_("this instrument cannot be previewed because"));
1577 ImVec2 warnTextSize2=ImGui::CalcTextSize(_("none of the chips can play it"));
1578 ImVec2 warnTextSize3=ImGui::CalcTextSize(_("your instrument is in peril!! be careful..."));
1579
1580 float maxTextSize=warnHeadSize.x;
1581 if (warnTextSize1.x>maxTextSize) maxTextSize=warnTextSize1.x;
1582 if (warnTextSize2.x>maxTextSize) maxTextSize=warnTextSize2.x;
1583 if (warnTextSize3.x>maxTextSize) maxTextSize=warnTextSize3.x;
1584
1585 ImVec2 sumOfAll=ImVec2(
1586 maxTextSize,
1587 warnHeadSize.y+warnTextSize1.y+warnTextSize2.y+warnTextSize3.y
1588 );
1589
1590 ImGui::RenderFrameDrawList(
1591 tdl,
1592 ImVec2(winCenter.x-sumOfAll.x*0.5-ImGui::GetStyle().ItemInnerSpacing.x,winCenter.y-sumOfAll.y*0.5-ImGui::GetStyle().ItemInnerSpacing.y),
1593 ImVec2(winCenter.x+sumOfAll.x*0.5+ImGui::GetStyle().ItemInnerSpacing.x,winCenter.y+sumOfAll.y*0.5+ImGui::GetStyle().ItemInnerSpacing.y),
1594 ImGui::GetColorU32(ImGuiCol_FrameBg),
1595 true,
1596 ImGui::GetStyle().FrameRounding
1597 );
1598
1599 float whereY=winCenter.y-sumOfAll.y*0.5;
1600
1601 tdl->AddText(
1602 bigFont,
1603 MAX(1,40*dpiScale),
1604 ImVec2(winCenter.x-warnHeadSize.x*0.5,whereY),
1605 ImGui::GetColorU32(ImGuiCol_Text),
1606 _("WARNING!!")
1607 );
1608 whereY+=warnHeadSize.y;
1609
1610 tdl->AddText(
1611 ImVec2(winCenter.x-warnTextSize1.x*0.5,whereY),
1612 ImGui::GetColorU32(ImGuiCol_Text),
1613 _("this instrument cannot be previewed because")
1614 );
1615 whereY+=warnTextSize1.y;
1616
1617 tdl->AddText(
1618 ImVec2(winCenter.x-warnTextSize2.x*0.5,whereY),
1619 ImGui::GetColorU32(ImGuiCol_Text),
1620 _("none of the chips can play it")
1621 );
1622 whereY+=warnTextSize2.y;
1623
1624 tdl->AddText(
1625 ImVec2(winCenter.x-warnTextSize3.x*0.5,whereY),
1626 ImGui::GetColorU32(ImGuiCol_Text),
1627 _("your instrument is in peril!! be careful...")
1628 );
1629 whereY+=warnTextSize3.y;
1630 }
1631 ImGui::PopFont();
1632
1633 if (fancyPattern) { // visualizer
1634 e->getCommandStream(cmdStream);
1635 ImDrawList* dl=ImGui::GetWindowDrawList();
1636 ImVec2 off=ImVec2(0.0f,0.0f);
1637
1638 ImVec2 winMin=ImGui::GetWindowPos();
1639 ImVec2 winMax=ImVec2(
1640 winMin.x+ImGui::GetWindowSize().x,
1641 winMin.y+ImGui::GetWindowSize().y
1642 );
1643
1644 // commands
1645 for (DivCommand& i: cmdStream) {
1646 if (i.cmd==DIV_CMD_PITCH) continue;
1647 if (i.cmd==DIV_CMD_NOTE_PORTA) continue;
1648 //if (i.cmd==DIV_CMD_NOTE_ON) continue;
1649 if (i.cmd==DIV_CMD_PRE_PORTA) continue;
1650 if (i.cmd==DIV_CMD_PRE_NOTE) continue;
1651 if (i.cmd==DIV_CMD_SAMPLE_BANK) continue;
1652 if (i.cmd==DIV_CMD_GET_VOLUME) continue;
1653 if (i.cmd==DIV_CMD_HINT_VOLUME ||
1654 i.cmd==DIV_CMD_HINT_PORTA ||
1655 i.cmd==DIV_CMD_HINT_LEGATO ||
1656 i.cmd==DIV_CMD_HINT_VOL_SLIDE ||
1657 i.cmd==DIV_CMD_HINT_VOL_SLIDE_TARGET ||
1658 i.cmd==DIV_CMD_HINT_ARPEGGIO ||
1659 i.cmd==DIV_CMD_HINT_PITCH ||
1660 i.cmd==DIV_CMD_HINT_VIBRATO ||
1661 i.cmd==DIV_CMD_HINT_VIBRATO_RANGE ||
1662 i.cmd==DIV_CMD_HINT_VIBRATO_SHAPE) continue;
1663
1664 float width=patChanX[i.chan+1]-patChanX[i.chan];
1665 float speedX=0.0f;
1666 float speedY=-18.0f;
1667 float grav=0.6f;
1668 float frict=1.0f;
1669 float life=255.0f;
1670 float lifeSpeed=8.0f;
1671 float spread=5.0f;
1672 int num=3;
1673 const char* partIcon=ICON_FA_MICROCHIP;
1674 ImU32* color=noteGrad;
1675
1676 switch (i.cmd) {
1677 case DIV_CMD_NOTE_ON: {
1678 float strength=CLAMP(i.value,0,119);
1679 partIcon=ICON_FA_ASTERISK;
1680 life=80.0f+((i.value==DIV_NOTE_NULL)?0.0f:(strength*0.3f));
1681 lifeSpeed=3.0f;
1682 num=6+(strength/16);
1683 break;
1684 }
1685 case DIV_CMD_LEGATO:
1686 partIcon=ICON_FA_COG;
1687 color=insGrad;
1688 life=64.0f;
1689 lifeSpeed=2.0f;
1690 break;
1691 case DIV_CMD_NOTE_OFF:
1692 case DIV_CMD_NOTE_OFF_ENV:
1693 case DIV_CMD_ENV_RELEASE:
1694 partIcon=ICON_FA_ASTERISK;
1695 speedX=0.0f;
1696 speedY=0.0f;
1697 grav=0.0f;
1698 life=24.0f;
1699 lifeSpeed=4.0f;
1700 break;
1701 case DIV_CMD_VOLUME: {
1702 float scaledVol=(float)i.value/(float)e->getMaxVolumeChan(i.chan);
1703 if (scaledVol>1.0f) scaledVol=1.0f;
1704 speedY=-18.0f-(10.0f*scaledVol);
1705 life=128+scaledVol*127;
1706 partIcon=ICON_FA_VOLUME_UP;
1707 num=12.0f*pow(scaledVol,2.0);
1708 color=volGrad;
1709 break;
1710 }
1711 case DIV_CMD_INSTRUMENT: {
1712 if (lastIns[i.chan]==i.value) {
1713 num=0;
1714 break;
1715 }
1716 lastIns[i.chan]=i.value;
1717 speedX=0.0f;
1718 speedY=0.0f;
1719 grav=0.0f;
1720 frict=0.98;
1721 spread=30.0f;
1722 life=128.0f;
1723 lifeSpeed=6.0f;
1724 color=insGrad;
1725 num=7+pow(i.value,0.6);
1726 break;
1727 }
1728 case DIV_CMD_PANNING: {
1729 float ratio=(float)(128-e->convertPanSplitToLinearLR(i.value,i.value2,256))/128.0f;
1730 logV("ratio %f",ratio);
1731 speedX=-22.0f*sin(ratio*M_PI*0.5);
1732 speedY=-22.0f*cos(ratio*M_PI*0.5);
1733 spread=5.0f+fabs(sin(ratio*M_PI*0.5))*7.0f;
1734 grav=0.0f;
1735 frict=0.96f;
1736 if (i.value==i.value2) {
1737 partIcon=ICON_FA_ARROWS_H;
1738 } else if (ratio>0) {
1739 partIcon=ICON_FA_ARROW_LEFT;
1740 } else {
1741 partIcon=ICON_FA_ARROW_RIGHT;
1742 }
1743 num=9;
1744 color=panGrad;
1745 break;
1746 }
1747 case DIV_CMD_SAMPLE_FREQ:
1748 speedX=0.0f;
1749 speedY=0.0f;
1750 grav=0.0f;
1751 frict=0.98;
1752 spread=19.0f;
1753 life=128.0f;
1754 lifeSpeed=3.0f;
1755 color=sysCmd2Grad;
1756 num=10+pow(i.value,0.6);
1757 break;
1758 default:
1759 //printf("unhandled %d\n",i.cmd);
1760 color=sysCmd1Grad;
1761 break;
1762 }
1763
1764 if (!e->curSubSong->chanShow[i.chan]) continue;
1765
1766 for (int j=0; j<num; j++) {
1767 ImVec2 partPos=ImVec2(
1768 off.x+patChanX[i.chan]+fmod(rand(),width),
1769 off.y+(playheadY)+randRange(0,PAT_FONT_SIZE)
1770 );
1771
1772 if (partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y) continue;
1773
1774 particles.push_back(Particle(
1775 color,
1776 partIcon,
1777 partPos.x,
1778 partPos.y,
1779 (speedX+randRange(-spread,spread))*0.5*dpiScale,
1780 (speedY+randRange(-spread,spread))*0.5*dpiScale,
1781 grav,
1782 frict,
1783 life-randRange(0,8),
1784 lifeSpeed
1785 ));
1786 }
1787 }
1788
1789 float frameTime=ImGui::GetIO().DeltaTime*60.0f;
1790
1791 // note slides and vibrato
1792 ImVec2 arrowPoints[7];
1793 if (e->isPlaying()) for (int i=0; i<chans; i++) {
1794 if (!e->curSubSong->chanShow[i]) continue;
1795 DivChannelState* ch=e->getChanState(i);
1796 if (ch->portaSpeed>0) {
1797 ImVec4 col=uiColors[GUI_COLOR_PATTERN_EFFECT_PITCH];
1798 col.w*=0.2;
1799 float width=patChanX[i+1]-patChanX[i];
1800
1801 ImVec2 partPos=ImVec2(
1802 off.x+patChanX[i]+fmod(rand(),width),
1803 off.y+fmod(rand(),MAX(1,ImGui::GetWindowHeight()))
1804 );
1805
1806 if (!(partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y)) {
1807 particles.push_back(Particle(
1808 pitchGrad,
1809 (ch->portaNote<=ch->note)?ICON_FA_CHEVRON_DOWN:ICON_FA_CHEVRON_UP,
1810 partPos.x,
1811 partPos.y,
1812 0.0f,
1813 (7.0f+(rand()%5)+pow(ch->portaSpeed,0.7f))*((ch->portaNote<=ch->note)?1:-1),
1814 0.0f,
1815 1.0f,
1816 255.0f,
1817 15.0f
1818 ));
1819 }
1820
1821 if (width>0.1) for (float j=-patChanSlideY[i]; j<ImGui::GetWindowHeight(); j+=width*0.7) {
1822 ImVec2 tMin=ImVec2(off.x+patChanX[i],off.y+j);
1823 ImVec2 tMax=ImVec2(off.x+patChanX[i+1],off.y+j+width*0.6);
1824 if (ch->portaNote<=ch->note) {
1825 arrowPoints[0]=ImLerp(tMin,tMax,ImVec2(0.1,1.0-0.8));
1826 arrowPoints[1]=ImLerp(tMin,tMax,ImVec2(0.5,1.0-0.0));
1827 arrowPoints[2]=ImLerp(tMin,tMax,ImVec2(0.9,1.0-0.8));
1828 arrowPoints[3]=ImLerp(tMin,tMax,ImVec2(0.8,1.0-1.0));
1829 arrowPoints[4]=ImLerp(tMin,tMax,ImVec2(0.5,1.0-0.37));
1830 arrowPoints[5]=ImLerp(tMin,tMax,ImVec2(0.2,1.0-1.0));
1831 arrowPoints[6]=arrowPoints[0];
1832 dl->AddPolyline(arrowPoints,7,ImGui::GetColorU32(col),ImDrawFlags_None,5.0f*dpiScale);
1833 } else {
1834 arrowPoints[0]=ImLerp(tMin,tMax,ImVec2(0.1,0.8));
1835 arrowPoints[1]=ImLerp(tMin,tMax,ImVec2(0.5,0.0));
1836 arrowPoints[2]=ImLerp(tMin,tMax,ImVec2(0.9,0.8));
1837 arrowPoints[3]=ImLerp(tMin,tMax,ImVec2(0.8,1.0));
1838 arrowPoints[4]=ImLerp(tMin,tMax,ImVec2(0.5,0.37));
1839 arrowPoints[5]=ImLerp(tMin,tMax,ImVec2(0.2,1.0));
1840 arrowPoints[6]=arrowPoints[0];
1841 dl->AddPolyline(arrowPoints,7,ImGui::GetColorU32(col),ImDrawFlags_None,5.0f*dpiScale);
1842 }
1843 }
1844 patChanSlideY[i]+=((ch->portaNote<=ch->note)?-8:8)*dpiScale*frameTime;
1845 if (width>0) {
1846 if (patChanSlideY[i]<0) {
1847 patChanSlideY[i]=-fmod(-patChanSlideY[i],width*0.7);
1848 } else {
1849 patChanSlideY[i]=fmod(patChanSlideY[i],width*0.7);
1850 }
1851 }
1852 }
1853 if (ch->vibratoDepth>0) {
1854 ImVec4 col=uiColors[GUI_COLOR_PATTERN_EFFECT_PITCH];
1855 col.w*=0.2;
1856 float width=patChanX[i+1]-patChanX[i];
1857
1858 ImVec2 partPos=ImVec2(
1859 off.x+patChanX[i]+(width*0.5+0.5*sin(M_PI*(float)ch->vibratoPosGiant/64.0f)*width),
1860 off.y+(ImGui::GetWindowHeight()*0.5f)+randRange(0,PAT_FONT_SIZE)
1861 );
1862
1863 if (!(partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y)) {
1864 particles.push_back(Particle(
1865 pitchGrad,
1866 ICON_FA_GLASS,
1867 partPos.x,
1868 partPos.y,
1869 randRange(-4.0f,4.0f),
1870 2.0f*(3.0f+(rand()%5)+ch->vibratoRate),
1871 0.4f,
1872 1.0f,
1873 128.0f,
1874 4.0f
1875 ));
1876 }
1877 }
1878 }
1879
1880 // particle simulation
1881 ImDrawList* fdl=ImGui::GetForegroundDrawList();
1882 if (!particles.empty()) WAKE_UP;
1883 fdl->AddCallback(_pushPartBlend,this);
1884 for (size_t i=0; i<particles.size(); i++) {
1885 Particle& part=particles[i];
1886 if (part.update(frameTime)) {
1887 if (part.life>255) part.life=255;
1888 fdl->AddText(
1889 iconFont,
1890 ICON_FONT_SIZE,
1891 ImVec2(part.pos.x-ICON_FONT_SIZE*0.5,part.pos.y-ICON_FONT_SIZE*0.5),
1892 part.colors[(int)part.life],
1893 part.type
1894 );
1895 } else {
1896 particles.erase(particles.begin()+i);
1897 i--;
1898 }
1899 }
1900 fdl->AddCallback(_popPartBlend,this);
1901 }
1902
1903 ImGui::PopStyleColor(3);
1904 ImGui::PopStyleVar();
1905 ImGui::PopFont();
1906 }
1907 ImGui::PopStyleVar();
1908 if (patternOpen) {
1909 if (!inhibitMenu && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) ImGui::OpenPopup("patternActionMenu");
1910 if (ImGui::BeginPopup("patternActionMenu",ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings)) {
1911 editOptions(false);
1912 ImGui::EndPopup();
1913 }
1914 }
1915 if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PATTERN;
1916 ImGui::End();
1917 }
1918