mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-14 11:49:59 +01:00
Metronome settings and UI improvements
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -59,6 +58,13 @@ namespace ableton
|
|||||||
return sessionState.beatAtTime(now(), mQuantum);
|
return sessionState.beatAtTime(now(), mQuantum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::chrono::microseconds timeNextBeat() const
|
||||||
|
{
|
||||||
|
auto sessionState = mLink.captureAppSessionState();
|
||||||
|
double beat = ceil(sessionState.beatAtTime(now(), mQuantum));
|
||||||
|
return sessionState.timeAtBeat(beat, mQuantum);
|
||||||
|
}
|
||||||
|
|
||||||
double phaseTime() const
|
double phaseTime() const
|
||||||
{
|
{
|
||||||
auto sessionState = mLink.captureAppSessionState();
|
auto sessionState = mLink.captureAppSessionState();
|
||||||
@@ -99,12 +105,12 @@ namespace ableton
|
|||||||
mLink.enableStartStopSync(enabled);
|
mLink.enableStartStopSync(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
std::chrono::microseconds now() const
|
std::chrono::microseconds now() const
|
||||||
{
|
{
|
||||||
return mLink.clock().micros();
|
return mLink.clock().micros();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
Link& mLink;
|
Link& mLink;
|
||||||
double mQuantum;
|
double mQuantum;
|
||||||
};
|
};
|
||||||
@@ -146,7 +152,6 @@ void Metronome::terminate()
|
|||||||
link_.enable(false);
|
link_.enable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double Metronome::beats() const
|
double Metronome::beats() const
|
||||||
{
|
{
|
||||||
return engine_.beatTime();
|
return engine_.beatTime();
|
||||||
@@ -181,6 +186,11 @@ double Metronome::tempo() const
|
|||||||
return engine_.tempo();
|
return engine_.tempo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::chrono::microseconds Metronome::timeToBeat()
|
||||||
|
{
|
||||||
|
return engine_.timeNextBeat() - engine_.now();
|
||||||
|
}
|
||||||
|
|
||||||
size_t Metronome::peers() const
|
size_t Metronome::peers() const
|
||||||
{
|
{
|
||||||
return link_.numPeers();
|
return link_.numPeers();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef METRONOME_H
|
#ifndef METRONOME_H
|
||||||
#define METRONOME_H
|
#define METRONOME_H
|
||||||
|
|
||||||
#include <string>
|
#include <chrono>
|
||||||
|
|
||||||
class Metronome
|
class Metronome
|
||||||
{
|
{
|
||||||
@@ -31,6 +31,8 @@ public:
|
|||||||
void setQuantum (double q);
|
void setQuantum (double q);
|
||||||
double quantum () const;
|
double quantum () const;
|
||||||
|
|
||||||
|
std::chrono::microseconds timeToBeat();
|
||||||
|
|
||||||
size_t peers () const;
|
size_t peers () const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -170,12 +170,16 @@ struct SourceConfig
|
|||||||
|
|
||||||
struct MetronomeConfig
|
struct MetronomeConfig
|
||||||
{
|
{
|
||||||
|
bool start_stop_sync;
|
||||||
double tempo;
|
double tempo;
|
||||||
double quantum;
|
double quantum;
|
||||||
|
bool sync_tempo;
|
||||||
|
|
||||||
MetronomeConfig() {
|
MetronomeConfig() {
|
||||||
|
start_stop_sync = true;
|
||||||
tempo = 120.;
|
tempo = 120.;
|
||||||
quantum = 4.;
|
quantum = 4.;
|
||||||
|
sync_tempo = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1591,7 +1591,7 @@ void UserInterface::RenderMetrics(bool *p_open, int* p_corner, int *p_mode)
|
|||||||
ICON_FA_TACHOMETER_ALT " Performance\0"
|
ICON_FA_TACHOMETER_ALT " Performance\0"
|
||||||
ICON_FA_HOURGLASS_HALF " Timers\0"
|
ICON_FA_HOURGLASS_HALF " Timers\0"
|
||||||
ICON_FA_VECTOR_SQUARE " Source\0"
|
ICON_FA_VECTOR_SQUARE " Source\0"
|
||||||
ICON_FA_USER_CLOCK " Ableton link\0");
|
ICON_FA_USER_CLOCK " Metronome\0");
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGuiToolkit::IconButton(5,8))
|
if (ImGuiToolkit::IconButton(5,8))
|
||||||
@@ -1603,13 +1603,13 @@ void UserInterface::RenderMetrics(bool *p_open, int* p_corner, int *p_mode)
|
|||||||
double t = Metronome::manager().tempo();
|
double t = Metronome::manager().tempo();
|
||||||
double p = Metronome::manager().phase();
|
double p = Metronome::manager().phase();
|
||||||
double q = Metronome::manager().quantum();
|
double q = Metronome::manager().quantum();
|
||||||
int n = (int) Metronome::manager().peers();
|
uint n = (int) Metronome::manager().peers();
|
||||||
|
|
||||||
|
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
||||||
|
|
||||||
// tempo
|
// tempo
|
||||||
char buf[32];
|
char buf[32];
|
||||||
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
|
||||||
ImGui::Text("Tempo %.1f BPM ", t);
|
ImGui::Text("Tempo %.1f BPM ", t);
|
||||||
|
|
||||||
// network peers indicator
|
// network peers indicator
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if ( n < 1) {
|
if ( n < 1) {
|
||||||
@@ -1626,17 +1626,14 @@ void UserInterface::RenderMetrics(bool *p_open, int* p_corner, int *p_mode)
|
|||||||
ImGuiToolkit::ToolTip(buf);
|
ImGuiToolkit::ToolTip(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute and display duration of a phase
|
// compute and display duration of a phase
|
||||||
double duration = 60.0 / t * q;
|
guint64 time_phase = GST_SECOND * (60.0 * q / t) ;
|
||||||
guint64 time_phase = GST_SECOND * duration ;
|
|
||||||
ImGui::Text("Phase %s", GstToolkit::time_to_string(time_phase, GstToolkit::TIME_STRING_READABLE).c_str());
|
ImGui::Text("Phase %s", GstToolkit::time_to_string(time_phase, GstToolkit::TIME_STRING_READABLE).c_str());
|
||||||
ImGui::PopFont();
|
|
||||||
|
|
||||||
// metronome
|
// metronome
|
||||||
sprintf(buf, "%d/%d", (int)(p)+1, (int)(q) );
|
sprintf(buf, "%d/%d", (int)(p)+1, (int)(q) );
|
||||||
ImGui::ProgressBar(ceil(p)/ceil(q), ImVec2(250.f,0.f), buf);
|
ImGui::ProgressBar(ceil(p)/ceil(q), ImVec2(250.f,0.f), buf);
|
||||||
|
|
||||||
|
ImGui::PopFont();
|
||||||
}
|
}
|
||||||
else if (*p_mode > 1) {
|
else if (*p_mode > 1) {
|
||||||
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
ImGuiToolkit::PushFont(ImGuiToolkit::FONT_MONO);
|
||||||
@@ -4760,15 +4757,15 @@ void Navigator::RenderMainPannelSettings()
|
|||||||
// Metronome
|
// Metronome
|
||||||
//
|
//
|
||||||
ImGuiToolkit::Spacing();
|
ImGuiToolkit::Spacing();
|
||||||
ImGui::Text("Ableton Link");
|
ImGui::Text("Ableton link");
|
||||||
|
|
||||||
ImGuiToolkit::HelpMarker("Ableton link enables time synchronization\n "
|
ImGuiToolkit::HelpMarker("Time synchronization between computers with Ableton link\n "
|
||||||
ICON_FA_ANGLE_RIGHT " Tempo is the number of beats per minute (or set by peers).\n "
|
ICON_FA_ANGLE_RIGHT " Tempo is the number of beats per minute (or set by peers).\n "
|
||||||
ICON_FA_ANGLE_RIGHT " Quantum is the number of beats in a phase.");
|
ICON_FA_ANGLE_RIGHT " Quantum is the number of beats in a phase.");
|
||||||
ImGui::SameLine(0);
|
ImGui::SameLine(0);
|
||||||
ImGui::SetCursorPosX(-1.f * IMGUI_RIGHT_ALIGN);
|
ImGui::SetCursorPosX(-1.f * IMGUI_RIGHT_ALIGN);
|
||||||
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
||||||
int t = (int) Metronome::manager().tempo();
|
int t = (int) ceil(Metronome::manager().tempo());
|
||||||
// if no other peers, user can set a tempo
|
// if no other peers, user can set a tempo
|
||||||
if (Metronome::manager().peers() < 1) {
|
if (Metronome::manager().peers() < 1) {
|
||||||
if ( ImGui::SliderInt("Tempo", &t, 20, 240, "%d BPM") )
|
if ( ImGui::SliderInt("Tempo", &t, 20, 240, "%d BPM") )
|
||||||
@@ -4786,10 +4783,12 @@ void Navigator::RenderMainPannelSettings()
|
|||||||
|
|
||||||
ImGui::SetCursorPosX(-1.f * IMGUI_RIGHT_ALIGN);
|
ImGui::SetCursorPosX(-1.f * IMGUI_RIGHT_ALIGN);
|
||||||
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
|
||||||
int q = (int) Metronome::manager().quantum();
|
int q = (int) ceil(Metronome::manager().quantum());
|
||||||
if ( ImGui::SliderInt("Quantum", &q, 2, 100) )
|
if ( ImGui::SliderInt("Quantum", &q, 2, 100) )
|
||||||
Metronome::manager().setQuantum((double) q);
|
Metronome::manager().setQuantum((double) q);
|
||||||
|
|
||||||
|
// ImGuiToolkit::ButtonSwitch( ICON_FA_USER_CLOCK " Start/stop sync", &Settings::application.metronome.start_stop_sync);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
ImGui::Text("Expert");
|
ImGui::Text("Expert");
|
||||||
// ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_HISTORY, &Settings::application.widget.history);
|
// ImGuiToolkit::ButtonSwitch( IMGUI_TITLE_HISTORY, &Settings::application.widget.history);
|
||||||
|
|||||||
Reference in New Issue
Block a user