From 5cc24839586cfc16e83ed3b27a9937e9c92e4861 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 6 Jan 2014 20:45:27 +0100 Subject: [PATCH] Song: added functions to maintain playback time information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now also maintain information about playback time in order to display it later. Most of the code provided by Rubén Ibarra Pastor . Further improvements by Raine M. Ekman . --- include/song.h | 51 ++++++++++++++++++++++++++++++++++++------- src/core/song.cpp | 16 ++++++++++++-- src/core/timeline.cpp | 3 ++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/include/song.h b/include/song.h index eddfe2d88..6a6a73d7c 100644 --- a/include/song.h +++ b/include/song.h @@ -1,7 +1,7 @@ /* * song.h - class song - the root of the model-tree * - * Copyright (c) 2004-2012 Tobias Doerffel + * Copyright (c) 2004-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -94,7 +94,46 @@ public: void processNextBuffer(); + inline int getMilliseconds() const + { + return m_elapsedMilliSeconds; + } + inline void setMilliSeconds( float _ellapsedMilliSeconds ) + { + m_elapsedMilliSeconds = (_ellapsedMilliSeconds); + } + inline int getTacts() const + { + return currentTact(); + } + inline int ticksPerTact() const + { + return DefaultTicksPerTact * + m_timeSigModel.getNumerator() / + m_timeSigModel.getDenominator(); + } + + // Returns the beat position inside the bar, 0-based + inline int getBeat() const + { + return (currentTick() - currentTact()*ticksPerTact()) / + (ticksPerTact() / m_timeSigModel.getNumerator() ); + } + // the remainder after bar and beat are removed + inline int getBeatTicks() const + { + return (currentTick() - currentTact()*ticksPerTact()) % + (ticksPerTact() / m_timeSigModel.getNumerator() ); + } + inline int getTicks() const + { + return currentTick(); + } + inline bool isTempoAutomated() + { + return m_tempoModel.isAutomated(); + } inline bool isPaused() const { return m_paused; @@ -260,13 +299,6 @@ private: virtual ~song(); - inline int ticksPerTact() const - { - return DefaultTicksPerTact * - m_timeSigModel.getNumerator() / - m_timeSigModel.getDenominator(); - } - inline tact_t currentTact() const { return m_playPos[m_playMode].getTact(); @@ -313,6 +345,9 @@ private: pattern * m_patternToPlay; bool m_loopPattern; + double m_elapsedMilliSeconds; + tick_t m_elapsedTicks; + tact_t m_elapsedTacts; enum Actions { diff --git a/src/core/song.cpp b/src/core/song.cpp index b8d281a0e..ee1f30fbb 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -1,7 +1,7 @@ /* * song.cpp - root of the model tree * - * Copyright (c) 2004-2013 Tobias Doerffel + * Copyright (c) 2004-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -104,6 +104,9 @@ song::song() : m_trackToPlay( NULL ), m_patternToPlay( NULL ), m_loopPattern( false ), + m_elapsedMilliSeconds( 0 ), + m_elapsedTicks( 0 ), + m_elapsedTacts( 0 ), m_shmID( -1 ), m_SncVSTplug( NULL ), m_shmQtID( "/usr/bin/lmms" ) @@ -179,7 +182,6 @@ song::song() : this, SLOT( masterPitchChanged() ) );*/ qRegisterMetaType( "note" ); - } @@ -285,6 +287,7 @@ void song::doActions() { case timeLine::BackToZero: m_playPos[m_playMode].setTicks( 0 ); + m_elapsedMilliSeconds = 0; break; case timeLine::BackToStart: @@ -292,6 +295,7 @@ void song::doActions() { m_playPos[m_playMode].setTicks( tl->savedPos().getTicks() ); + m_elapsedMilliSeconds = (((tl->savedPos().getTicks())*60*1000/48)/getTempo()); tl->savePos( -1 ); } break; @@ -305,6 +309,7 @@ void song::doActions() else { m_playPos[m_playMode].setTicks( 0 ); + m_elapsedMilliSeconds = 0; } m_playPos[m_playMode].setCurrentFrame( 0 ); @@ -454,6 +459,7 @@ void song::processNextBuffer() if( m_playPos[m_playMode] < tl->loopBegin() || m_playPos[m_playMode] >= tl->loopEnd() ) { + m_elapsedMilliSeconds = (tl->loopBegin().getTicks()*60*1000/48)/getTempo(); m_playPos[m_playMode].setTicks( tl->loopBegin().getTicks() ); } @@ -546,6 +552,7 @@ void song::processNextBuffer() { m_playPos[m_playMode].setTicks( tl->loopBegin().getTicks() ); + m_elapsedMilliSeconds = ((tl->loopBegin().getTicks())*60*1000/48)/getTempo(); } } else @@ -599,6 +606,9 @@ void song::processNextBuffer() total_frames_played += played_frames; m_playPos[m_playMode].setCurrentFrame( played_frames + current_frame ); + m_elapsedMilliSeconds += (((played_frames/frames_per_tick)*60*1000/48)/getTempo()); + m_elapsedTacts = m_playPos[Mode_PlaySong].getTact(); + m_elapsedTicks = (m_playPos[Mode_PlaySong].getTicks()%ticksPerTact())/48; } } @@ -733,6 +743,8 @@ void song::updateLength() void song::setPlayPos( tick_t _ticks, PlayModes _play_mode ) { + m_elapsedTicks += m_playPos[_play_mode].getTicks() - _ticks; + m_elapsedMilliSeconds += (((( _ticks - m_playPos[_play_mode].getTicks()))*60*1000/48)/getTempo()); m_playPos[_play_mode].setTicks( _ticks ); m_playPos[_play_mode].setCurrentFrame( 0.0f ); } diff --git a/src/core/timeline.cpp b/src/core/timeline.cpp index f3dc59d6f..11aed487f 100644 --- a/src/core/timeline.cpp +++ b/src/core/timeline.cpp @@ -1,7 +1,7 @@ /* * timeline.cpp - class timeLine, representing a time-line with position marker * - * Copyright (c) 2004-2008 Tobias Doerffel + * Copyright (c) 2004-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -324,6 +324,7 @@ void timeLine::mouseMoveEvent( QMouseEvent * _me ) { case MovePositionMarker: m_pos.setTicks( t.getTicks() ); + engine::getSong()->setMilliSeconds(((((t.getTicks()))*60*1000/48)/engine::getSong()->getTempo())); m_pos.setCurrentFrame( 0 ); updatePosition(); break;