Skip to content

Commit

Permalink
Let sample tracks play from any song position (LMMS#3133)
Browse files Browse the repository at this point in the history
* play sampletracks from any song position

* take care of TCO length

* TCOs shouldn't be updated when SE window is resized

* take care of zooming level

* takes care on all song position changes and mute/solo tracks now

* playes the sample only within the buffer limits

* takes care of time signature changes

* some minor code improvements (zapashcanon)

* loopback one tick earlier

* minor code changes

* get rid off clicks by resize and scrolling song editor

* removes playhandle by remove TCO

* minor bugs on manipulating TCOs in Song Editor

* update on add sample by playing

* white spaces 1
  • Loading branch information
BaraMGB authored and liushuyu committed Jan 10, 2017
1 parent addbb8e commit 7e98aed
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 21 deletions.
2 changes: 1 addition & 1 deletion include/Editor.h
Expand Up @@ -43,7 +43,7 @@ class Editor : public QMainWindow
Q_OBJECT
public:
void setPauseIcon(bool displayPauseIcon=true);

QAction *playAction() const;
protected:
DropToolBar * addDropToolBarToTop(QString const & windowTitle);
DropToolBar * addDropToolBar(Qt::ToolBarArea whereToAdd, QString const & windowTitle);
Expand Down
14 changes: 12 additions & 2 deletions include/SampleTrack.h
Expand Up @@ -59,20 +59,27 @@ class SampleTCO : public TrackContentObject
}

MidiTime sampleLength() const;

void setSampleStartFrame( f_cnt_t startFrame );
void setSamplePlayLength( f_cnt_t length );
virtual TrackContentObjectView * createView( TrackView * _tv );


bool isPlaying() const;
void setIsPlaying(bool isPlaying);

public slots:
void setSampleBuffer( SampleBuffer* sb );
void setSampleFile( const QString & _sf );
void updateLength( bpm_t = 0 );
void updateLength();
void toggleRecord();
void playbackPositionChanged();
void updateTrackTcos();


private:
SampleBuffer* m_sampleBuffer;
BoolModel m_recordModel;
bool m_isPlaying;


friend class SampleTCOView;
Expand Down Expand Up @@ -102,6 +109,7 @@ public slots:
protected:
virtual void contextMenuEvent( QContextMenuEvent * _cme );
virtual void mousePressEvent( QMouseEvent * _me );
virtual void mouseReleaseEvent( QMouseEvent * _me );
virtual void dragEnterEvent( QDragEnterEvent * _dee );
virtual void dropEvent( QDropEvent * _de );
virtual void mouseDoubleClickEvent( QMouseEvent * );
Expand Down Expand Up @@ -143,6 +151,8 @@ class SampleTrack : public Track
return "sampletrack";
}

public slots:
void updateTcos();

private:
FloatModel m_volumeModel;
Expand Down
1 change: 1 addition & 0 deletions include/Song.h
Expand Up @@ -381,6 +381,7 @@ private slots:
void timeSignatureChanged( int oldTicksPerTact, int ticksPerTact );
void controllerAdded( Controller * );
void controllerRemoved( Controller * );
void updateSampleTracks();

} ;

Expand Down
5 changes: 5 additions & 0 deletions include/SongEditor.h
Expand Up @@ -71,6 +71,8 @@ class SongEditor : public TrackContainerView
void saveSettings( QDomDocument& doc, QDomElement& element );
void loadSettings( const QDomElement& element );

ComboBoxModel *zoomingModel() const;

public slots:
void scrolled( int new_pos );

Expand Down Expand Up @@ -158,6 +160,9 @@ protected slots:

void adjustUiAfterProjectLoad();

signals:
void playTriggered();

private:
QAction* m_addBBTrackAction;
QAction* m_addSampleTrackAction;
Expand Down
1 change: 1 addition & 0 deletions include/TimeLineWidget.h
Expand Up @@ -241,6 +241,7 @@ public slots:
signals:
void positionChanged( const MidiTime & _t );
void loopPointStateLoaded( int _n );
void positionMarkerMoved();

} ;

Expand Down
2 changes: 2 additions & 0 deletions include/Track.h
Expand Up @@ -577,6 +577,8 @@ class EXPORT Track : public Model, public JournallingObject
return m_processingLock.tryLock();
}

BoolModel* getMutedModel();

public slots:
virtual void setName( const QString & newName )
{
Expand Down
10 changes: 8 additions & 2 deletions src/core/Song.cpp
Expand Up @@ -270,6 +270,7 @@ void Song::processNextBuffer()
( tl->loopBegin().getTicks() * 60 * 1000 / 48 ) / getTempo();
m_playPos[m_playMode].setTicks(
tl->loopBegin().getTicks() );
emit updateSampleTracks();
}
}

Expand Down Expand Up @@ -343,10 +344,14 @@ void Song::processNextBuffer()
{
m_playPos[m_playMode].setTicks( tl->loopBegin().getTicks() );

m_elapsedMilliSeconds =
( ( tl->loopBegin().getTicks() ) * 60 * 1000 / 48 ) /
m_elapsedMilliSeconds =
( ( tl->loopBegin().getTicks() ) * 60 * 1000 / 48 ) /
getTempo();
}
else if( m_playPos[m_playMode] == tl->loopEnd() - 1 )
{
emit updateSampleTracks();
}
}
else
{
Expand Down Expand Up @@ -577,6 +582,7 @@ void Song::setPlayPos( tick_t ticks, PlayModes playMode )
if( isPlaying() )
{
emit playbackPositionChanged();
emit updateSampleTracks();
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/core/Track.cpp
Expand Up @@ -68,6 +68,7 @@
#include "ProjectJournal.h"
#include "SampleTrack.h"
#include "Song.h"
#include "SongEditor.h"
#include "StringPairDrag.h"
#include "templates.h"
#include "TextFloat.h"
Expand Down Expand Up @@ -151,8 +152,8 @@ void TrackContentObject::movePosition( const MidiTime & pos )
{
m_startPosition = pos;
Engine::getSong()->updateLength();
emit positionChanged();
}
emit positionChanged();
}


Expand All @@ -167,11 +168,8 @@ void TrackContentObject::movePosition( const MidiTime & pos )
*/
void TrackContentObject::changeLength( const MidiTime & length )
{
if( m_length != length )
{
m_length = length;
Engine::getSong()->updateLength();
}
m_length = length;
Engine::getSong()->updateLength();
emit lengthChanged();
}

Expand Down Expand Up @@ -280,12 +278,15 @@ TrackContentObjectView::TrackContentObjectView( TrackContentObject * tco,

connect( m_tco, SIGNAL( lengthChanged() ),
this, SLOT( updateLength() ) );
connect( gui->songEditor()->m_editor->zoomingModel(), SIGNAL( dataChanged() ), this, SLOT( updateLength() ) );
connect( m_tco, SIGNAL( positionChanged() ),
this, SLOT( updatePosition() ) );
connect( m_tco, SIGNAL( destroyedTCO() ), this, SLOT( close() ) );
setModel( m_tco );

m_trackView->getTrackContentWidget()->addTCOView( this );
updateLength();
updatePosition();
}


Expand Down Expand Up @@ -2483,6 +2484,14 @@ void Track::toggleSolo()



BoolModel *Track::getMutedModel()
{
return &m_mutedModel;
}






// ===========================================================================
Expand Down
1 change: 1 addition & 0 deletions src/gui/TimeLineWidget.cpp
Expand Up @@ -374,6 +374,7 @@ void TimeLineWidget::mouseMoveEvent( QMouseEvent* event )
Engine::getSong()->setMilliSeconds(((((t.getTicks()))*60*1000/48)/Engine::getSong()->getTempo()));
m_pos.setCurrentFrame( 0 );
updatePosition();
positionMarkerMoved();
break;

case MoveLoopBegin:
Expand Down
5 changes: 5 additions & 0 deletions src/gui/editors/Editor.cpp
Expand Up @@ -115,6 +115,11 @@ Editor::~Editor()

}

QAction *Editor::playAction() const
{
return m_playAction;
}




Expand Down
9 changes: 9 additions & 0 deletions src/gui/editors/SongEditor.cpp
Expand Up @@ -610,6 +610,14 @@ bool SongEditor::allowRubberband() const



ComboBoxModel *SongEditor::zoomingModel() const
{
return m_zoomingModel;
}




SongEditorWindow::SongEditorWindow(Song* song) :
Editor(Engine::mixer()->audioDev()->supportsCapture()),
m_editor(new SongEditor(song))
Expand Down Expand Up @@ -703,6 +711,7 @@ QSize SongEditorWindow::sizeHint() const

void SongEditorWindow::play()
{
emit playTriggered();
if( Engine::getSong()->playMode() != Song::Mode_PlaySong )
{
Engine::getSong()->playSong();
Expand Down

0 comments on commit 7e98aed

Please sign in to comment.