Skip to content

Commit

Permalink
Add option to reference clock to acquisition start
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiegle committed Sep 10, 2024
1 parent 4558e25 commit 53bbfbc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 21 deletions.
72 changes: 55 additions & 17 deletions Source/UI/ControlPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ const int SIZE_AUDIO_EDITOR_MAX_WIDTH = 500;
NewDirectoryButton::NewDirectoryButton() : Button ("NewDirectory")
{
//XmlDocument xmlDoc (R"(
// <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
// fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round"
// stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-folder-plus">
// <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 19h-7a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v3.5" />
//<path d="M16 19h6" /><path d="M19 16v6" /></svg>)");
// <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"
// fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round"
// stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-folder-plus">
// <path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 19h-7a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v3.5" />
//<path d="M16 19h6" /><path d="M19 16v6" /></svg>)");

XmlDocument xmlDoc (R"(
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" class="icon icon-tabler icons-tabler-filled icon-tabler-folder"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 3a1 1 0 0 1 .608 .206l.1 .087l2.706 2.707h6.586a3 3 0 0 1 2.995 2.824l.005 .176v8a3 3 0 0 1 -2.824 2.995l-.176 .005h-14a3 3 0 0 1 -2.995 -2.824l-.005 -.176v-11a3 3 0 0 1 2.824 -2.995l.176 -.005h4z" /></svg>)");
Expand Down Expand Up @@ -72,9 +72,9 @@ void NewDirectoryButton::paintButton (Graphics& g, bool isMouseOver, bool isButt
g.fillRoundedRectangle (0, 0, getWidth(), getHeight(), 5);
g.setColour (buttonColour);
g.fillRoundedRectangle (1, 1, getWidth() - 2, getHeight() - 2, 3);

g.setColour (Colours::black);
newDirectoryIcon->drawWithin (g, juce::Rectangle<float>(2,2.5,18,18), RectanglePlacement::centred, 1.0f);
newDirectoryIcon->drawWithin (g, juce::Rectangle<float> (2, 2.5, 18, 18), RectanglePlacement::centred, 1.0f);
g.setColour (buttonColour);
g.drawRect (10, 9, 2, 6);
g.drawRect (8, 11, 6, 2);
Expand Down Expand Up @@ -273,6 +273,7 @@ void Clock::drawTime (Graphics& g)
int64 now = Time::currentTimeMillis();
int64 diff = now - lastTime;
totalTime += diff;
latestAcquisitionTime += diff;

if (isRecording)
{
Expand All @@ -286,23 +287,34 @@ void Clock::drawTime (Graphics& g)
int s;
int h;

int64 timeToDraw;

if (referenceTime == ACQUISITION_START)
{
timeToDraw = latestAcquisitionTime;
}
else
{
if (isRecording)
timeToDraw = totalRecordingTime;
else
timeToDraw = totalTime;
}

h = floor (timeToDraw / 3600000.0f);
m = floor (timeToDraw / 60000.0);
s = floor ((timeToDraw - m * 60000.0) / 1000.0);

if (isRecording)
{
g.setColour (Colours::black);
h = floor (totalRecordingTime / 3600000.0f);
m = floor (totalRecordingTime / 60000.0);
s = floor ((totalRecordingTime - m * 60000.0) / 1000.0);
}
else
{
if (isRunning)
g.setColour (findColour (ThemeColours::controlPanelText));
else
g.setColour (findColour (ThemeColours::controlPanelText).withAlpha (0.8f));

h = floor (totalTime / 3600000.0f);
m = floor (totalTime / 60000.0);
s = floor ((totalTime - m * 60000.0) / 1000.0);
}

String timeString = "";
Expand Down Expand Up @@ -346,6 +358,11 @@ void Clock::start()
}
}

void Clock::resetAcquisitionTime()
{
latestAcquisitionTime = 0;
}

void Clock::resetRecordingTime()
{
totalRecordingTime = 0;
Expand Down Expand Up @@ -389,17 +406,27 @@ void Clock::setMode (Mode m)
repaint();
}

void Clock::setReferenceTime (ReferenceTime t)
{
referenceTime = t;

repaint();
}

void Clock::mouseDown (const MouseEvent& e)
{
if (e.mods.isRightButtonDown())
{
PopupMenu m;
m.setLookAndFeel (&getLookAndFeel());

m.addItem (1, "Clock mode", false);
m.addSeparator();
m.addItem (1, "Display mode", false);
m.addItem (2, "Default", true, mode == DEFAULT);
m.addItem (3, "HH:MM:SS", true, mode == HHMMSS);
m.addSeparator();
m.addItem (4, "Reference time", false);
m.addItem (5, "Cumulative", true, referenceTime == CUMULATIVE);
m.addItem (6, "Acquisition start", true, referenceTime == ACQUISITION_START);

int result = m.showMenu (PopupMenu::Options {}.withStandardItemHeight (20));

Expand All @@ -411,6 +438,14 @@ void Clock::mouseDown (const MouseEvent& e)
{
setMode (HHMMSS);
}
else if (result == 5)
{
setReferenceTime (CUMULATIVE);
}
else if (result == 6)
{
setReferenceTime (ACQUISITION_START);
}
}
}

Expand Down Expand Up @@ -569,7 +604,6 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
return;
}


if (audio->getSampleRate() < 44100)
{
playButton->setToggleState (false, dontSendNotification);
Expand Down Expand Up @@ -625,7 +659,9 @@ void ControlPanel::startAcquisition (bool recordingShouldAlsoStart)
recordOptionsButton->setEnabled (false);
}

clock->resetAcquisitionTime();
audio->beginCallbacks(); // starts acquisition callbacks

}
}

Expand Down Expand Up @@ -1235,6 +1271,7 @@ void ControlPanel::saveStateToXml (XmlElement* xml)
controlPanelState->setAttribute ("recordPath", filenameComponent->getCurrentFile().getFullPathName());
controlPanelState->setAttribute ("recordEngine", recordEngines[recordSelector->getSelectedId() - 1]->getID());
controlPanelState->setAttribute ("clockMode", (int) clock->getMode());
controlPanelState->setAttribute ("clockReferenceTime", (int) clock->getReferenceTime());
controlPanelState->setAttribute ("forceNewDirectory", forceNewDirectoryButton->getToggleState());

if (! isConsoleApp)
Expand Down Expand Up @@ -1267,6 +1304,7 @@ void ControlPanel::loadStateFromXml (XmlElement* xml)
}

clock->setMode ((Clock::Mode) xmlNode->getIntAttribute ("clockMode", Clock::Mode::DEFAULT));
clock->setReferenceTime ((Clock::ReferenceTime) xmlNode->getIntAttribute ("clockReferenceTime", Clock::ReferenceTime::CUMULATIVE));

bool isOpen = xmlNode->getBoolAttribute ("isOpen");
openState (isOpen);
Expand Down
17 changes: 17 additions & 0 deletions Source/UI/ControlPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ class Clock : public Component
HHMMSS
};

enum ReferenceTime
{
CUMULATIVE,
ACQUISITION_START
};

/** Constructor*/
Clock();

Expand All @@ -270,6 +276,9 @@ class Clock : public Component
/** Sets the cumulative recording time to zero.*/
void resetRecordingTime();

/** Sets the cumulative acquisition time to zero.*/
void resetAcquisitionTime();

/** Gets the current recording time */
int64 getRecordingTime() const;

Expand All @@ -282,6 +291,12 @@ class Clock : public Component
/** Gets the clock mode*/
Mode getMode() { return mode; }

/** Sets the clock reference time*/
void setReferenceTime (ReferenceTime t);

/** Gets the clock reference time */
ReferenceTime getReferenceTime() { return referenceTime; }

/** Responds to right clicks*/
void mouseDown (const MouseEvent& e);

Expand All @@ -293,13 +308,15 @@ class Clock : public Component

int64 totalTime = 0;
int64 totalRecordingTime = 0;
int64 latestAcquisitionTime = 0;

bool isRunning = false;
bool isRecording = false;

FontOptions clockFont;

Mode mode = DEFAULT;
ReferenceTime referenceTime = CUMULATIVE;
};

class UtilityButton;
Expand Down
33 changes: 29 additions & 4 deletions Source/UI/UIComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,13 @@ PopupMenu UIComponent::getMenuForIndex (int menuIndex, const String& menuName)
}
else if (menuIndex == 2)
{
PopupMenu clockMenu;
clockMenu.addCommandItem (commandManager, setClockModeDefault);
clockMenu.addCommandItem (commandManager, setClockModeHHMMSS);
PopupMenu clockModeMenu;
clockModeMenu.addCommandItem (commandManager, setClockModeDefault);
clockModeMenu.addCommandItem (commandManager, setClockModeHHMMSS);

PopupMenu clockReferenceTimeMenu;
clockReferenceTimeMenu.addCommandItem (commandManager, setClockReferenceTimeCumulative);
clockReferenceTimeMenu.addCommandItem (commandManager, setClockReferenceTimeAcqStart);

PopupMenu themeMenu;
themeMenu.addCommandItem (commandManager, setColourThemeLight);
Expand All @@ -480,7 +484,8 @@ PopupMenu UIComponent::getMenuForIndex (int menuIndex, const String& menuName)
menu.addCommandItem (commandManager, toggleGraphViewer);
menu.addCommandItem (commandManager, showMessageWindow);
menu.addSeparator();
menu.addSubMenu ("Clock mode", clockMenu);
menu.addSubMenu ("Clock display mode", clockModeMenu);
menu.addSubMenu ("Clock reference time", clockReferenceTimeMenu);
menu.addSeparator();
menu.addSubMenu ("Theme", themeMenu);
menu.addSeparator();
Expand Down Expand Up @@ -541,6 +546,8 @@ void UIComponent::getAllCommands (Array<CommandID>& commands)
showMessageWindow,
setClockModeDefault,
setClockModeHHMMSS,
setClockReferenceTimeCumulative,
setClockReferenceTimeAcqStart,
showHelp,
checkForUpdates,
resizeWindow,
Expand Down Expand Up @@ -688,6 +695,16 @@ void UIComponent::getCommandInfo (CommandID commandID, ApplicationCommandInfo& r
result.setTicked (controlPanel->clock->getMode() == Clock::HHMMSS);
break;

case setClockReferenceTimeCumulative:
result.setInfo ("Cumulative", "Set clock reference time to cumulative.", "General", 0);
result.setTicked (controlPanel->clock->getReferenceTime() == Clock::CUMULATIVE);
break;

case setClockReferenceTimeAcqStart:
result.setInfo ("Acquisition start", "Set clock to reset when acquisition starts.", "General", 0);
result.setTicked (controlPanel->clock->getReferenceTime() == Clock::ACQUISITION_START);
break;

case setColourThemeLight:
result.setInfo ("Light", "Set colour theme Light.", "General", 0);
result.setTicked (getTheme() == ColourTheme::LIGHT);
Expand Down Expand Up @@ -986,6 +1003,14 @@ bool UIComponent::perform (const InvocationInfo& info)
controlPanel->clock->setMode (Clock::HHMMSS);
break;

case setClockReferenceTimeCumulative:
controlPanel->clock->setReferenceTime (Clock::CUMULATIVE);
break;

case setClockReferenceTimeAcqStart:
controlPanel->clock->setReferenceTime (Clock::ACQUISITION_START);
break;

case setColourThemeLight:
setTheme (ColourTheme::LIGHT);
break;
Expand Down
2 changes: 2 additions & 0 deletions Source/UI/UIComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class UIComponent : public Component,
showMessageWindow = 0x2013,
setClockModeDefault = 0x2111,
setClockModeHHMMSS = 0x2112,
setClockReferenceTimeCumulative = 0x2113,
setClockReferenceTimeAcqStart = 0x2114,
toggleHttpServer = 0x4001,
showHelp = 0x2211,
checkForUpdates = 0x2222,
Expand Down

0 comments on commit 53bbfbc

Please sign in to comment.