GUI: add a clock
This commit is contained in:
parent
baa3989502
commit
3f2f8a7197
|
@ -571,6 +571,7 @@ src/gui/guiConst.cpp
|
|||
src/gui/about.cpp
|
||||
src/gui/channels.cpp
|
||||
src/gui/chanOsc.cpp
|
||||
src/gui/clock.cpp
|
||||
src/gui/compatFlags.cpp
|
||||
src/gui/cursor.cpp
|
||||
src/gui/dataList.cpp
|
||||
|
|
|
@ -2359,6 +2359,8 @@ void DivEngine::reset() {
|
|||
shallStop=false;
|
||||
shallStopSched=false;
|
||||
pendingMetroTick=0;
|
||||
elapsedBars=0;
|
||||
elapsedBeats=0;
|
||||
nextSpeed=speed1;
|
||||
divider=60;
|
||||
if (curSubSong->customTempo) {
|
||||
|
@ -2547,6 +2549,14 @@ int DivEngine::getRow() {
|
|||
return prevRow;
|
||||
}
|
||||
|
||||
int DivEngine::getElapsedBars() {
|
||||
return elapsedBars;
|
||||
}
|
||||
|
||||
int DivEngine::getElapsedBeats() {
|
||||
return elapsedBeats;
|
||||
}
|
||||
|
||||
size_t DivEngine::getCurrentSubSong() {
|
||||
return curSubSongIndex;
|
||||
}
|
||||
|
|
|
@ -351,7 +351,7 @@ class DivEngine {
|
|||
bool midiOutClock;
|
||||
int midiOutMode;
|
||||
int softLockCount;
|
||||
int subticks, ticks, curRow, curOrder, prevRow, prevOrder, remainingLoops, totalLoops, lastLoopPos, exportLoopCount, nextSpeed;
|
||||
int subticks, ticks, curRow, curOrder, prevRow, prevOrder, remainingLoops, totalLoops, lastLoopPos, exportLoopCount, nextSpeed, elapsedBars, elapsedBeats;
|
||||
size_t curSubSongIndex;
|
||||
double divider;
|
||||
int cycles;
|
||||
|
@ -709,6 +709,10 @@ class DivEngine {
|
|||
// get current row
|
||||
int getRow();
|
||||
|
||||
// get beat/bar
|
||||
int getElapsedBars();
|
||||
int getElapsedBeats();
|
||||
|
||||
// get current subsong
|
||||
size_t getCurrentSubSong();
|
||||
|
||||
|
@ -1058,6 +1062,8 @@ class DivEngine {
|
|||
lastLoopPos(0),
|
||||
exportLoopCount(0),
|
||||
nextSpeed(3),
|
||||
elapsedBars(0),
|
||||
elapsedBeats(0),
|
||||
curSubSongIndex(0),
|
||||
divider(60),
|
||||
cycles(0),
|
||||
|
|
|
@ -964,10 +964,17 @@ void DivEngine::nextRow() {
|
|||
}
|
||||
|
||||
if (curSubSong->hilightA>0) {
|
||||
if ((curRow%curSubSong->hilightA)==0) pendingMetroTick=1;
|
||||
if ((curRow%curSubSong->hilightA)==0) {
|
||||
pendingMetroTick=1;
|
||||
elapsedBeats++;
|
||||
}
|
||||
}
|
||||
if (curSubSong->hilightB>0) {
|
||||
if ((curRow%curSubSong->hilightB)==0) pendingMetroTick=2;
|
||||
if ((curRow%curSubSong->hilightB)==0) {
|
||||
pendingMetroTick=2;
|
||||
elapsedBars++;
|
||||
elapsedBeats=0;
|
||||
}
|
||||
}
|
||||
|
||||
prevOrder=curOrder;
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "gui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "imgui.h"
|
||||
|
||||
void FurnaceGUI::drawClock() {
|
||||
if (nextWindow==GUI_WINDOW_CLOCK) {
|
||||
clockOpen=true;
|
||||
ImGui::SetNextWindowFocus();
|
||||
nextWindow=GUI_WINDOW_NOTHING;
|
||||
}
|
||||
if (!clockOpen) return;
|
||||
if (ImGui::Begin("Clock",&clockOpen,globalWinFlags)) {
|
||||
int row=e->getRow();
|
||||
int elapsedBars=e->getElapsedBars();
|
||||
int elapsedBeats=e->getElapsedBeats();
|
||||
bool playing=e->isPlaying();
|
||||
if (clockShowRow) {
|
||||
ImGui::PushFont(bigFont);
|
||||
ImGui::Text("%.3d:%.3d",e->getOrder(),row);
|
||||
ImGui::PopFont();
|
||||
}
|
||||
if (clockShowBeat) {
|
||||
ImGui::PushFont(bigFont);
|
||||
ImGui::Text("%.3d:%.1d",elapsedBars,elapsedBeats+1);
|
||||
ImGui::PopFont();
|
||||
}
|
||||
if (clockShowMetro) {
|
||||
ImDrawList* dl=ImGui::GetWindowDrawList();
|
||||
ImGuiWindow* window=ImGui::GetCurrentWindow();
|
||||
ImVec2 size=ImGui::GetContentRegionAvail();
|
||||
size.y=12.0f*dpiScale;
|
||||
|
||||
ImVec2 minArea=window->DC.CursorPos;
|
||||
ImVec2 maxArea=ImVec2(
|
||||
minArea.x+size.x,
|
||||
minArea.y+size.y
|
||||
);
|
||||
ImRect rect=ImRect(minArea,maxArea);
|
||||
/*ImRect inRect=rect;
|
||||
inRect.Min.x+=dpiScale;
|
||||
inRect.Min.y+=dpiScale;
|
||||
inRect.Max.x-=dpiScale;
|
||||
inRect.Max.y-=dpiScale;*/
|
||||
ImGuiStyle& style=ImGui::GetStyle();
|
||||
ImGui::ItemSize(size,style.FramePadding.y);
|
||||
if (ImGui::ItemAdd(rect,ImGui::GetID("metroQ"))) {
|
||||
int h1=e->curSubSong->hilightA;
|
||||
int h2=e->curSubSong->hilightB;
|
||||
if (h1>0 && h2>0) {
|
||||
int beats=(h2+(h1-1))/h1;
|
||||
if (beats<0) beats=1;
|
||||
if (beats>16) beats=16;
|
||||
if (playing) {
|
||||
if (elapsedBeats!=oldBeat || elapsedBars!=oldBar) {
|
||||
if (elapsedBeats>15) elapsedBeats=15;
|
||||
clockMetroTick[elapsedBeats]=1.0f;
|
||||
oldBeat=elapsedBeats;
|
||||
oldBar=elapsedBars;
|
||||
}
|
||||
} else {
|
||||
oldBeat=-1;
|
||||
oldBar=-1;
|
||||
}
|
||||
for (int i=0; i<beats; i++) {
|
||||
ImVec2 minB=ImLerp(minArea,maxArea,ImVec2((float)i/(float)beats,0.0f));
|
||||
ImVec2 maxB=ImLerp(minArea,maxArea,ImVec2((float)(i+1)/(float)beats,1.0f));
|
||||
ImVec4 col=ImLerp(uiColors[GUI_COLOR_CLOCK_BEAT_LOW],uiColors[GUI_COLOR_CLOCK_BEAT_HIGH],clockMetroTick[i]);
|
||||
dl->AddQuadFilled(
|
||||
ImLerp(minB,maxB,ImVec2(0.35f,0.0f)),
|
||||
ImLerp(minB,maxB,ImVec2(0.9f,0.0f)),
|
||||
ImLerp(minB,maxB,ImVec2(0.65f,1.0f)),
|
||||
ImLerp(minB,maxB,ImVec2(0.1f,1.0f)),
|
||||
ImGui::GetColorU32(col)
|
||||
);
|
||||
|
||||
if (elapsedBeats==i && playing) {
|
||||
clockMetroTick[i]-=0.1f*ImGui::GetIO().DeltaTime*60.0f;
|
||||
if (clockMetroTick[i]<0.3f) clockMetroTick[i]=0.3f;
|
||||
} else {
|
||||
clockMetroTick[i]-=0.1f*ImGui::GetIO().DeltaTime*60.0f;
|
||||
if (clockMetroTick[i]<0.0f) clockMetroTick[i]=0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clockShowTime) {
|
||||
int totalTicks=e->getTotalTicks();
|
||||
int totalSeconds=e->getTotalSeconds();
|
||||
ImGui::PushFont(bigFont);
|
||||
ImGui::Text("%.2d:%.2d.%.2d",(totalSeconds/60),totalSeconds%60,totalTicks/10000);
|
||||
ImGui::PopFont();
|
||||
}
|
||||
}
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows)) curWindow=GUI_WINDOW_SPOILER;
|
||||
ImGui::End();
|
||||
}
|
|
@ -3620,6 +3620,7 @@ bool FurnaceGUI::loop() {
|
|||
if (ImGui::MenuItem("oscilloscope (master)",BIND_FOR(GUI_ACTION_WINDOW_OSCILLOSCOPE),oscOpen)) oscOpen=!oscOpen;
|
||||
if (ImGui::MenuItem("oscilloscope (per-channel)",BIND_FOR(GUI_ACTION_WINDOW_CHAN_OSC),chanOscOpen)) chanOscOpen=!chanOscOpen;
|
||||
if (ImGui::MenuItem("volume meter",BIND_FOR(GUI_ACTION_WINDOW_VOL_METER),volMeterOpen)) volMeterOpen=!volMeterOpen;
|
||||
if (ImGui::MenuItem("clock",BIND_FOR(GUI_ACTION_WINDOW_CLOCK),clockOpen)) clockOpen=!clockOpen;
|
||||
if (ImGui::MenuItem("register view",BIND_FOR(GUI_ACTION_WINDOW_REGISTER_VIEW),regViewOpen)) regViewOpen=!regViewOpen;
|
||||
if (ImGui::MenuItem("log viewer",BIND_FOR(GUI_ACTION_WINDOW_LOG),logOpen)) logOpen=!logOpen;
|
||||
if (ImGui::MenuItem("statistics",BIND_FOR(GUI_ACTION_WINDOW_STATS),statsOpen)) statsOpen=!statsOpen;
|
||||
|
@ -3783,6 +3784,7 @@ bool FurnaceGUI::loop() {
|
|||
drawChannels();
|
||||
drawPatManager();
|
||||
drawSysManager();
|
||||
drawClock();
|
||||
drawRegView();
|
||||
drawLog();
|
||||
drawEffectList();
|
||||
|
@ -5021,6 +5023,7 @@ bool FurnaceGUI::init() {
|
|||
channelsOpen=e->getConfBool("channelsOpen",false);
|
||||
patManagerOpen=e->getConfBool("patManagerOpen",false);
|
||||
sysManagerOpen=e->getConfBool("sysManagerOpen",false);
|
||||
clockOpen=e->getConfBool("clockOpen",false);
|
||||
regViewOpen=e->getConfBool("regViewOpen",false);
|
||||
logOpen=e->getConfBool("logOpen",false);
|
||||
effectListOpen=e->getConfBool("effectListOpen",false);
|
||||
|
@ -5384,6 +5387,7 @@ bool FurnaceGUI::finish() {
|
|||
e->setConf("channelsOpen",channelsOpen);
|
||||
e->setConf("patManagerOpen",patManagerOpen);
|
||||
e->setConf("sysManagerOpen",sysManagerOpen);
|
||||
e->setConf("clockOpen",clockOpen);
|
||||
e->setConf("regViewOpen",regViewOpen);
|
||||
e->setConf("logOpen",logOpen);
|
||||
e->setConf("effectListOpen",effectListOpen);
|
||||
|
@ -5572,6 +5576,8 @@ FurnaceGUI::FurnaceGUI():
|
|||
dragSourceY(0),
|
||||
dragDestinationX(0),
|
||||
dragDestinationY(0),
|
||||
oldBeat(-1),
|
||||
oldBar(-1),
|
||||
exportFadeOut(5.0),
|
||||
editControlsOpen(true),
|
||||
ordersOpen(true),
|
||||
|
@ -5604,6 +5610,12 @@ FurnaceGUI::FurnaceGUI():
|
|||
spoilerOpen(false),
|
||||
patManagerOpen(false),
|
||||
sysManagerOpen(false),
|
||||
clockOpen(false),
|
||||
clockShowReal(true),
|
||||
clockShowRow(true),
|
||||
clockShowBeat(true),
|
||||
clockShowMetro(true),
|
||||
clockShowTime(true),
|
||||
selecting(false),
|
||||
selectingFull(false),
|
||||
dragging(false),
|
||||
|
|
|
@ -243,6 +243,10 @@ enum FurnaceGUIColors {
|
|||
GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE,
|
||||
GUI_COLOR_PIANO_KEY_TOP_ACTIVE,
|
||||
|
||||
GUI_COLOR_CLOCK_TEXT,
|
||||
GUI_COLOR_CLOCK_BEAT_LOW,
|
||||
GUI_COLOR_CLOCK_BEAT_HIGH,
|
||||
|
||||
GUI_COLOR_LOGLEVEL_ERROR,
|
||||
GUI_COLOR_LOGLEVEL_WARNING,
|
||||
GUI_COLOR_LOGLEVEL_INFO,
|
||||
|
@ -285,6 +289,7 @@ enum FurnaceGUIWindows {
|
|||
GUI_WINDOW_CHAN_OSC,
|
||||
GUI_WINDOW_SUBSONGS,
|
||||
GUI_WINDOW_FIND,
|
||||
GUI_WINDOW_CLOCK,
|
||||
GUI_WINDOW_SPOILER
|
||||
};
|
||||
|
||||
|
@ -425,6 +430,7 @@ enum FurnaceGUIActions {
|
|||
GUI_ACTION_WINDOW_CHAN_OSC,
|
||||
GUI_ACTION_WINDOW_SUBSONGS,
|
||||
GUI_ACTION_WINDOW_FIND,
|
||||
GUI_ACTION_WINDOW_CLOCK,
|
||||
|
||||
GUI_ACTION_COLLAPSE_WINDOW,
|
||||
GUI_ACTION_CLOSE_WINDOW,
|
||||
|
@ -1367,7 +1373,7 @@ class FurnaceGUI {
|
|||
|
||||
int curIns, curWave, curSample, curOctave, curOrder, prevIns, oldRow, oldOrder, oldOrder1, editStep, exportLoops, soloChan, soloTimeout, orderEditMode, orderCursor;
|
||||
int loopOrder, loopRow, loopEnd, isClipping, extraChannelButtons, patNameTarget, newSongCategory, latchTarget;
|
||||
int wheelX, wheelY, dragSourceX, dragSourceY, dragDestinationX, dragDestinationY;
|
||||
int wheelX, wheelY, dragSourceX, dragSourceY, dragDestinationX, dragDestinationY, oldBeat, oldBar;
|
||||
|
||||
double exportFadeOut;
|
||||
|
||||
|
@ -1375,7 +1381,10 @@ class FurnaceGUI {
|
|||
bool waveListOpen, waveEditOpen, sampleListOpen, sampleEditOpen, aboutOpen, settingsOpen;
|
||||
bool mixerOpen, debugOpen, inspectorOpen, oscOpen, volMeterOpen, statsOpen, compatFlagsOpen;
|
||||
bool pianoOpen, notesOpen, channelsOpen, regViewOpen, logOpen, effectListOpen, chanOscOpen;
|
||||
bool subSongsOpen, findOpen, spoilerOpen, patManagerOpen, sysManagerOpen;
|
||||
bool subSongsOpen, findOpen, spoilerOpen, patManagerOpen, sysManagerOpen, clockOpen;
|
||||
|
||||
bool clockShowReal, clockShowRow, clockShowBeat, clockShowMetro, clockShowTime;
|
||||
float clockMetroTick[16];
|
||||
|
||||
SelectionPoint selStart, selEnd, cursor, cursorDrag, dragStart, dragEnd;
|
||||
bool selecting, selectingFull, dragging, curNibble, orderNibble, followOrders, followPattern, changeAllOrders, mobileUI;
|
||||
|
@ -1717,6 +1726,7 @@ class FurnaceGUI {
|
|||
void drawSubSongs();
|
||||
void drawFindReplace();
|
||||
void drawSpoiler();
|
||||
void drawClock();
|
||||
|
||||
void parseKeybinds();
|
||||
void promptKey(int which);
|
||||
|
|
|
@ -513,6 +513,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={
|
|||
D("WINDOW_CHAN_OSC", "Oscilloscope (per-channel)", 0),
|
||||
D("WINDOW_SUBSONGS", "Subsongs", 0),
|
||||
D("WINDOW_FIND", "Find/Replace", FURKMOD_CMD|SDLK_f),
|
||||
D("WINDOW_CLOCK", "Clock", 0),
|
||||
|
||||
D("COLLAPSE_WINDOW", "Collapse/expand current window", 0),
|
||||
D("CLOSE_WINDOW", "Close current window", FURKMOD_SHIFT|SDLK_ESCAPE),
|
||||
|
@ -874,6 +875,10 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={
|
|||
D(GUI_COLOR_PIANO_KEY_BOTTOM_ACTIVE,"",ImVec4(0.5f,0.5f,0.5f,1.0f)),
|
||||
D(GUI_COLOR_PIANO_KEY_TOP_ACTIVE,"",ImVec4(0.4f,0.4f,0.4f,1.0f)),
|
||||
|
||||
D(GUI_COLOR_CLOCK_TEXT,"",ImVec4(1.0f,1.0f,1.0f,1.0f)),
|
||||
D(GUI_COLOR_CLOCK_BEAT_LOW,"",ImVec4(0.1f,0.13f,0.25f,1.0f)),
|
||||
D(GUI_COLOR_CLOCK_BEAT_HIGH,"",ImVec4(0.5f,0.8f,1.0f,1.0f)),
|
||||
|
||||
D(GUI_COLOR_LOGLEVEL_ERROR,"",ImVec4(1.0f,0.2f,0.2f,1.0f)),
|
||||
D(GUI_COLOR_LOGLEVEL_WARNING,"",ImVec4(1.0f,1.0f,0.2f,1.0f)),
|
||||
D(GUI_COLOR_LOGLEVEL_INFO,"",ImVec4(0.4f,1.0f,0.4f,1.0f)),
|
||||
|
|
Loading…
Reference in New Issue