mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-12 02:40:00 +01:00
Media player synchronicity to beat or phase
Metronome synched play, rewind and step. saving in xml.
This commit is contained in:
@@ -646,12 +646,17 @@ void MediaPlayer::play(bool on)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Metronome
|
// Metronome
|
||||||
if (metro_sync_) {
|
if (metro_sync_ > Metronome::SYNC_NONE) {
|
||||||
// busy with this play()
|
// busy with this delayed action
|
||||||
pending_ = true;
|
pending_ = true;
|
||||||
// Execute: sync to Metronome if active
|
// delayed execution function
|
||||||
Metronome::manager().executeAtBeat( std::bind([](MediaPlayer *p, bool o) {
|
std::function<void()> playlater = std::bind([](MediaPlayer *p, bool o) {
|
||||||
p->execute_play_command(o); p->pending_=false; }, this, on) );
|
p->execute_play_command(o); p->pending_=false; }, this, on);
|
||||||
|
// Execute: sync to Metronome
|
||||||
|
if (metro_sync_ > Metronome::SYNC_BEAT)
|
||||||
|
Metronome::manager().executeAtPhase( playlater );
|
||||||
|
else
|
||||||
|
Metronome::manager().executeAtBeat( playlater );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// execute immediately
|
// execute immediately
|
||||||
@@ -702,11 +707,16 @@ void MediaPlayer::rewind(bool force)
|
|||||||
|
|
||||||
// Metronome
|
// Metronome
|
||||||
if (metro_sync_) {
|
if (metro_sync_) {
|
||||||
// busy with this play()
|
// busy with this delayed action
|
||||||
pending_ = true;
|
pending_ = true;
|
||||||
// Execute: sync to Metronome if active
|
// delayed execution function
|
||||||
Metronome::manager().executeAtBeat( std::bind([](MediaPlayer *p, GstClockTime t, bool f) {
|
std::function<void()> rewindlater = std::bind([](MediaPlayer *p, GstClockTime t, bool f) {
|
||||||
p->execute_seek_command( t, f ); p->pending_=false; }, this, target, force) );
|
p->execute_seek_command( t, f ); p->pending_=false; }, this, target, force);
|
||||||
|
// Execute: sync to Metronome
|
||||||
|
if (metro_sync_ > Metronome::SYNC_BEAT)
|
||||||
|
Metronome::manager().executeAtPhase( rewindlater );
|
||||||
|
else
|
||||||
|
Metronome::manager().executeAtBeat( rewindlater );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// execute immediately
|
// execute immediately
|
||||||
@@ -729,11 +739,17 @@ void MediaPlayer::step()
|
|||||||
|
|
||||||
// Metronome
|
// Metronome
|
||||||
if (metro_sync_) {
|
if (metro_sync_) {
|
||||||
// busy with this play()
|
// busy with this delayed action
|
||||||
pending_ = true;
|
pending_ = true;
|
||||||
// Execute: sync to Metronome if active
|
// delayed execution function
|
||||||
Metronome::manager().executeAtBeat( std::bind([](MediaPlayer *p, GstEvent *e) {
|
std::function<void()> steplater = std::bind([](MediaPlayer *p, GstEvent *e) {
|
||||||
gst_element_send_event(p->pipeline_, e); p->pending_=false; }, this, stepevent) );
|
gst_element_send_event(p->pipeline_, e); p->pending_=false; }, this, stepevent) ;
|
||||||
|
// Execute: sync to Metronome
|
||||||
|
if (metro_sync_ > Metronome::SYNC_BEAT)
|
||||||
|
Metronome::manager().executeAtPhase( steplater );
|
||||||
|
else
|
||||||
|
Metronome::manager().executeAtBeat( steplater );
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// execute immediately
|
// execute immediately
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ public:
|
|||||||
* Option to synchronize with metronome
|
* Option to synchronize with metronome
|
||||||
* */
|
* */
|
||||||
inline void setSyncToMetronome(Metronome::Synchronicity s) { metro_sync_ = s; }
|
inline void setSyncToMetronome(Metronome::Synchronicity s) { metro_sync_ = s; }
|
||||||
inline Metronome::Synchronicity synchedToMetronome() const { return metro_sync_; }
|
inline Metronome::Synchronicity syncToMetronome() const { return metro_sync_; }
|
||||||
/**
|
/**
|
||||||
* Accept visitors
|
* Accept visitors
|
||||||
* */
|
* */
|
||||||
|
|||||||
@@ -75,8 +75,9 @@ namespace ableton
|
|||||||
std::chrono::microseconds timeNextPhase() const
|
std::chrono::microseconds timeNextPhase() const
|
||||||
{
|
{
|
||||||
auto sessionState = mLink.captureAppSessionState();
|
auto sessionState = mLink.captureAppSessionState();
|
||||||
double beat = ceil(sessionState.phaseAtTime(now(), mQuantum));
|
double phase = ceil(sessionState.phaseAtTime(now(), mQuantum));
|
||||||
return sessionState.timeAtBeat(beat, mQuantum);
|
double beat = ceil(sessionState.beatAtTime(now(), mQuantum));
|
||||||
|
return sessionState.timeAtBeat(beat + (mQuantum-phase), mQuantum);
|
||||||
}
|
}
|
||||||
|
|
||||||
double tempo() const
|
double tempo() const
|
||||||
|
|||||||
@@ -726,6 +726,10 @@ void SessionLoader::visit(MediaPlayer &n)
|
|||||||
mediaplayerNode->QueryBoolAttribute("rewind_on_disabled", &rewind_on_disabled);
|
mediaplayerNode->QueryBoolAttribute("rewind_on_disabled", &rewind_on_disabled);
|
||||||
n.setRewindOnDisabled(rewind_on_disabled);
|
n.setRewindOnDisabled(rewind_on_disabled);
|
||||||
|
|
||||||
|
int sync_to_metronome = 0;
|
||||||
|
mediaplayerNode->QueryIntAttribute("sync_to_metronome", &sync_to_metronome);
|
||||||
|
n.setSyncToMetronome( (Metronome::Synchronicity) sync_to_metronome);
|
||||||
|
|
||||||
bool play = true;
|
bool play = true;
|
||||||
mediaplayerNode->QueryBoolAttribute("play", &play);
|
mediaplayerNode->QueryBoolAttribute("play", &play);
|
||||||
n.play(play);
|
n.play(play);
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ void SessionVisitor::visit(MediaPlayer &n)
|
|||||||
newelement->SetAttribute("speed", n.playSpeed());
|
newelement->SetAttribute("speed", n.playSpeed());
|
||||||
newelement->SetAttribute("software_decoding", n.softwareDecodingForced());
|
newelement->SetAttribute("software_decoding", n.softwareDecodingForced());
|
||||||
newelement->SetAttribute("rewind_on_disabled", n.rewindOnDisabled());
|
newelement->SetAttribute("rewind_on_disabled", n.rewindOnDisabled());
|
||||||
|
newelement->SetAttribute("sync_to_metronome", (int) n.syncToMetronome());
|
||||||
|
|
||||||
// timeline
|
// timeline
|
||||||
XMLElement *timelineelement = xmlDoc_->NewElement("Timeline");
|
XMLElement *timelineelement = xmlDoc_->NewElement("Timeline");
|
||||||
|
|||||||
@@ -104,11 +104,8 @@ void SetNextWindowVisible(ImVec2 pos, ImVec2 size, float margin = 180.f);
|
|||||||
std::string readable_date_time_string(std::string date){
|
std::string readable_date_time_string(std::string date){
|
||||||
if (date.length()<12)
|
if (date.length()<12)
|
||||||
return "";
|
return "";
|
||||||
std::string s = date.substr(0, 12);
|
std::string s = date.substr(6, 2) + "/" + date.substr(4, 2) + "/" + date.substr(0, 4);
|
||||||
s.insert(10, ":");
|
s += " @ " + date.substr(8, 2) + ":" + date.substr(10, 2);
|
||||||
s.insert(8, " ");
|
|
||||||
s.insert(6, "/");
|
|
||||||
s.insert(4, "/");
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2472,7 +2469,7 @@ void SourceController::Render()
|
|||||||
|
|
||||||
if (ImGui::BeginMenu(ICON_FA_CLOCK " Metronome"))
|
if (ImGui::BeginMenu(ICON_FA_CLOCK " Metronome"))
|
||||||
{
|
{
|
||||||
Metronome::Synchronicity sync = mediaplayer_active_->synchedToMetronome();
|
Metronome::Synchronicity sync = mediaplayer_active_->syncToMetronome();
|
||||||
bool active = sync == Metronome::SYNC_NONE;
|
bool active = sync == Metronome::SYNC_NONE;
|
||||||
if (ImGuiToolkit::MenuItemIcon(5, 13, " Not synchronized", active ))
|
if (ImGuiToolkit::MenuItemIcon(5, 13, " Not synchronized", active ))
|
||||||
mediaplayer_active_->setSyncToMetronome(Metronome::SYNC_NONE);
|
mediaplayer_active_->setSyncToMetronome(Metronome::SYNC_NONE);
|
||||||
|
|||||||
Reference in New Issue
Block a user