furnace/src/gui/pattern.cpp

1908 lines
72 KiB
C++
Raw Normal View History

2022-02-17 14:04:39 -05:00
/**
* Furnace Tracker - multi-system chiptune tracker
2025-01-28 18:49:19 -05:00
* Copyright (C) 2021-2025 tildearrow and contributors
2022-02-17 14:04:39 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
2022-09-20 02:00:31 -04:00
// for suck's fake Clang extension!
2022-02-17 14:04:39 -05:00
#define _USE_MATH_DEFINES
#include "gui.h"
#include "../ta-log.h"
2022-02-17 14:04:39 -05:00
#include "imgui_internal.h"
#include "IconsFontAwesome4.h"
2023-10-18 05:26:50 -04:00
#include "furIcons.h"
2022-02-21 03:05:00 -05:00
#include "misc/cpp/imgui_stdlib.h"
2022-02-17 14:04:39 -05:00
#include "guiConst.h"
2022-09-20 20:07:17 -04:00
#include "../utfutils.h"
2022-02-17 14:04:39 -05:00
#include <fmt/printf.h>
struct DelayedLabel {
float posCenter, posY;
ImVec2 textSize;
const char* label;
DelayedLabel(float pc, float py, ImVec2 ts, const char* l):
posCenter(pc),
posY(py),
textSize(ts),
label(l) {}
};
2022-02-17 14:04:39 -05:00
inline float randRange(float min, float max) {
return min+((float)rand()/(float)RAND_MAX)*(max-min);
}
2022-06-14 05:41:31 -04:00
void _pushPartBlend(const ImDrawList* drawList, const ImDrawCmd* cmd) {
if (cmd!=NULL) {
if (cmd->UserCallbackData!=NULL) {
((FurnaceGUI*)cmd->UserCallbackData)->pushPartBlend();
}
}
}
void _popPartBlend(const ImDrawList* drawList, const ImDrawCmd* cmd) {
if (cmd!=NULL) {
if (cmd->UserCallbackData!=NULL) {
((FurnaceGUI*)cmd->UserCallbackData)->popPartBlend();
}
}
}
void FurnaceGUI::pushPartBlend() {
rend->setBlendMode(GUI_BLEND_MODE_ADD);
2022-06-14 05:41:31 -04:00
}
void FurnaceGUI::popPartBlend() {
rend->setBlendMode(GUI_BLEND_MODE_BLEND);
2022-06-14 05:41:31 -04:00
}
2022-02-17 14:04:39 -05:00
// draw a pattern row
inline void FurnaceGUI::patternRow(int i, bool isPlaying, float lineHeight, int chans, int ord, const DivPattern** patCache, bool inhibitSel) {
static char id[64];
bool selectedRow=(
!inhibitSel &&
(ord>sel1.order || (ord==sel1.order && i>=sel1.y)) &&
(ord<sel2.order || (ord==sel2.order && i<=sel2.y))
);
2022-02-17 14:04:39 -05:00
ImGui::TableNextRow(0,lineHeight);
ImGui::TableNextColumn();
float cursorPosY=ImGui::GetCursorPos().y-ImGui::GetScrollY();
// store playhead position on the screen
if (ord==playOrder && oldRow==i) {
playheadY=ImGui::GetCursorScreenPos().y;
}
2022-02-17 14:04:39 -05:00
// check if the row is visible
if (cursorPosY<-lineHeight || cursorPosY>ImGui::GetWindowSize().y) {
return;
}
// check if we are in range
if (ord<0 || ord>=e->curSubSong->ordersLen) {
2022-02-17 14:04:39 -05:00
return;
}
if (i<0 || i>=e->curSubSong->patLen) {
2022-02-17 14:04:39 -05:00
return;
}
2025-06-28 03:17:40 -04:00
// set the top-most and bottom-most Y positions
if (topMostOrder==-1) {
topMostOrder=ord;
}
if (topMostRow==-1) {
topMostRow=i;
}
bottomMostOrder=ord;
bottomMostRow=i;
// stuff
bool isPushing=false;
ImVec4 activeColor=uiColors[GUI_COLOR_PATTERN_ACTIVE];
ImVec4 inactiveColor=uiColors[GUI_COLOR_PATTERN_INACTIVE];
ImVec4 rowIndexColor=uiColors[GUI_COLOR_PATTERN_ROW_INDEX];
if (e->curSubSong->hilightB>0 && !(i%e->curSubSong->hilightB)) {
activeColor=uiColors[GUI_COLOR_PATTERN_ACTIVE_HI2];
inactiveColor=uiColors[GUI_COLOR_PATTERN_INACTIVE_HI2];
rowIndexColor=uiColors[GUI_COLOR_PATTERN_ROW_INDEX_HI2];
} else if (e->curSubSong->hilightA>0 && !(i%e->curSubSong->hilightA)) {
activeColor=uiColors[GUI_COLOR_PATTERN_ACTIVE_HI1];
inactiveColor=uiColors[GUI_COLOR_PATTERN_INACTIVE_HI1];
rowIndexColor=uiColors[GUI_COLOR_PATTERN_ROW_INDEX_HI1];
}
2022-02-17 14:04:39 -05:00
// check overflow highlight
if (settings.overflowHighlight) {
if (edit && cursor.y==i && cursor.order==ord && curWindowLast==GUI_WINDOW_PATTERN) {
2023-10-18 01:00:23 -04:00
if (editClone && !isPatUnique && secondTimer<0.5) {
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING_CLONE]));
} else {
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING]));
}
} else if (isPlaying && oldRow==i && ord==playOrder) {
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PLAY_HEAD]));
} else if (e->curSubSong->hilightB>0 && !(i%e->curSubSong->hilightB)) {
2022-02-17 14:04:39 -05:00
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_2]));
} else if (e->curSubSong->hilightA>0 && !(i%e->curSubSong->hilightA)) {
2022-02-17 14:04:39 -05:00
ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_1]));
}
} else {
isPushing=true;
if (edit && cursor.y==i && cursor.order==ord && curWindowLast==GUI_WINDOW_PATTERN) {
2023-10-18 01:00:23 -04:00
if (editClone && !isPatUnique && secondTimer<0.5) {
ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING_CLONE]));
} else {
ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_EDITING]));
}
} else if (isPlaying && oldRow==i && ord==playOrder) {
ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PLAY_HEAD]));
} else if (e->curSubSong->hilightB>0 && !(i%e->curSubSong->hilightB)) {
ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_2]));
} else if (e->curSubSong->hilightA>0 && !(i%e->curSubSong->hilightA)) {
ImGui::PushStyleColor(ImGuiCol_Header,ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_HI_1]));
} else {
isPushing=false;
}
2022-02-17 14:04:39 -05:00
}
// row number
ImGui::PushStyleColor(ImGuiCol_Text,rowIndexColor);
2022-02-17 14:04:39 -05:00
if (settings.patRowsBase==1) {
2025-02-22 20:25:42 -05:00
snprintf(id,63," %.2X ###PR_%d",i,i);
2022-02-17 14:04:39 -05:00
} else {
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%3d ###PR_%d",i,i);
2022-02-17 14:04:39 -05:00
}
ImGui::Selectable(id,false,ImGuiSelectableFlags_NoPadWithHalfSpacing,fourChars);
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(0,0,i,ord,true);
}
if (ImGui::IsItemClicked()) {
startSelection(0,0,i,ord,true);
}
2022-12-02 16:52:47 -05:00
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
2022-12-02 04:13:26 -05:00
ImGui::InhibitInertialScroll();
NOTIFY_LONG_HOLD;
mobilePatSel=true;
2022-12-02 04:13:26 -05:00
}
ImGui::PopStyleColor();
2022-02-17 14:04:39 -05:00
// for each column
int mustSetXOf=0;
2022-02-17 14:04:39 -05:00
for (int j=0; j<chans; j++) {
// check if channel is not hidden
if (!e->curSubSong->chanShow[j]) {
2022-02-17 14:04:39 -05:00
continue;
}
int chanVolMax=e->getMaxVolumeChan(j);
if (chanVolMax<1) chanVolMax=1;
const DivPattern* pat=patCache[j];
if (!ImGui::TableNextColumn()) {
continue;
}
for (int k=mustSetXOf; k<=j; k++) {
patChanX[k]=ImGui::GetCursorScreenPos().x;
}
mustSetXOf=j+1;
2022-02-17 14:04:39 -05:00
// selection highlight flags
int sel1XSum=sel1.xCoarse*32+sel1.xFine;
int sel2XSum=sel2.xCoarse*32+sel2.xFine;
int j32=j*32;
bool selectedNote=selectedRow && (j32>=sel1XSum && j32<=sel2XSum);
bool selectedIns=selectedRow && (j32+1>=sel1XSum && j32+1<=sel2XSum);
bool selectedVol=selectedRow && (j32+2>=sel1XSum && j32+2<=sel2XSum);
bool cursorNote=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==0 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorIns=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==1 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorVol=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==2 && curWindowLast==GUI_WINDOW_PATTERN);
2022-02-17 14:04:39 -05:00
// note
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.31s###PN_%d_%d",noteName(pat->data[i][0],pat->data[i][1]),i,j);
2022-02-17 14:04:39 -05:00
if (pat->data[i][0]==0 && pat->data[i][1]==0) {
ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
2022-02-17 14:04:39 -05:00
} else {
ImGui::PushStyleColor(ImGuiCol_Text,activeColor);
2022-02-17 14:04:39 -05:00
}
if (cursorNote) {
ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,noteCellSize);
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor(3);
} else {
if (selectedNote) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,isPushing || selectedNote,ImGuiSelectableFlags_NoPadWithHalfSpacing,noteCellSize);
if (selectedNote) ImGui::PopStyleColor();
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemClicked()) {
startSelection(j,0,i,ord);
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,0,i,ord);
2022-02-17 14:04:39 -05:00
}
2022-12-02 16:52:47 -05:00
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
2022-12-02 04:13:26 -05:00
ImGui::InhibitInertialScroll();
NOTIFY_LONG_HOLD;
mobilePatSel=true;
2022-12-02 04:13:26 -05:00
}
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor();
// the following is only visible when the channel is not collapsed
if (e->curSubSong->chanCollapse[j]<3) {
2022-02-17 14:04:39 -05:00
// instrument
if (pat->data[i][2]==-1) {
ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.31s###PI_%d_%d",emptyLabel2,i,j);
2022-02-17 14:04:39 -05:00
} else {
if (pat->data[i][2]<0 || pat->data[i][2]>=e->song.insLen) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS_ERROR]);
} else {
DivInstrumentType t=e->song.ins[pat->data[i][2]]->type;
if (t!=DIV_INS_AMIGA && t!=e->getPreferInsType(j)) {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS_WARN]);
} else {
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_INS]);
}
}
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.2X###PI_%d_%d",pat->data[i][2],i,j);
2022-02-17 14:04:39 -05:00
}
ImGui::SameLine(0.0f,0.0f);
if (cursorIns) {
ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,insCellSize);
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor(3);
} else {
if (selectedIns) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,isPushing || selectedIns,ImGuiSelectableFlags_NoPadWithHalfSpacing,insCellSize);
if (selectedIns) ImGui::PopStyleColor();
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemClicked()) {
startSelection(j,1,i,ord);
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,1,i,ord);
2022-02-17 14:04:39 -05:00
}
2022-12-02 16:52:47 -05:00
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
2022-12-02 04:13:26 -05:00
ImGui::InhibitInertialScroll();
NOTIFY_LONG_HOLD;
mobilePatSel=true;
2022-12-02 04:13:26 -05:00
}
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor();
}
2022-02-17 14:04:39 -05:00
if (e->curSubSong->chanCollapse[j]<2) {
2022-02-17 14:04:39 -05:00
// volume
if (pat->data[i][3]==-1) {
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.31s###PV_%d_%d",emptyLabel2,i,j);
ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
2022-02-17 14:04:39 -05:00
} else {
int volColor=(pat->data[i][3]*127)/chanVolMax;
if (volColor>127) volColor=127;
if (volColor<0) volColor=0;
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.2X###PV_%d_%d",pat->data[i][3],i,j);
2022-02-17 14:04:39 -05:00
ImGui::PushStyleColor(ImGuiCol_Text,volColors[volColor]);
}
ImGui::SameLine(0.0f,0.0f);
if (cursorVol) {
ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,volCellSize);
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor(3);
} else {
if (selectedVol) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,isPushing || selectedVol,ImGuiSelectableFlags_NoPadWithHalfSpacing,volCellSize);
if (selectedVol) ImGui::PopStyleColor();
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemClicked()) {
startSelection(j,2,i,ord);
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,2,i,ord);
2022-02-17 14:04:39 -05:00
}
2022-12-02 16:52:47 -05:00
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
2022-12-02 04:13:26 -05:00
ImGui::InhibitInertialScroll();
NOTIFY_LONG_HOLD;
mobilePatSel=true;
2022-12-02 04:13:26 -05:00
}
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor();
}
2022-02-17 14:04:39 -05:00
if (e->curSubSong->chanCollapse[j]<1) {
2022-02-17 14:04:39 -05:00
// effects
for (int k=0; k<e->curPat[j].effectCols; k++) {
2022-02-17 14:04:39 -05:00
int index=4+(k<<1);
bool selectedEffect=selectedRow && (j32+index-1>=sel1XSum && j32+index-1<=sel2XSum);
bool selectedEffectVal=selectedRow && (j32+index>=sel1XSum && j32+index<=sel2XSum);
bool cursorEffect=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==index-1 && curWindowLast==GUI_WINDOW_PATTERN);
bool cursorEffectVal=(cursor.order==ord && cursor.y==i && cursor.xCoarse==j && cursor.xFine==index && curWindowLast==GUI_WINDOW_PATTERN);
2022-02-17 14:04:39 -05:00
// effect
if (pat->data[i][index]==-1) {
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.31s###PE%d_%d_%d",emptyLabel2,k,i,j);
ImGui::PushStyleColor(ImGuiCol_Text,inactiveColor);
2022-02-17 14:04:39 -05:00
} else {
2022-04-09 19:25:38 -04:00
if (pat->data[i][index]>0xff) {
2025-02-22 20:25:42 -05:00
snprintf(id,63,"??###PE%d_%d_%d",k,i,j);
2022-02-17 14:04:39 -05:00
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_PATTERN_EFFECT_INVALID]);
} else if (pat->data[i][index]>=0x10 || settings.oneDigitEffects==0) {
2022-04-09 19:25:38 -04:00
const unsigned char data=pat->data[i][index];
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.2X###PE%d_%d_%d",data,k,i,j);
2022-04-30 00:41:14 -04:00
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[fxColors[data]]);
} else {
const unsigned char data=pat->data[i][index];
2025-02-22 20:25:42 -05:00
snprintf(id,63," %.1X###PE%d_%d_%d",data,k,i,j);
ImGui::PushStyleColor(ImGuiCol_Text,uiColors[fxColors[data]]);
2022-02-17 14:04:39 -05:00
}
}
ImGui::SameLine(0.0f,0.0f);
if (cursorEffect) {
ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectCellSize);
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor(3);
} else {
if (selectedEffect) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,isPushing || selectedEffect,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectCellSize);
if (selectedEffect) ImGui::PopStyleColor();
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemClicked()) {
startSelection(j,index-1,i,ord);
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,index-1,i,ord);
2022-02-17 14:04:39 -05:00
}
2022-12-02 16:52:47 -05:00
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
2022-12-02 04:13:26 -05:00
ImGui::InhibitInertialScroll();
NOTIFY_LONG_HOLD;
mobilePatSel=true;
2022-12-02 04:13:26 -05:00
}
2022-02-17 14:04:39 -05:00
// effect value
if (pat->data[i][index+1]==-1) {
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.31s###PF%d_%d_%d",emptyLabel2,k,i,j);
2022-02-17 14:04:39 -05:00
} else {
2025-02-22 20:25:42 -05:00
snprintf(id,63,"%.2X###PF%d_%d_%d",pat->data[i][index+1],k,i,j);
2022-02-17 14:04:39 -05:00
}
ImGui::SameLine(0.0f,0.0f);
if (cursorEffectVal) {
ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_CURSOR]);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_CURSOR_ACTIVE]);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_CURSOR_HOVER]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectValCellSize);
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor(3);
} else {
if (selectedEffectVal) ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
2022-05-26 23:26:44 -04:00
ImGui::Selectable(id,isPushing || selectedEffectVal,ImGuiSelectableFlags_NoPadWithHalfSpacing,effectValCellSize);
if (selectedEffectVal) ImGui::PopStyleColor();
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemClicked()) {
startSelection(j,index,i,ord);
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) {
updateSelection(j,index,i,ord);
2022-02-17 14:04:39 -05:00
}
2022-12-02 16:52:47 -05:00
if (ImGui::IsItemActive() && CHECK_LONG_HOLD) {
2022-12-02 04:13:26 -05:00
ImGui::InhibitInertialScroll();
NOTIFY_LONG_HOLD;
mobilePatSel=true;
2022-12-02 04:13:26 -05:00
}
2022-02-17 14:04:39 -05:00
ImGui::PopStyleColor();
}
}
}
if (isPushing) {
ImGui::PopStyleColor();
}
2022-02-17 14:04:39 -05:00
ImGui::TableNextColumn();
for (int k=mustSetXOf; k<=chans; k++) {
patChanX[k]=ImGui::GetCursorScreenPos().x;
}
2022-02-17 14:04:39 -05:00
}
void FurnaceGUI::drawPattern() {
//int delta0=SDL_GetPerformanceCounter();
2022-02-17 14:04:39 -05:00
if (nextWindow==GUI_WINDOW_PATTERN) {
patternOpen=true;
ImGui::SetNextWindowFocus();
nextWindow=GUI_WINDOW_NOTHING;
}
if (!patternOpen) return;
2022-03-09 03:40:24 -05:00
bool inhibitMenu=false;
2023-09-20 17:16:25 -04:00
if (e->isPlaying() && followPattern) {
if (oldRowChanged || !e->isStepping()) {
if (e->isStepping()) pendingStepUpdate=1;
cursor.y=oldRow;
cursor.order=curOrder;
if (selStart.xCoarse==selEnd.xCoarse && selStart.xFine==selEnd.xFine && selStart.y==selEnd.y && selStart.order==selEnd.order && !selecting) {
2023-09-20 17:16:25 -04:00
selStart=cursor;
selEnd=cursor;
}
}
}
2022-02-17 14:04:39 -05:00
sel1=selStart;
sel2=selEnd;
if (sel2.order<sel1.order) {
sel2.order^=sel1.order;
sel1.order^=sel2.order;
sel2.order^=sel1.order;
sel2.y^=sel1.y;
sel1.y^=sel2.y;
sel2.y^=sel1.y;
} else if (sel2.order==sel1.order && sel2.y<sel1.y) {
2022-02-17 14:04:39 -05:00
sel2.y^=sel1.y;
sel1.y^=sel2.y;
sel2.y^=sel1.y;
}
if (sel2.xCoarse<sel1.xCoarse) {
sel2.xCoarse^=sel1.xCoarse;
sel1.xCoarse^=sel2.xCoarse;
sel2.xCoarse^=sel1.xCoarse;
sel2.xFine^=sel1.xFine;
sel1.xFine^=sel2.xFine;
sel2.xFine^=sel1.xFine;
} else if (sel2.xCoarse==sel1.xCoarse && sel2.xFine<sel1.xFine) {
sel2.xFine^=sel1.xFine;
sel1.xFine^=sel2.xFine;
sel2.xFine^=sel1.xFine;
}
2025-06-28 03:17:40 -04:00
/*
topMostOrder=-1;
topMostRow=-1;
bottomMostOrder=-1;
bottomMostRow=-1;
*/
2023-10-03 05:38:28 -04:00
ImVec2 origWinPadding=ImGui::GetStyle().WindowPadding;
2022-02-17 14:04:39 -05:00
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0.0f,0.0f));
2022-09-08 20:15:19 -04:00
if (mobileUI) {
2022-11-29 18:30:48 -05:00
patWindowPos=(portrait?ImVec2(0.0f,(mobileMenuPos*-0.65*canvasH)+(0.12*canvasW)):ImVec2((0.16*canvasH)+0.5*canvasW*mobileMenuPos,0.0f));
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)));
2022-09-08 20:15:19 -04:00
ImGui::SetNextWindowPos(patWindowPos);
ImGui::SetNextWindowSize(patWindowSize);
}
if (ImGui::Begin("Pattern",&patternOpen,globalWinFlags|(settings.avoidRaisingPattern?ImGuiWindowFlags_NoBringToFrontOnFocus:0)|((settings.cursorFollowsWheel && !selecting)?ImGuiWindowFlags_NoScrollWithMouse:0),_("Pattern"))) {
2022-09-08 20:15:19 -04:00
if (!mobileUI) {
patWindowPos=ImGui::GetWindowPos();
patWindowSize=ImGui::GetWindowSize();
}
2022-02-17 14:04:39 -05:00
//char id[32];
ImGui::PushFont(patFont);
int ord=curOrder;
2022-02-17 14:04:39 -05:00
int chans=e->getTotalChannelCount();
int displayChans=0;
float chanHeadBottom=0.0f;
const DivPattern* patCache[DIV_MAX_CHANS];
2022-02-17 14:04:39 -05:00
for (int i=0; i<chans; i++) {
if (e->curSubSong->chanShow[i]) displayChans++;
2022-02-17 14:04:39 -05:00
}
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding,ImVec2(0.0f,0.0f));
ImGui::PushStyleColor(ImGuiCol_Header,uiColors[GUI_COLOR_PATTERN_SELECTION]);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,uiColors[GUI_COLOR_PATTERN_SELECTION_HOVER]);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,uiColors[GUI_COLOR_PATTERN_SELECTION_ACTIVE]);
if (settings.centerPattern) {
float centerOff=(ImGui::GetContentRegionAvail().x-lastPatternWidth)*0.5;
if (centerOff>0.0f) {
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+centerOff);
}
}
if (e->isPlaying() && followPattern && (!e->isStepping() || pendingStepUpdate)) updateScroll(oldRow);
if (--pendingStepUpdate<0) pendingStepUpdate=0;
if (nextScroll>-0.5f) {
ImGui::SetNextWindowScroll(ImVec2(-1.0f,nextScroll));
nextScroll=-1.0f;
nextAddScroll=0.0f;
nextAddScrollX=0.0f;
}
ImDrawList* tdl=NULL;
if (chans<1) {
2024-05-26 20:31:17 -04:00
ImGui::Text(_("there aren't any channels to show."));
} else if (ImGui::BeginTable("PatternView",displayChans+2,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_ScrollX|ImGuiTableFlags_ScrollY|ImGuiTableFlags_NoPadInnerX|ImGuiTableFlags_NoBordersInFrozenArea|(((settings.cursorFollowsWheel && !selecting) || wheelCalmDown)?ImGuiTableFlags_NoScrollWithMouse:0))) {
2022-02-17 14:04:39 -05:00
char chanID[2048];
float lineHeight=(ImGui::GetTextLineHeight()+2*dpiScale);
// this could be moved somewhere else for performance...
float oneCharSize=ImGui::CalcTextSize("A").x;
fourChars=ImVec2(oneCharSize*4.0f,lineHeight);
threeChars=ImVec2(oneCharSize*3.0f,lineHeight);
twoChars=ImVec2(oneCharSize*2.0f,lineHeight);
oneChar=ImVec2(oneCharSize,lineHeight);
noteCellSize=threeChars;
noteCellSize.x+=(float)settings.noteCellSpacing*dpiScale;
insCellSize=twoChars;
insCellSize.x+=(float)settings.insCellSpacing*dpiScale;
volCellSize=twoChars;
volCellSize.x+=(float)settings.volCellSpacing*dpiScale;
effectCellSize=twoChars;
effectCellSize.x+=(float)settings.effectCellSpacing*dpiScale;
effectValCellSize=twoChars;
effectValCellSize.x+=(float)settings.effectValCellSpacing*dpiScale;
// and now set things up
ImGui::TableSetupColumn("pos",ImGuiTableColumnFlags_WidthFixed,fourChars.x);
2022-02-17 14:04:39 -05:00
if (nextAddScroll!=0.0f) {
float newScroll=ImGui::GetScrollY()+nextAddScroll;
2025-06-28 03:17:40 -04:00
// wrap around and go to previous/next pattern if we're about to go beyond the view
if (newScroll<0.0f && curOrder>0) {
ImGui::SetScrollY(ImGui::GetScrollMaxY()+newScroll);
if (!e->isPlaying() || !followPattern) setOrder(curOrder-1);
} else if (newScroll>ImGui::GetScrollMaxY() && curOrder<(e->curSubSong->ordersLen-1)) {
ImGui::SetScrollY(newScroll-ImGui::GetScrollMaxY());
if (!e->isPlaying() || !followPattern) setOrder(curOrder+1);
} else {
ImGui::SetScrollY(newScroll);
}
2025-06-28 03:17:40 -04:00
// select in empty space
if (nextAddScroll>0.0f) {
updateSelection(selEnd.xCoarse,selEnd.xFine,bottomMostRow,bottomMostOrder);
} else {
updateSelection(selEnd.xCoarse,selEnd.xFine,topMostRow,topMostOrder);
}
2022-02-17 14:04:39 -05:00
nextScroll=-1.0f;
nextAddScroll=0.0f;
}
if (nextAddScrollX!=0.0f) {
ImGui::SetScrollX(ImGui::GetScrollX()+nextAddScrollX);
nextAddScrollX=0.0f;
}
2022-02-17 14:04:39 -05:00
ImGui::TableSetupScrollFreeze(1,1);
for (int i=0; i<chans; i++) {
if (!e->curSubSong->chanShow[i]) continue;
float chanWidth=noteCellSize.x;
if (e->curSubSong->chanCollapse[i]<3) {
chanWidth+=insCellSize.x;
}
if (e->curSubSong->chanCollapse[i]<2) {
chanWidth+=volCellSize.x;
}
if (e->curSubSong->chanCollapse[i]<1) {
chanWidth+=(effectCellSize.x+effectValCellSize.x)*e->curPat[i].effectCols;
}
ImGui::TableSetupColumn(fmt::sprintf("c%d",i).c_str(),ImGuiTableColumnFlags_WidthFixed,chanWidth);
2022-02-17 14:04:39 -05:00
}
ImGui::TableNextRow();
ImGui::TableNextColumn();
float lpwStart=ImGui::GetCursorPosX();
2025-02-22 20:25:42 -05:00
if (ImGui::Selectable(" ++###ExtraChannelButtons",false,ImGuiSelectableFlags_NoPadWithHalfSpacing,ImVec2(0.0f,lineHeight+1.0f*dpiScale))) {
2023-10-03 05:38:28 -04:00
ImGui::OpenPopup("PatternOpt");
2022-02-17 14:04:39 -05:00
}
if (ImGui::IsItemHovered() && !mobileUI) {
2024-05-26 20:31:17 -04:00
ImGui::SetTooltip(_("click for pattern options (effect columns/pattern names/visualizer)"));
2022-02-21 17:13:21 -05:00
}
2022-02-17 14:04:39 -05:00
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
fancyPattern=!fancyPattern;
2022-03-09 03:40:24 -05:00
inhibitMenu=true;
2022-02-17 14:04:39 -05:00
e->enableCommandStream(fancyPattern);
e->getCommandStream(cmdStream);
cmdStream.clear();
}
2023-10-03 05:38:28 -04:00
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,origWinPadding);
ImGui::PushFont(mainFont);
if (ImGui::BeginPopup("PatternOpt",ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings)) {
2024-05-26 20:31:17 -04:00
ImGui::Text(_("Options:"));
2023-10-03 05:38:28 -04:00
ImGui::Indent();
2024-05-26 20:31:17 -04:00
ImGui::Checkbox(_("Effect columns/collapse"),&patExtraButtons);
ImGui::Checkbox(_("Pattern names"),&patChannelNames);
ImGui::Checkbox(_("Channel group hints"),&patChannelPairs);
if (ImGui::Checkbox(_("Visualizer"),&fancyPattern)) {
2023-10-03 05:38:28 -04:00
inhibitMenu=true;
e->enableCommandStream(fancyPattern);
e->getCommandStream(cmdStream);
cmdStream.clear();
}
ImGui::Unindent();
2024-05-26 20:31:17 -04:00
ImGui::Text(_("Channel status:"));
2023-10-03 05:38:28 -04:00
ImGui::Indent();
2025-02-22 20:25:42 -05:00
if (ImGui::RadioButton(_("No###_PCS0"),patChannelHints==0)) {
2023-10-03 05:38:28 -04:00
patChannelHints=0;
}
2025-02-22 20:25:42 -05:00
if (ImGui::RadioButton(_("Yes###_PCS1"),patChannelHints==1)) {
2023-10-03 05:38:28 -04:00
patChannelHints=1;
}
2023-10-15 20:48:20 -04:00
/*
2025-02-22 20:25:42 -05:00
if (ImGui::RadioButton(_("Regular###_PCS2"),patChannelHints==2)) {
2023-10-03 05:38:28 -04:00
patChannelHints=2;
}
2025-02-22 20:25:42 -05:00
if (ImGui::RadioButton(_("Detailed###_PCS3"),patChannelHints==3)) {
2023-10-03 05:38:28 -04:00
patChannelHints=3;
2023-10-15 20:48:20 -04:00
}*/
2023-10-03 05:38:28 -04:00
ImGui::Unindent();
ImGui::EndPopup();
}
ImGui::PopFont();
ImGui::PopStyleVar();
2022-02-17 14:04:39 -05:00
for (int i=0; i<chans; i++) {
if (!e->curSubSong->chanShow[i]) continue;
2022-02-17 14:04:39 -05:00
ImGui::TableNextColumn();
bool displayTooltip=false;
2022-09-18 04:51:10 -04:00
2022-02-17 14:04:39 -05:00
bool muted=e->isChannelMuted(i);
2022-09-18 04:51:10 -04:00
ImVec4 chanHead=muted?uiColors[GUI_COLOR_CHANNEL_MUTED]:channelColor(i);
2022-02-17 14:04:39 -05:00
ImVec4 chanHeadActive=chanHead;
ImVec4 chanHeadHover=chanHead;
2022-09-20 02:00:31 -04:00
ImVec4 chanHeadBase=chanHead;
2022-09-18 04:51:10 -04:00
2022-02-17 14:04:39 -05:00
if (e->keyHit[i]) {
keyHit1[i]=1.0f;
if (chanOscRandomPhase) {
chanOscChan[i].phaseOff=(float)rand()/(float)RAND_MAX;
} else {
chanOscChan[i].phaseOff=0.0f;
}
2022-09-18 04:51:10 -04:00
if (settings.channelFeedbackStyle==1) {
keyHit[i]=0.2;
if (!muted) {
int note=e->getChanState(i)->note+60;
if (note>=0 && note<180) {
pianoKeyHit[note]=1.0;
}
}
}
e->keyHit[i]=false;
2022-09-18 04:51:10 -04:00
}
if (settings.channelFeedbackStyle==2 && e->isRunning()) {
float amount=((float)(e->getChanState(i)->volume>>8)/(float)e->getMaxVolumeChan(i));
if (!e->getChanState(i)->keyOn) amount=0.0f;
keyHit[i]=amount*0.2f;
2022-04-13 04:24:49 -04:00
if (!muted) {
int note=e->getChanState(i)->note+60;
if (note>=0 && note<180) {
2022-09-18 04:51:10 -04:00
pianoKeyHit[note]=amount;
}
}
} else if (settings.channelFeedbackStyle==3 && e->isRunning()) {
bool active=e->getChanState(i)->keyOn;
keyHit[i]=active?0.2f:0.0f;
if (!muted) {
int note=e->getChanState(i)->note+60;
if (note>=0 && note<180) {
pianoKeyHit[note]=active?1.0f:0.0f;
2022-04-13 04:24:49 -04:00
}
}
2022-02-17 14:04:39 -05:00
}
if (settings.guiColorsBase) {
chanHead.x*=1.0-keyHit[i]; chanHead.y*=1.0-keyHit[i]; chanHead.z*=1.0-keyHit[i];
chanHeadActive.x*=0.5; chanHeadActive.y*=0.5; chanHeadActive.z*=0.5;
chanHeadHover.x*=0.9-keyHit[i]; chanHeadHover.y*=0.9-keyHit[i]; chanHeadHover.z*=0.9-keyHit[i];
} else {
chanHead.x*=0.25+keyHit[i]; chanHead.y*=0.25+keyHit[i]; chanHead.z*=0.25+keyHit[i];
chanHeadActive.x*=0.8; chanHeadActive.y*=0.8; chanHeadActive.z*=0.8;
chanHeadHover.x*=0.4+keyHit[i]; chanHeadHover.y*=0.4+keyHit[i]; chanHeadHover.z*=0.4+keyHit[i];
}
2022-09-20 02:00:31 -04:00
keyHit[i]-=((settings.channelStyle==0)?0.02:0.01)*60.0*ImGui::GetIO().DeltaTime;
2022-02-17 14:04:39 -05:00
if (keyHit[i]<0) keyHit[i]=0;
ImGui::PushStyleColor(ImGuiCol_Header,chanHead);
ImGui::PushStyleColor(ImGuiCol_HeaderActive,chanHeadActive);
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,chanHeadHover);
2022-09-18 04:51:10 -04:00
ImGui::PushStyleColor(ImGuiCol_Text,ImGui::GetColorU32(channelTextColor(i)));
2022-09-20 02:00:31 -04:00
if (settings.channelStyle==0) ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg,ImGui::GetColorU32(chanHead));
2022-02-17 14:04:39 -05:00
if (muted) ImGui::PushStyleColor(ImGuiCol_Text,uiColors[GUI_COLOR_CHANNEL_MUTED]);
2022-09-18 05:20:08 -04:00
if (settings.channelFont==0) ImGui::PushFont(mainFont);
// TODO: appearance
2022-09-20 02:00:31 -04:00
ImGuiWindow* window=ImGui::GetCurrentWindow();
ImVec2 size=ImVec2(
1.0f,
2022-09-20 20:07:17 -04:00
lineHeight+1.0f*dpiScale
2022-09-20 02:00:31 -04:00
);
ImDrawList* dl=ImGui::GetWindowDrawList();
2022-09-20 20:07:17 -04:00
if (settings.channelStyle!=0) {
size.y+=6.0f*dpiScale;
}
2022-09-20 02:00:31 -04:00
if (settings.channelStyle==2) {
size.y+=6.0f*dpiScale;
}
ImVec2 minArea=window->DC.CursorPos;
ImVec2 maxArea=ImVec2(
minArea.x+window->WorkRect.Max.x-window->WorkRect.Min.x,
minArea.y+size.y
);
ImRect rect=ImRect(minArea,maxArea);
2022-09-20 20:07:17 -04:00
float padding=ImGui::CalcTextSize("A").x;
ImVec2 minLabelArea=minArea;
ImVec2 maxLabelArea=maxArea;
if (e->curSubSong->chanCollapse[i]) {
const char* chName=e->getChannelShortName(i);
if (strlen(chName)>3) {
snprintf(chanID,2048,"...");
} else {
snprintf(chanID,2048,"%s",chName);
}
displayTooltip=true;
} else {
minLabelArea.x+=padding;
maxLabelArea.x-=padding;
2022-09-20 20:41:07 -04:00
if (settings.channelStyle==3) { // split button
maxLabelArea.x-=ImGui::GetFrameHeightWithSpacing();
}
2022-09-20 20:07:17 -04:00
const char* chName=e->getChannelName(i);
float chNameLimit=maxLabelArea.x-minLabelArea.x;
if (ImGui::CalcTextSize(chName).x>chNameLimit) {
String shortChName;
float totalAdvanced=0.0f;
float ellipsisSize=ImGui::CalcTextSize("...").x;
for (const char* j=chName; *j;) {
signed char l;
int ch=decodeUTF8((const unsigned char*)j,l);
totalAdvanced+=ImGui::GetFont()->GetCharAdvance(ch);
if (totalAdvanced>(chNameLimit-ellipsisSize)) break;
for (int k=0; k<l; k++) {
shortChName+=j[k];
}
j+=l;
}
shortChName+="...";
snprintf(chanID,2048,"%s",shortChName.c_str());
displayTooltip=true;
} else {
snprintf(chanID,2048,"%s",chName);
}
}
if (settings.channelTextCenter) {
minLabelArea.x+=0.5f*(maxLabelArea.x-minLabelArea.x-ImGui::CalcTextSize(chanID).x);
}
2023-10-03 05:38:28 -04:00
if ((!patExtraButtons && !patChannelNames && !patChannelHints) || settings.channelVolStyle!=0) ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,ImVec2(0.0f,0.0f));
2022-09-20 20:41:07 -04:00
2022-09-20 20:07:17 -04:00
ImGui::PushID(2048+i);
2022-09-20 02:00:31 -04:00
switch (settings.channelStyle) {
case 0: // classic
2022-09-20 20:07:17 -04:00
ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
2022-12-25 03:26:44 -05:00
ImU32 col=(hovered || (mobileUI && ImGui::IsMouseDown(ImGuiMouseButton_Left)))?ImGui::GetColorU32(ImGuiCol_HeaderHovered):ImGui::GetColorU32(ImGuiCol_Header);
2022-09-20 20:07:17 -04:00
dl->AddRectFilled(rect.Min,rect.Max,col);
2024-07-14 02:56:18 -04:00
dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y),ImGui::GetColorU32(channelTextColor(i)),chanID);
2022-09-20 03:32:23 -04:00
}
2022-09-20 02:00:31 -04:00
break;
case 1: { // line
ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
2022-09-20 02:00:31 -04:00
ImU32 fadeCol0=ImGui::GetColorU32(ImVec4(
chanHeadBase.x,
chanHeadBase.y,
chanHeadBase.z,
2022-12-03 00:51:57 -05:00
(hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.25f:0.0f
2022-09-20 02:00:31 -04:00
));
ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
chanHeadBase.x,
chanHeadBase.y,
chanHeadBase.z,
2022-12-03 00:51:57 -05:00
(hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.5f:MIN(1.0f,chanHeadBase.w*keyHit[i]*4.0f)
2022-09-20 02:00:31 -04:00
));
dl->AddRectFilledMultiColor(rect.Min,rect.Max,fadeCol0,fadeCol0,fadeCol,fadeCol);
dl->AddLine(ImVec2(rect.Min.x,rect.Max.y),ImVec2(rect.Max.x,rect.Max.y),ImGui::GetColorU32(chanHeadBase),2.0f*dpiScale);
2024-07-14 02:56:18 -04:00
dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
2022-09-20 02:00:31 -04:00
}
break;
}
case 2: { // round
ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
2022-09-20 02:00:31 -04:00
ImU32 fadeCol0=ImGui::GetColorU32(ImVec4(
chanHeadBase.x,
chanHeadBase.y,
chanHeadBase.z,
2022-12-03 00:51:57 -05:00
(hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.5f:MIN(1.0f,0.3f+chanHeadBase.w*keyHit[i]*1.5f)
2022-09-20 02:00:31 -04:00
));
ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
chanHeadBase.x,
chanHeadBase.y,
chanHeadBase.z,
2022-12-03 00:51:57 -05:00
(hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?0.3f:MIN(1.0f,0.2f+chanHeadBase.w*keyHit[i]*1.2f)
2022-09-20 02:00:31 -04:00
));
ImVec2 rMin=rect.Min;
ImVec2 rMax=rect.Max;
rMin.x+=3.0f*dpiScale;
rMin.y+=6.0f*dpiScale;
rMax.x-=3.0f*dpiScale;
rMax.y-=6.0f*dpiScale;
dl->AddRectFilledMultiColor(rMin,rMax,fadeCol0,fadeCol0,fadeCol,fadeCol,4.0f*dpiScale);
2024-07-14 02:56:18 -04:00
dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+6.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
2022-09-20 02:00:31 -04:00
}
break;
}
case 3: // split button
ImGui::Dummy(ImVec2(1.0f,2.0f*dpiScale));
//ImGui::SetCursorPosX(minLabelArea.x);
2024-07-14 02:56:18 -04:00
ImGui::TextNoHashHide("%s",chanID);
2022-09-20 02:00:31 -04:00
ImGui::SameLine();
ImGui::PushFont(mainFont);
ImGui::SmallButton(muted?ICON_FA_VOLUME_OFF:ICON_FA_VOLUME_UP);
ImGui::PopFont();
break;
case 4: { // square border
ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
2022-09-20 02:00:31 -04:00
ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
chanHeadBase.x,
chanHeadBase.y,
chanHeadBase.z,
2022-12-03 00:51:57 -05:00
(hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?1.0f:MIN(1.0f,0.2f+chanHeadBase.w*keyHit[i]*4.0f)
2022-09-20 02:00:31 -04:00
));
ImVec2 rMin=rect.Min;
ImVec2 rMax=rect.Max;
rMin.x+=2.0f*dpiScale;
rMin.y+=3.0f*dpiScale;
rMax.x-=3.0f*dpiScale;
rMax.y-=3.0f*dpiScale;
dl->AddRect(rMin,rMax,fadeCol,0.0f,2.0*dpiScale);
2024-07-14 02:56:18 -04:00
dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
2022-09-20 02:00:31 -04:00
}
break;
}
case 5: { // round border
ImGui::ItemSize(size,ImGui::GetStyle().FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID(chanID))) {
bool hovered=ImGui::ItemHoverable(rect,ImGui::GetID(chanID),0);
2022-09-20 02:00:31 -04:00
ImU32 fadeCol=ImGui::GetColorU32(ImVec4(
chanHeadBase.x,
chanHeadBase.y,
chanHeadBase.z,
2022-12-03 00:51:57 -05:00
(hovered && (!mobileUI || ImGui::IsMouseDown(ImGuiMouseButton_Left)))?1.0f:MIN(1.0f,0.2f+chanHeadBase.w*keyHit[i]*4.0f)
2022-09-20 02:00:31 -04:00
));
ImVec2 rMin=rect.Min;
ImVec2 rMax=rect.Max;
rMin.x+=2.0f*dpiScale;
rMin.y+=3.0f*dpiScale;
rMax.x-=3.0f*dpiScale;
rMax.y-=3.0f*dpiScale;
dl->AddRect(rMin,rMax,fadeCol,4.0f*dpiScale,ImDrawFlags_RoundCornersAll,2.0*dpiScale);
2024-07-14 02:56:18 -04:00
dl->AddTextNoHashHide(ImVec2(minLabelArea.x,rect.Min.y+3.0*dpiScale),ImGui::GetColorU32(channelTextColor(i)),chanID);
2022-09-20 02:00:31 -04:00
}
break;
}
}
2022-09-20 20:07:17 -04:00
ImGui::PopID();
2022-09-18 05:20:08 -04:00
2023-10-03 05:38:28 -04:00
if ((!patExtraButtons && !patChannelNames && !patChannelHints) || settings.channelVolStyle!=0) ImGui::PopStyleVar();
2022-09-20 20:41:07 -04:00
if (displayTooltip && ImGui::IsItemHovered() && !mobileUI) {
2022-02-17 14:04:39 -05:00
ImGui::SetTooltip("%s",e->getChannelName(i));
}
2022-09-18 05:20:08 -04:00
if (settings.channelFont==0) ImGui::PopFont();
if (mobileUI) {
if (ImGui::IsItemHovered()) {
if (CHECK_LONG_HOLD) {
NOTIFY_LONG_HOLD;
e->toggleSolo(i);
soloChan=i;
}
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::WasInertialScroll()) {
if (soloChan!=i) {
e->toggleMute(i);
} else {
soloChan=-1;
}
}
}
} else {
if (ImGui::IsItemClicked(ImGuiMouseButton_Left)) {
if (settings.soloAction!=1 && soloTimeout>0 && soloChan==i) {
e->toggleSolo(i);
soloTimeout=0;
} else {
e->toggleMute(i);
2023-01-14 14:07:50 -05:00
soloTimeout=settings.doubleClickTime;
soloChan=i;
}
2022-02-17 14:04:39 -05:00
}
}
if (muted) ImGui::PopStyleColor();
2022-09-18 04:51:10 -04:00
ImGui::PopStyleColor(4);
if (settings.soloAction!=2 && !mobileUI) if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) {
2022-03-09 03:40:24 -05:00
inhibitMenu=true;
e->toggleSolo(i);
2022-02-17 14:04:39 -05:00
}
2022-09-20 03:32:23 -04:00
2022-09-20 02:00:31 -04:00
if (settings.channelStyle==3) {
ImGui::Dummy(ImVec2(1.0f,2.0f*dpiScale));
}
2022-09-20 03:32:23 -04:00
// volume bar
if (settings.channelVolStyle!=0) {
ImVec2 sizeV=ImVec2(
1.0f,
6.0*dpiScale
);
ImVec2 minAreaV=window->DC.CursorPos;
ImVec2 maxAreaV=ImVec2(
minAreaV.x+window->WorkRect.Max.x-window->WorkRect.Min.x,
minAreaV.y+sizeV.y
);
ImRect rectV=ImRect(minAreaV,maxAreaV);
ImGui::ItemSize(sizeV,ImGui::GetStyle().FramePadding.y);
if (ImGui::ItemAdd(rectV,ImGui::GetID(chanID))) {
float xLeft=0.0f;
float xRight=1.0f;
if (e->keyHit[i]) {
keyHit1[i]=1.0f;
e->keyHit[i]=false;
2022-09-20 03:32:23 -04:00
}
if (e->isRunning()) {
2022-09-20 20:41:07 -04:00
DivChannelState* cs=e->getChanState(i);
2023-08-24 04:25:38 -04:00
unsigned short chanPan=e->getChanPan(i);
float stereoPan=(float)(e->convertPanSplitToLinear(chanPan,8,256)-128)/128.0;
2022-09-20 03:32:23 -04:00
switch (settings.channelVolStyle) {
case 1: // simple
2023-08-24 04:25:38 -04:00
xRight=((float)(cs->volume>>8)/(float)e->getMaxVolumeChan(i))*0.9+(keyHit1[i]*0.1f);
2022-09-20 03:32:23 -04:00
break;
2022-09-20 20:41:07 -04:00
case 2: { // stereo
2023-08-24 04:25:38 -04:00
float amount=((float)(cs->volume>>8)/(float)e->getMaxVolumeChan(i))*0.4+(keyHit1[i]*0.1f);
2022-09-20 20:41:07 -04:00
xRight=0.5+amount*(1.0+MIN(0.0,stereoPan));
xLeft=0.5-amount*(1.0-MAX(0.0,stereoPan));
2022-09-20 03:32:23 -04:00
break;
2022-09-20 20:41:07 -04:00
}
2022-09-20 03:32:23 -04:00
case 3: // real
xRight=chanOscVol[i];
break;
case 4: // real (stereo)
2022-09-20 20:41:07 -04:00
xRight=0.5+chanOscVol[i]*0.5*(1.0+MIN(0.0,stereoPan));
xLeft=0.5-chanOscVol[i]*0.5*(1.0-MAX(0.0,stereoPan));
2022-09-20 03:32:23 -04:00
break;
}
if (xLeft<0.0f) xLeft=0.0f;
if (xLeft>1.0f) xLeft=1.0f;
if (xRight<0.0f) xRight=0.0f;
if (xRight>1.0f) xRight=1.0f;
2022-09-20 03:32:23 -04:00
dl->AddRectFilled(
ImLerp(rectV.Min,rectV.Max,ImVec2(xLeft,0.0f)),
ImLerp(rectV.Min,rectV.Max,ImVec2(xRight,1.0f)),
ImGui::GetColorU32(chanHeadBase)
);
}
}
}
// extra buttons
2023-10-03 05:38:28 -04:00
if (patExtraButtons) {
2025-02-22 20:25:42 -05:00
snprintf(chanID,2048,"%c###_HCH%d",e->curSubSong->chanCollapse[i]?'+':'-',i);
2022-02-17 14:04:39 -05:00
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+4.0f*dpiScale);
if (ImGui::SmallButton(chanID)) {
if (e->curSubSong->chanCollapse[i]==0) {
e->curSubSong->chanCollapse[i]=3;
} else if (e->curSubSong->chanCollapse[i]>0) {
e->curSubSong->chanCollapse[i]--;
}
finishSelection();
2022-02-17 14:04:39 -05:00
}
if (!e->curSubSong->chanCollapse[i]) {
2022-02-17 14:04:39 -05:00
ImGui::SameLine();
2025-02-22 20:25:42 -05:00
snprintf(chanID,2048,"<###_LCH%d",i);
ImGui::BeginDisabled(e->curPat[i].effectCols<=1);
2022-02-17 14:04:39 -05:00
if (ImGui::SmallButton(chanID)) {
e->curPat[i].effectCols--;
if (e->curPat[i].effectCols<1) e->curPat[i].effectCols=1;
finishSelection();
2022-02-17 14:04:39 -05:00
}
ImGui::EndDisabled();
ImGui::SameLine();
ImGui::BeginDisabled(e->curPat[i].effectCols>=DIV_MAX_EFFECTS);
2025-02-22 20:25:42 -05:00
snprintf(chanID,2048,">###_RCH%d",i);
2022-02-17 14:04:39 -05:00
if (ImGui::SmallButton(chanID)) {
e->curPat[i].effectCols++;
if (e->curPat[i].effectCols>DIV_MAX_EFFECTS) e->curPat[i].effectCols=DIV_MAX_EFFECTS;
finishSelection();
2022-02-17 14:04:39 -05:00
}
ImGui::EndDisabled();
}
ImGui::Spacing();
}
2023-10-03 05:38:28 -04:00
if (patChannelNames) {
DivPattern* pat=e->curPat[i].getPattern(e->curOrders->ord[i][ord],true);
ImGui::PushFont(mainFont);
2025-02-22 20:25:42 -05:00
snprintf(chanID,2048," %s###PatName%d",pat->name.c_str(),i);
2023-10-03 05:38:28 -04:00
if (ImGui::Selectable(chanID,true,ImGuiSelectableFlags_NoPadWithHalfSpacing,ImVec2(0.0f,lineHeight+1.0f*dpiScale))) {
editStr(&pat->name);
}
ImGui::PopFont();
}
if (patChannelHints) {
2023-10-18 05:26:50 -04:00
ImGuiWindow* win=ImGui::GetCurrentWindow();
ImVec2 posMin=win->DC.CursorPos;
2023-10-15 20:48:20 -04:00
ImGui::Dummy(ImVec2(dpiScale,settings.iconSize*dpiScale));
ImVec2 posMax=ImVec2(win->WorkRect.Max.x,win->WorkRect.Max.y);
posMin.y-=ImGui::GetStyle().ItemSpacing.y*0.5;
2023-10-18 05:26:50 -04:00
ImDrawList* dl=ImGui::GetWindowDrawList();
ImVec2 iconPos[6];
2023-10-03 05:38:28 -04:00
DivChannelState* cs=e->getChanState(i);
if (cs!=NULL) {
2023-10-26 20:03:45 -04:00
DivChannelModeHints hints=e->getChanModeHints(i);
if (hints.count>4) hints.count=4;
int hintCount=3+hints.count;
// calculate icon size
for (int i=0; i<hintCount; i++) {
iconPos[i]=ImLerp(posMin,posMax,ImVec2((float)(2*i+1)/(float)(hintCount*2),0.0f));
}
2023-10-18 05:26:50 -04:00
// 1. ON/OFF
ImVec4 onOffColor;
2023-10-03 05:38:28 -04:00
if (cs->keyOn) {
if (cs->releasing) {
2023-10-18 05:26:50 -04:00
onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_REL_ON];
2023-10-03 05:38:28 -04:00
} else {
2023-10-18 05:26:50 -04:00
onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_ON];
2023-10-03 05:38:28 -04:00
}
} else {
if (cs->releasing) {
2023-10-18 05:26:50 -04:00
onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_REL];
2023-10-03 05:38:28 -04:00
} else {
2023-10-18 05:26:50 -04:00
onOffColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
2023-10-03 05:38:28 -04:00
}
}
2023-10-26 20:03:45 -04:00
iconPos[0].x-=mainFont->CalcTextSizeA(mainFont->FontSize,FLT_MAX,0.0f,ICON_FA_SQUARE).x*0.5f;
2023-10-18 05:26:50 -04:00
dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[0],ImGui::GetColorU32(onOffColor),ICON_FA_SQUARE);
2023-10-15 20:48:20 -04:00
2023-10-18 05:26:50 -04:00
// 2. PITCH SLIDE/VIBRATO
ImVec4 pitchColor;
const char* pitchIcon=ICON_FUR_SINE;
if (cs->inPorta) {
pitchIcon=ICON_FA_SHARE;
2023-10-27 05:23:35 -04:00
pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
2023-10-18 05:26:50 -04:00
} else if (cs->portaSpeed>0) {
if (cs->portaNote>=60) {
pitchIcon=ICON_FA_CHEVRON_UP;
} else {
pitchIcon=ICON_FA_CHEVRON_DOWN;
}
2023-10-27 05:23:35 -04:00
pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
2023-10-18 05:26:50 -04:00
} else if (cs->vibratoDepth>0) {
pitchIcon=ICON_FUR_SINE;
2023-10-27 05:23:35 -04:00
pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
2023-10-18 05:26:50 -04:00
} else if (cs->arp) {
pitchIcon=ICON_FA_BARS;
2023-10-27 05:23:35 -04:00
pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_NOTE];
2023-10-18 05:26:50 -04:00
} else {
2023-10-27 05:23:35 -04:00
pitchColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
2023-10-18 05:26:50 -04:00
}
2023-10-26 20:03:45 -04:00
iconPos[1].x-=mainFont->CalcTextSizeA(mainFont->FontSize,FLT_MAX,0.0f,pitchIcon).x*0.5f;
2023-10-18 05:26:50 -04:00
dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[1],ImGui::GetColorU32(pitchColor),pitchIcon);
// 3. VOLUME
ImVec4 volColor;
const char* volIcon=ICON_FA_MINUS;
if (cs->tremoloDepth>0) {
volIcon=ICON_FUR_SINE;
2023-10-27 05:23:35 -04:00
volColor=uiColors[GUI_COLOR_PATTERN_STATUS_VOLUME];
2023-10-18 05:26:50 -04:00
} else if (cs->volSpeed) {
if (cs->volSpeed>0) {
volIcon=ICON_FA_CHEVRON_UP;
} else {
volIcon=ICON_FA_CHEVRON_DOWN;
}
2023-10-27 05:23:35 -04:00
volColor=uiColors[GUI_COLOR_PATTERN_STATUS_VOLUME];
2023-10-18 05:26:50 -04:00
} else {
2023-10-27 05:23:35 -04:00
volColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
2023-10-18 05:26:50 -04:00
}
2023-10-26 20:03:45 -04:00
iconPos[2].x-=mainFont->CalcTextSizeA(mainFont->FontSize,FLT_MAX,0.0f,volIcon).x*0.5f;
2023-10-18 05:26:50 -04:00
dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[2],ImGui::GetColorU32(volColor),volIcon);
2023-10-26 20:03:45 -04:00
// 4. OTHER
for (int i=0; i<hints.count; i++) {
if (hints.hint[i]==NULL) continue;
2023-10-27 05:23:35 -04:00
ImVec4 hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
switch (hints.type[i]) {
case 0:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_OFF];
break;
case 1:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_VOLUME];
break;
case 2:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_PITCH];
break;
case 3:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_PANNING];
break;
case 4:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_SYS1];
break;
case 5:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_SYS2];
break;
case 6:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MIXING];
break;
case 7:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DSP];
break;
case 8:
2023-10-27 19:08:37 -04:00
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_NOTE];
2023-10-27 05:23:35 -04:00
break;
case 9:
2023-10-27 19:08:37 -04:00
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MISC1];
2023-10-27 05:23:35 -04:00
break;
case 10:
2023-10-27 19:08:37 -04:00
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MISC2];
break;
case 11:
2023-10-27 05:23:35 -04:00
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_MISC3];
break;
2023-10-27 19:08:37 -04:00
case 12:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_ATTACK];
break;
case 13:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DECAY];
break;
case 14:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_SUSTAIN];
break;
case 15:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_RELEASE];
break;
case 16:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DEC_LINEAR];
break;
case 17:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DEC_EXP];
break;
case 18:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_INC];
break;
case 19:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_BENT];
break;
case 20:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_DIRECT];
break;
2025-06-24 03:54:18 -04:00
case 21:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_WARNING];
break;
case 22:
hintColor=uiColors[GUI_COLOR_PATTERN_STATUS_ERROR];
break;
2023-10-27 05:23:35 -04:00
default:
hintColor=uiColors[GUI_COLOR_TEXT];
break;
}
2023-10-26 20:03:45 -04:00
iconPos[i+3].x-=mainFont->CalcTextSizeA(mainFont->FontSize,FLT_MAX,0.0f,hints.hint[i]).x*0.5f;
dl->AddText(mainFont,settings.mainFontSize*dpiScale,iconPos[i+3],ImGui::GetColorU32(hintColor),hints.hint[i]);
}
2023-10-18 05:26:50 -04:00
}
2023-10-03 05:38:28 -04:00
}
2023-10-08 05:07:26 -04:00
chanHeadBottom=ImGui::GetCursorScreenPos().y-ImGui::GetStyle().ItemSpacing.y;
2022-02-17 14:04:39 -05:00
}
ImGui::TableNextColumn();
lastPatternWidth=ImGui::GetCursorPosX()-lpwStart+ImGui::GetStyle().ScrollbarSize;
2022-02-17 14:04:39 -05:00
if (e->hasExtValue()) {
ImGui::TextColored(uiColors[GUI_COLOR_EE_VALUE]," %.2X",e->getExtValue());
2022-02-17 14:04:39 -05:00
}
2022-05-26 23:26:44 -04:00
2022-02-17 14:04:39 -05:00
dummyRows=(ImGui::GetWindowSize().y/lineHeight)/2;
2022-05-26 23:26:44 -04:00
2025-06-28 03:17:40 -04:00
topMostOrder=-1;
topMostRow=-1;
2022-02-17 14:04:39 -05:00
// オップナー2608 i owe you one more for this horrible code
// previous pattern
2022-05-24 04:49:52 -04:00
ImGui::PushStyleVar(ImGuiStyleVar_FrameShading,0.0f);
2022-02-17 14:04:39 -05:00
if (settings.viewPrevPattern) {
int viewOrder=ord;
int viewRow=-dummyRows+1;
while (viewRow<0) {
viewOrder--;
viewRow+=e->curSubSong->patLen;
}
if (viewOrder>=0 && viewOrder<e->curSubSong->ordersLen) for (int i=0; i<chans; i++) {
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][viewOrder],false);
}
2025-07-16 06:07:22 -04:00
if (orderLock) {
ImGui::BeginDisabled();
} else {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*ImGui::GetStyle().DisabledAlpha);
}
2022-02-17 14:04:39 -05:00
for (int i=0; i<dummyRows-1; i++) {
2025-07-16 06:07:22 -04:00
patternRow(viewRow,e->isPlaying(),lineHeight,chans,viewOrder,patCache,orderLock);
if (++viewRow>=e->curSubSong->patLen) {
viewRow=0;
viewOrder++;
if (viewOrder>=0 && viewOrder<e->curSubSong->ordersLen) for (int j=0; j<chans; j++) {
patCache[j]=e->curPat[j].getPattern(e->curOrders->ord[j][viewOrder],false);
}
}
2022-02-17 14:04:39 -05:00
}
2025-07-16 06:07:22 -04:00
if (orderLock) {
ImGui::EndDisabled();
} else {
ImGui::PopStyleVar();
}
2022-02-17 14:04:39 -05:00
} else {
for (int i=0; i<dummyRows-1; i++) {
ImGui::TableNextRow(0,lineHeight);
ImGui::TableNextColumn();
}
}
// active area
for (int i=0; i<chans; i++) {
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord],true);
}
for (int i=0; i<e->curSubSong->patLen; i++) {
patternRow(i,e->isPlaying(),lineHeight,chans,ord,patCache,false);
2022-02-17 14:04:39 -05:00
}
// next pattern
if (settings.viewPrevPattern) {
int viewOrder=ord+1;
int viewRow=0;
if (viewOrder<e->curSubSong->ordersLen) for (int i=0; i<chans; i++) {
patCache[i]=e->curPat[i].getPattern(e->curOrders->ord[i][ord+1],true);
}
2025-07-16 06:07:22 -04:00
if (orderLock) {
ImGui::BeginDisabled();
} else {
ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*ImGui::GetStyle().DisabledAlpha);
}
2022-02-17 14:04:39 -05:00
for (int i=0; i<=dummyRows; i++) {
2025-07-16 06:07:22 -04:00
patternRow(viewRow,e->isPlaying(),lineHeight,chans,viewOrder,patCache,orderLock);
if (++viewRow>=e->curSubSong->patLen) {
viewRow=0;
viewOrder++;
if (viewOrder>=0 && viewOrder<e->curSubSong->ordersLen) for (int j=0; j<chans; j++) {
patCache[j]=e->curPat[j].getPattern(e->curOrders->ord[j][viewOrder],false);
}
}
2022-02-17 14:04:39 -05:00
}
2025-07-16 06:07:22 -04:00
if (orderLock) {
ImGui::EndDisabled();
} else {
ImGui::PopStyleVar();
}
2022-02-17 14:04:39 -05:00
} else {
for (int i=0; i<=dummyRows; i++) {
ImGui::TableNextRow(0,lineHeight);
ImGui::TableNextColumn();
}
}
2022-05-24 04:49:52 -04:00
ImGui::PopStyleVar();
2022-02-17 14:04:39 -05:00
if (demandScrollX) {
float finalX=-fourChars.x;
// manually calculate X scroll
for (int i=0; i<=cursor.xCoarse; i++) {
int fine=(i==cursor.xCoarse)?cursor.xFine:9999;
if (!e->curSubSong->chanShow[i]) continue;
finalX+=noteCellSize.x;
// ins
if (fine==0) break;
if (e->curSubSong->chanCollapse[i]<3) {
finalX+=insCellSize.x;
}
// vol
if (fine==1) break;
if (e->curSubSong->chanCollapse[i]<2) {
finalX+=volCellSize.x;
}
// effects
if (fine==2) break;
if (e->curSubSong->chanCollapse[i]<1) {
for (int j=0; j<MIN(fine-2,e->curPat[i].effectCols*2); j++) {
if (j&1) {
finalX+=effectValCellSize.x;
} else {
finalX+=effectCellSize.x;
}
}
}
}
float totalDemand=finalX-ImGui::GetScrollX();
float availWidth=ImGui::GetWindowWidth();
if (totalDemand<(availWidth*0.25f)) {
ImGui::SetScrollX(finalX-availWidth*0.25f);
} else if (totalDemand>(availWidth*0.7f)) {
ImGui::SetScrollX(finalX-availWidth*0.7f);
2022-02-17 14:04:39 -05:00
}
demandScrollX=false;
}
2022-04-13 19:16:55 -04:00
// cursor follows wheel
if (settings.cursorFollowsWheel && (!e->isPlaying() || !followPattern || selecting) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows)) {
if (wheelX!=0 || wheelY!=0) {
int xAmount=wheelX;
int yAmount=(settings.cursorFollowsWheel==2)?wheelY:-wheelY;
if (settings.cursorWheelStep==1) {
xAmount*=MAX(1,editStep);
yAmount*=MAX(1,editStep);
}
2025-06-24 04:56:25 -04:00
if (settings.cursorWheelStep==2) {
xAmount*=MAX(1,editStepCoarse);
yAmount*=MAX(1,editStepCoarse);
}
moveCursor(xAmount,yAmount,false);
}
}
2022-04-13 19:16:55 -04:00
// overflow changes order
2023-08-22 03:30:33 -04:00
if (--wheelCalmDown<0) wheelCalmDown=0;
if (settings.scrollChangesOrder && (!e->isPlaying() || !followPattern) && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && !settings.cursorFollowsWheel && !wheelCalmDown) {
2022-04-13 19:16:55 -04:00
if (wheelY!=0) {
if (wheelY>0) {
if (ImGui::GetScrollY()<=0) {
if (haveHitBounds) {
if (curOrder>0) {
setOrder(curOrder-1);
2022-04-13 19:16:55 -04:00
ImGui::SetScrollY(ImGui::GetScrollMaxY());
updateScroll(e->curSubSong->patLen);
2023-08-22 03:30:33 -04:00
wheelCalmDown=2;
} else if (settings.scrollChangesOrder==2) {
setOrder(e->curSubSong->ordersLen-1);
ImGui::SetScrollY(ImGui::GetScrollMaxY());
updateScroll(e->curSubSong->patLen);
2023-08-22 03:30:33 -04:00
wheelCalmDown=2;
2022-04-13 19:16:55 -04:00
}
haveHitBounds=false;
} else {
haveHitBounds=true;
}
} else {
haveHitBounds=false;
}
} else {
if (ImGui::GetScrollY()>=ImGui::GetScrollMaxY()) {
if (haveHitBounds) {
if (curOrder<(e->curSubSong->ordersLen-1)) {
setOrder(curOrder+1);
2022-04-13 19:16:55 -04:00
ImGui::SetScrollY(0);
updateScroll(0);
2023-08-22 03:30:33 -04:00
wheelCalmDown=2;
} else if (settings.scrollChangesOrder==2) {
setOrder(0);
ImGui::SetScrollY(0);
updateScroll(0);
2023-08-22 03:30:33 -04:00
wheelCalmDown=2;
2022-04-13 19:16:55 -04:00
}
haveHitBounds=false;
} else {
haveHitBounds=true;
}
} else {
haveHitBounds=false;
}
}
}
}
// HACK: rendering here would cause the pairs to be drawn behind the pattern for some reason...
// ...so we capture the table's window draw list...
tdl=ImGui::GetWindowDrawList();
2022-02-17 14:04:39 -05:00
ImGui::EndTable();
}
// ...and then use it here
ImGui::PushFont(mainFont);
if (patChannelPairs && e->isRunning() && tdl!=NULL) { // pair hints
float pos=0.0f;
float posCenter=0.0f;
float posMin=FLT_MAX;
float posMax=-FLT_MAX;
ImVec2 textSize;
unsigned int floors[4][4]; // bit array
std::vector<DelayedLabel> delayedLabels;
memset(floors,0,4*4*sizeof(unsigned int));
for (int i=0; i<chans; i++) {
std::vector<DivChannelPair> pairs;
e->getChanPaired(i,pairs);
for (DivChannelPair pair: pairs) {
bool isPaired=false;
int numPairs=0;
unsigned int pairMin=i;
unsigned int pairMax=i;
unsigned char curFloor=0;
if (!e->curSubSong->chanShow[i]) {
continue;
}
for (int j=0; j<8; j++) {
if (pair.pairs[j]==-1) continue;
int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
continue;
}
isPaired=true;
if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
}
if (!isPaired) continue;
float posY=chanHeadBottom;
// find a free floor
while (curFloor<4) {
bool free=true;
for (unsigned int j=pairMin; j<=pairMax; j++) {
const unsigned int j0=j>>5;
const unsigned int j1=1U<<(j&31);
if (floors[curFloor][j0]&j1) {
free=false;
break;
}
}
if (free) break;
curFloor++;
}
if (curFloor<4) {
// occupy floor
floors[curFloor][pairMin>>5]|=1U<<(pairMin&31);
floors[curFloor][pairMax>>5]|=1U<<(pairMax&31);
}
pos=(patChanX[i+1]+patChanX[i])*0.5;
posCenter=pos;
posMin=pos;
posMax=pos;
numPairs++;
if (pair.label==NULL) {
textSize=ImGui::CalcTextSize("???");
} else {
textSize=ImGui::CalcTextSize(pair.label);
}
posY+=(textSize.y+ImGui::GetStyle().ItemSpacing.y)*curFloor;
tdl->AddLine(
ImVec2(pos,chanHeadBottom),
ImVec2(pos,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
for (int j=0; j<8; j++) {
if (pair.pairs[j]==-1) continue;
int pairCh=e->dispatchFirstChan[i]+pair.pairs[j];
if (!e->curSubSong->chanShow[pairCh]) {
continue;
}
pos=(patChanX[pairCh+1]+patChanX[pairCh])*0.5;
posCenter+=pos;
numPairs++;
if (pos<posMin) posMin=pos;
if (pos>posMax) posMax=pos;
tdl->AddLine(
ImVec2(pos,chanHeadBottom),
ImVec2(pos,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
}
posCenter/=numPairs;
if (pair.label==NULL) {
tdl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
} else {
tdl->AddLine(
ImVec2(posMin,posY+textSize.y),
ImVec2(posCenter-textSize.x*0.5-6.0f*dpiScale,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
tdl->AddLine(
ImVec2(posCenter+textSize.x*0.5+6.0f*dpiScale,posY+textSize.y),
ImVec2(posMax,posY+textSize.y),
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
2.0f*dpiScale
);
delayedLabels.push_back(DelayedLabel(posCenter,posY,textSize,pair.label));
}
}
}
for (DelayedLabel& i: delayedLabels) {
ImGui::RenderFrameDrawList(
tdl,
ImVec2(i.posCenter-i.textSize.x*0.5-6.0f*dpiScale,i.posY+i.textSize.y*0.5-3.0f*dpiScale),
ImVec2(i.posCenter+i.textSize.x*0.5+6.0f*dpiScale,i.posY+i.textSize.y*1.5+3.0f*dpiScale),
ImGui::GetColorU32(ImGuiCol_FrameBg),
true,
ImGui::GetStyle().FrameRounding
);
tdl->AddText(
ImVec2(i.posCenter-i.textSize.x*0.5,i.posY+i.textSize.y*0.5),
ImGui::GetColorU32(ImGuiCol_Text),
i.label
);
}
}
// also let's draw a warning if the instrument cannot be previewed
if (tdl!=NULL && failedNoteOn) {
ImVec2 winCenter=ImGui::GetWindowPos()+ImGui::GetWindowSize()*0.5f;
ImGui::PushFont(bigFont);
2024-05-26 20:31:17 -04:00
ImVec2 warnHeadSize=ImGui::CalcTextSize(_("WARNING!!"));
ImGui::PopFont();
2024-05-26 20:31:17 -04:00
ImVec2 warnTextSize1=ImGui::CalcTextSize(_("this instrument cannot be previewed because"));
ImVec2 warnTextSize2=ImGui::CalcTextSize(_("none of the chips can play it"));
ImVec2 warnTextSize3=ImGui::CalcTextSize(_("your instrument is in peril!! be careful..."));
float maxTextSize=warnHeadSize.x;
if (warnTextSize1.x>maxTextSize) maxTextSize=warnTextSize1.x;
if (warnTextSize2.x>maxTextSize) maxTextSize=warnTextSize2.x;
if (warnTextSize3.x>maxTextSize) maxTextSize=warnTextSize3.x;
ImVec2 sumOfAll=ImVec2(
maxTextSize,
warnHeadSize.y+warnTextSize1.y+warnTextSize2.y+warnTextSize3.y
);
ImGui::RenderFrameDrawList(
tdl,
ImVec2(winCenter.x-sumOfAll.x*0.5-ImGui::GetStyle().ItemInnerSpacing.x,winCenter.y-sumOfAll.y*0.5-ImGui::GetStyle().ItemInnerSpacing.y),
ImVec2(winCenter.x+sumOfAll.x*0.5+ImGui::GetStyle().ItemInnerSpacing.x,winCenter.y+sumOfAll.y*0.5+ImGui::GetStyle().ItemInnerSpacing.y),
ImGui::GetColorU32(ImGuiCol_FrameBg),
true,
ImGui::GetStyle().FrameRounding
);
float whereY=winCenter.y-sumOfAll.y*0.5;
tdl->AddText(
bigFont,
MAX(1,40*dpiScale),
ImVec2(winCenter.x-warnHeadSize.x*0.5,whereY),
ImGui::GetColorU32(ImGuiCol_Text),
2024-05-26 20:31:17 -04:00
_("WARNING!!")
);
whereY+=warnHeadSize.y;
tdl->AddText(
ImVec2(winCenter.x-warnTextSize1.x*0.5,whereY),
ImGui::GetColorU32(ImGuiCol_Text),
2024-05-26 20:31:17 -04:00
_("this instrument cannot be previewed because")
);
whereY+=warnTextSize1.y;
tdl->AddText(
ImVec2(winCenter.x-warnTextSize2.x*0.5,whereY),
ImGui::GetColorU32(ImGuiCol_Text),
2024-05-26 20:31:17 -04:00
_("none of the chips can play it")
);
whereY+=warnTextSize2.y;
tdl->AddText(
ImVec2(winCenter.x-warnTextSize3.x*0.5,whereY),
ImGui::GetColorU32(ImGuiCol_Text),
2024-05-26 20:31:17 -04:00
_("your instrument is in peril!! be careful...")
);
whereY+=warnTextSize3.y;
}
ImGui::PopFont();
2022-02-17 14:04:39 -05:00
if (fancyPattern) { // visualizer
e->getCommandStream(cmdStream);
ImDrawList* dl=ImGui::GetWindowDrawList();
ImVec2 off=ImVec2(0.0f,0.0f);
ImVec2 winMin=ImGui::GetWindowPos();
ImVec2 winMax=ImVec2(
winMin.x+ImGui::GetWindowSize().x,
winMin.y+ImGui::GetWindowSize().y
);
2022-02-17 14:04:39 -05:00
// commands
for (DivCommand& i: cmdStream) {
if (i.cmd==DIV_CMD_PITCH) continue;
if (i.cmd==DIV_CMD_NOTE_PORTA) continue;
//if (i.cmd==DIV_CMD_NOTE_ON) continue;
if (i.cmd==DIV_CMD_PRE_PORTA) continue;
if (i.cmd==DIV_CMD_PRE_NOTE) continue;
if (i.cmd==DIV_CMD_SAMPLE_BANK) continue;
if (i.cmd==DIV_CMD_GET_VOLUME) continue;
2022-08-16 03:07:57 -04:00
if (i.cmd==DIV_CMD_HINT_VOLUME ||
i.cmd==DIV_CMD_HINT_PORTA ||
i.cmd==DIV_CMD_HINT_LEGATO ||
i.cmd==DIV_CMD_HINT_VOL_SLIDE ||
i.cmd==DIV_CMD_HINT_VOL_SLIDE_TARGET ||
2022-08-16 03:07:57 -04:00
i.cmd==DIV_CMD_HINT_ARPEGGIO ||
i.cmd==DIV_CMD_HINT_PITCH ||
i.cmd==DIV_CMD_HINT_VIBRATO ||
i.cmd==DIV_CMD_HINT_VIBRATO_RANGE ||
i.cmd==DIV_CMD_HINT_VIBRATO_SHAPE) continue;
2022-02-17 14:04:39 -05:00
float width=patChanX[i.chan+1]-patChanX[i.chan];
float speedX=0.0f;
float speedY=-18.0f;
float grav=0.6f;
float frict=1.0f;
float life=255.0f;
float lifeSpeed=8.0f;
float spread=5.0f;
int num=3;
const char* partIcon=ICON_FA_MICROCHIP;
ImU32* color=noteGrad;
switch (i.cmd) {
2022-06-14 05:41:31 -04:00
case DIV_CMD_NOTE_ON: {
float strength=CLAMP(i.value,0,119);
2022-02-17 14:04:39 -05:00
partIcon=ICON_FA_ASTERISK;
2022-06-14 05:41:31 -04:00
life=80.0f+((i.value==DIV_NOTE_NULL)?0.0f:(strength*0.3f));
lifeSpeed=3.0f;
2022-06-14 05:41:31 -04:00
num=6+(strength/16);
2022-02-17 14:04:39 -05:00
break;
2022-06-14 05:41:31 -04:00
}
2022-02-17 14:04:39 -05:00
case DIV_CMD_LEGATO:
partIcon=ICON_FA_COG;
color=insGrad;
life=64.0f;
lifeSpeed=2.0f;
break;
case DIV_CMD_NOTE_OFF:
case DIV_CMD_NOTE_OFF_ENV:
case DIV_CMD_ENV_RELEASE:
partIcon=ICON_FA_ASTERISK;
speedX=0.0f;
speedY=0.0f;
grav=0.0f;
life=24.0f;
lifeSpeed=4.0f;
break;
case DIV_CMD_VOLUME: {
float scaledVol=(float)i.value/(float)e->getMaxVolumeChan(i.chan);
if (scaledVol>1.0f) scaledVol=1.0f;
speedY=-18.0f-(10.0f*scaledVol);
life=128+scaledVol*127;
partIcon=ICON_FA_VOLUME_UP;
num=12.0f*pow(scaledVol,2.0);
color=volGrad;
break;
}
2022-02-22 00:13:32 -05:00
case DIV_CMD_INSTRUMENT: {
if (lastIns[i.chan]==i.value) {
num=0;
break;
}
lastIns[i.chan]=i.value;
speedX=0.0f;
speedY=0.0f;
grav=0.0f;
frict=0.98;
spread=30.0f;
life=128.0f;
lifeSpeed=6.0f;
color=insGrad;
num=7+pow(i.value,0.6);
break;
}
2022-02-17 14:04:39 -05:00
case DIV_CMD_PANNING: {
2022-04-30 00:41:14 -04:00
float ratio=(float)(128-e->convertPanSplitToLinearLR(i.value,i.value2,256))/128.0f;
logV("ratio %f",ratio);
2022-02-17 14:04:39 -05:00
speedX=-22.0f*sin(ratio*M_PI*0.5);
speedY=-22.0f*cos(ratio*M_PI*0.5);
spread=5.0f+fabs(sin(ratio*M_PI*0.5))*7.0f;
grav=0.0f;
frict=0.96f;
2022-04-30 00:41:14 -04:00
if (i.value==i.value2) {
2022-02-17 14:04:39 -05:00
partIcon=ICON_FA_ARROWS_H;
} else if (ratio>0) {
partIcon=ICON_FA_ARROW_LEFT;
} else {
partIcon=ICON_FA_ARROW_RIGHT;
}
num=9;
color=panGrad;
break;
}
case DIV_CMD_SAMPLE_FREQ:
speedX=0.0f;
speedY=0.0f;
grav=0.0f;
frict=0.98;
spread=19.0f;
life=128.0f;
lifeSpeed=3.0f;
color=sysCmd2Grad;
num=10+pow(i.value,0.6);
break;
default:
//printf("unhandled %d\n",i.cmd);
color=sysCmd1Grad;
break;
}
if (!e->curSubSong->chanShow[i.chan]) continue;
2022-02-17 14:04:39 -05:00
for (int j=0; j<num; j++) {
ImVec2 partPos=ImVec2(
2023-02-21 03:15:35 -05:00
off.x+patChanX[i.chan]+fmod(rand(),width),
off.y+(playheadY)+randRange(0,patFont->FontSize)
);
if (partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y) continue;
2022-02-17 14:04:39 -05:00
particles.push_back(Particle(
color,
partIcon,
partPos.x,
partPos.y,
2022-02-17 14:04:39 -05:00
(speedX+randRange(-spread,spread))*0.5*dpiScale,
(speedY+randRange(-spread,spread))*0.5*dpiScale,
grav,
frict,
life-randRange(0,8),
lifeSpeed
));
}
}
float frameTime=ImGui::GetIO().DeltaTime*60.0f;
2022-06-14 05:41:31 -04:00
// note slides and vibrato
2022-02-17 14:04:39 -05:00
ImVec2 arrowPoints[7];
2022-02-22 00:32:13 -05:00
if (e->isPlaying()) for (int i=0; i<chans; i++) {
if (!e->curSubSong->chanShow[i]) continue;
2022-02-17 14:04:39 -05:00
DivChannelState* ch=e->getChanState(i);
if (ch->portaSpeed>0) {
ImVec4 col=uiColors[GUI_COLOR_PATTERN_EFFECT_PITCH];
col.w*=0.2;
float width=patChanX[i+1]-patChanX[i];
ImVec2 partPos=ImVec2(
2023-02-21 03:15:35 -05:00
off.x+patChanX[i]+fmod(rand(),width),
off.y+fmod(rand(),MAX(1,ImGui::GetWindowHeight()))
);
if (!(partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y)) {
particles.push_back(Particle(
pitchGrad,
(ch->portaNote<=ch->note)?ICON_FA_CHEVRON_DOWN:ICON_FA_CHEVRON_UP,
partPos.x,
partPos.y,
0.0f,
(7.0f+(rand()%5)+pow(ch->portaSpeed,0.7f))*((ch->portaNote<=ch->note)?1:-1),
0.0f,
1.0f,
255.0f,
15.0f
));
}
2022-02-17 14:04:39 -05:00
if (width>0.1) for (float j=-patChanSlideY[i]; j<ImGui::GetWindowHeight(); j+=width*0.7) {
ImVec2 tMin=ImVec2(off.x+patChanX[i],off.y+j);
ImVec2 tMax=ImVec2(off.x+patChanX[i+1],off.y+j+width*0.6);
2022-02-17 14:04:39 -05:00
if (ch->portaNote<=ch->note) {
arrowPoints[0]=ImLerp(tMin,tMax,ImVec2(0.1,1.0-0.8));
arrowPoints[1]=ImLerp(tMin,tMax,ImVec2(0.5,1.0-0.0));
arrowPoints[2]=ImLerp(tMin,tMax,ImVec2(0.9,1.0-0.8));
arrowPoints[3]=ImLerp(tMin,tMax,ImVec2(0.8,1.0-1.0));
arrowPoints[4]=ImLerp(tMin,tMax,ImVec2(0.5,1.0-0.37));
arrowPoints[5]=ImLerp(tMin,tMax,ImVec2(0.2,1.0-1.0));
arrowPoints[6]=arrowPoints[0];
dl->AddPolyline(arrowPoints,7,ImGui::GetColorU32(col),ImDrawFlags_None,5.0f*dpiScale);
} else {
arrowPoints[0]=ImLerp(tMin,tMax,ImVec2(0.1,0.8));
arrowPoints[1]=ImLerp(tMin,tMax,ImVec2(0.5,0.0));
arrowPoints[2]=ImLerp(tMin,tMax,ImVec2(0.9,0.8));
arrowPoints[3]=ImLerp(tMin,tMax,ImVec2(0.8,1.0));
arrowPoints[4]=ImLerp(tMin,tMax,ImVec2(0.5,0.37));
arrowPoints[5]=ImLerp(tMin,tMax,ImVec2(0.2,1.0));
arrowPoints[6]=arrowPoints[0];
dl->AddPolyline(arrowPoints,7,ImGui::GetColorU32(col),ImDrawFlags_None,5.0f*dpiScale);
}
}
patChanSlideY[i]+=((ch->portaNote<=ch->note)?-8:8)*dpiScale*frameTime;
2022-02-17 14:04:39 -05:00
if (width>0) {
if (patChanSlideY[i]<0) {
patChanSlideY[i]=-fmod(-patChanSlideY[i],width*0.7);
} else {
patChanSlideY[i]=fmod(patChanSlideY[i],width*0.7);
}
}
}
2022-06-14 05:41:31 -04:00
if (ch->vibratoDepth>0) {
ImVec4 col=uiColors[GUI_COLOR_PATTERN_EFFECT_PITCH];
col.w*=0.2;
float width=patChanX[i+1]-patChanX[i];
ImVec2 partPos=ImVec2(
2023-02-21 03:15:35 -05:00
off.x+patChanX[i]+(width*0.5+0.5*sin(M_PI*(float)ch->vibratoPosGiant/64.0f)*width),
off.y+(ImGui::GetWindowHeight()*0.5f)+randRange(0,patFont->FontSize)
);
if (!(partPos.x<winMin.x || partPos.y<winMin.y || partPos.x>winMax.x || partPos.y>winMax.y)) {
particles.push_back(Particle(
pitchGrad,
ICON_FA_GLASS,
partPos.x,
partPos.y,
randRange(-4.0f,4.0f),
2.0f*(3.0f+(rand()%5)+ch->vibratoRate),
0.4f,
1.0f,
128.0f,
4.0f
));
}
2022-06-14 05:41:31 -04:00
}
2022-02-17 14:04:39 -05:00
}
// particle simulation
ImDrawList* fdl=ImGui::GetForegroundDrawList();
2022-04-16 19:35:25 -04:00
if (!particles.empty()) WAKE_UP;
2022-06-14 05:41:31 -04:00
fdl->AddCallback(_pushPartBlend,this);
2022-02-17 14:04:39 -05:00
for (size_t i=0; i<particles.size(); i++) {
Particle& part=particles[i];
if (part.update(frameTime)) {
2022-02-17 14:04:39 -05:00
if (part.life>255) part.life=255;
fdl->AddText(
iconFont,
iconFont->FontSize,
ImVec2(part.pos.x-iconFont->FontSize*0.5,part.pos.y-iconFont->FontSize*0.5),
part.colors[(int)part.life],
part.type
);
} else {
particles.erase(particles.begin()+i);
i--;
}
}
2022-06-14 05:41:31 -04:00
fdl->AddCallback(_popPartBlend,this);
2022-02-17 14:04:39 -05:00
}
ImGui::PopStyleColor(3);
ImGui::PopStyleVar();
ImGui::PopFont();
}
ImGui::PopStyleVar();
2022-03-09 03:40:24 -05:00
if (patternOpen) {
if (!inhibitMenu && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) ImGui::OpenPopup("patternActionMenu");
if (ImGui::BeginPopup("patternActionMenu",ImGuiWindowFlags_NoMove|ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings)) {
editOptions(false);
2022-03-09 03:40:24 -05:00
ImGui::EndPopup();
}
}
2022-02-17 14:04:39 -05:00
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_PATTERN;
ImGui::End();
}