Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/Editor.h
Original file line number Diff line number Diff line change
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
10 changes: 8 additions & 2 deletions include/SampleTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,26 @@ 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();


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


friend class SampleTCOView;
Expand Down
1 change: 1 addition & 0 deletions include/Song.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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 @@ -345,6 +346,7 @@ void Song::processNextBuffer()
m_elapsedMilliSeconds =
( ( tl->loopBegin().getTicks() ) * 60 * 1000 / 48 ) /
Copy link
Contributor

@redianthus redianthus Jan 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_elapsedMilliSeconds = tl->loopBegin().getTicks() * 1250 / getTempo();

Copy link
Contributor

@redianthus redianthus Jan 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same thing on lines 269, 326, 409, 574 and 643.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This will make it harder to deduce where 1250 came from in the first place. The compiler does operations on real numbers for us.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to change code I don't have to touch. I want to have this PR as clean as possible. We can make an extra PR with code cleaning stuff.

getTempo();
emit updateSampleTracks();
}
}
else
Expand Down Expand Up @@ -576,6 +578,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
104 changes: 94 additions & 10 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QPushButton>

#include "gui_templates.h"
#include "GuiApplication.h"
#include "Song.h"
#include "embed.h"
#include "Engine.h"
Expand All @@ -42,7 +43,9 @@
#include "BBTrack.h"
#include "SamplePlayHandle.h"
#include "SampleRecordHandle.h"
#include "SongEditor.h"
#include "StringPairDrag.h"
#include "TimeLineWidget.h"
#include "Knob.h"
#include "MainWindow.h"
#include "Mixer.h"
Expand All @@ -53,10 +56,10 @@
#include "panning_constants.h"
#include "volume.h"


SampleTCO::SampleTCO( Track * _track ) :
TrackContentObject( _track ),
m_sampleBuffer( new SampleBuffer )
m_sampleBuffer( new SampleBuffer ),
m_isPlaying( false )
{
saveJournallingState( false );
setSampleFile( "" );
Expand All @@ -65,7 +68,26 @@ SampleTCO::SampleTCO( Track * _track ) :
// we need to receive bpm-change-events, because then we have to
// change length of this TCO
connect( Engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ),
this, SLOT( updateLength( bpm_t ) ) );
this, SLOT( updateLength() ) );
connect( Engine::getSong(), SIGNAL( timeSignatureChanged( int,int ) ),
this, SLOT( updateLength() ) );

//care about positionmarker
TimeLineWidget * timeLine = Engine::getSong()->getPlayPos( Engine::getSong()->Mode_PlaySong ).m_timeLine;
connect( timeLine, SIGNAL( positionMarkerMoved() ), this, SLOT( playbackPositionChanged() ) );
//care about loops
connect( Engine::getSong(), SIGNAL( updateSampleTracks() ), this, SLOT( playbackPositionChanged() ) );
//care about mute TCOs
connect( this, SIGNAL( dataChanged() ), this, SLOT( playbackPositionChanged() ) );
//care about mute track
connect( getTrack()->getMutedModel(), SIGNAL( dataChanged() ),this, SLOT( playbackPositionChanged() ) );
//care about TCO length
connect( this, SIGNAL( lengthChanged() ), this, SLOT( playbackPositionChanged() ) );
//care about TCO position
connect( this, SIGNAL( positionChanged() ), this, SLOT( playbackPositionChanged() ) );
//playbutton clicked or space key
connect( gui->songEditor(), SIGNAL( playTriggered() ), this, SLOT( playbackPositionChanged() ) );

switch( getTrack()->trackContainer()->type() )
{
case TrackContainer::BBContainer:
Expand Down Expand Up @@ -93,7 +115,10 @@ SampleTCO::~SampleTCO()

void SampleTCO::changeLength( const MidiTime & _length )
{
TrackContentObject::changeLength( qMax( static_cast<int>( _length ), DefaultTicksPerTact ) );
float nom = Engine::getSong()->getTimeSigModel().getNumerator();
float den = Engine::getSong()->getTimeSigModel().getDenominator();
int ticksPerTact = DefaultTicksPerTact * ( nom / den );
TrackContentObject::changeLength( qMax( static_cast<int>( _length ), ticksPerTact ) );
}


Expand Down Expand Up @@ -137,7 +162,26 @@ void SampleTCO::toggleRecord()



void SampleTCO::updateLength( bpm_t )
void SampleTCO::playbackPositionChanged()
{
Engine::mixer()->removePlayHandlesOfTypes( getTrack(), PlayHandle::TypeSamplePlayHandle );
m_isPlaying = false;
}

bool SampleTCO::isPlaying() const
{
return m_isPlaying;
}

void SampleTCO::setIsPlaying(bool isPlaying)
{
m_isPlaying = isPlaying;
}




void SampleTCO::updateLength()
{
changeLength( sampleLength() );
}
Expand All @@ -153,6 +197,22 @@ MidiTime SampleTCO::sampleLength() const



void SampleTCO::setSampleStartFrame(f_cnt_t startFrame)
{
m_sampleBuffer->setStartFrame( startFrame );
}




void SampleTCO::setSamplePlayLength(f_cnt_t length)
{
m_sampleBuffer->setEndFrame( length );
}




void SampleTCO::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
if( _this.parentNode().nodeName() == "clipboard" )
Expand Down Expand Up @@ -394,10 +454,12 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )
/ (float) m_tco->length().getTact() :
pixelsPerTact();

float nom = Engine::getSong()->getTimeSigModel().getNumerator();
float den = Engine::getSong()->getTimeSigModel().getDenominator();
float ticksPerTact = DefaultTicksPerTact * ( nom / den );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float ticksPerTact = DefaultTicksPerTact * nom / den;


QRect r = QRect( TCO_BORDER_WIDTH, spacing,
qMax( static_cast<int>( m_tco->sampleLength() * ppt
/ DefaultTicksPerTact ), 1 ),
rect().bottom() - 2 * spacing );
qMax( static_cast<int>( m_tco->sampleLength() * ppt / ticksPerTact ), 1 ), rect().bottom() - 2 * spacing );
m_tco->m_sampleBuffer->visualize( p, r, pe->rect() );

// disable antialiasing for borders, since its not needed
Expand Down Expand Up @@ -497,9 +559,31 @@ bool SampleTrack::play( const MidiTime & _start, const fpp_t _frames,
for( int i = 0; i < numOfTCOs(); ++i )
{
TrackContentObject * tco = getTCO( i );
if( tco->startPosition() == _start )
SampleTCO * sTco = dynamic_cast<SampleTCO*>( tco );
float framesPerTick = Engine::framesPerTick();
if( _start >= sTco->startPosition() && _start < sTco->endPosition() )
{
if( sTco->isPlaying() == false )
{
f_cnt_t sampleStart = ( _start * framesPerTick ) - ( sTco->startPosition() * framesPerTick );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f_cnt_t sampleStart = framesPerTick * ( _start - sTco->startPosition() );

f_cnt_t tcoFrameLength = ( sTco->endPosition() * framesPerTick ) - ( sTco->startPosition() * framesPerTick );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f_cnt_t tcoFrameLength = framesPerTick * ( sTco->endPosition() - sTco->startPosition() );

f_cnt_t sampleBufferLength = sTco->sampleBuffer()->frames();
//if the Tco smaller than the sample length we play only until Tco end
//else we play the sample to the end but nothing more
f_cnt_t samplePlayLength = tcoFrameLength > sampleBufferLength ? sampleBufferLength : tcoFrameLength;
//we only play within the sampleBuffer limits
if( sampleStart < sTco->sampleBuffer()->frames() )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if( sampleStart < sampleBufferLength )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, sometimes I'm a little bit blind. ;)

{
sTco->setSampleStartFrame( sampleStart );
sTco->setSamplePlayLength( samplePlayLength );
tcos.push_back( sTco );
sTco->setIsPlaying( true );
}
}
}
else
{
tcos.push_back( tco );
sTco->setIsPlaying( false );
}
}
}
Expand Down