Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sample track TCOs to resize smaller than one bar #4933

Merged
merged 15 commits into from
Apr 15, 2019
22 changes: 11 additions & 11 deletions src/core/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ TrackContentObjectView::~TrackContentObjectView()

/*! \brief Update a TrackContentObjectView
*
* TCO's get drawn only when needed,
* and when a TCO is updated,
* TCO's get drawn only when needed,
* and when a TCO is updated,
* it needs to be redrawn.
*
*/
Expand Down Expand Up @@ -678,7 +678,7 @@ void TrackContentObjectView::mousePressEvent( QMouseEvent * me )
}
}
}
else if( me->button() == Qt::LeftButton &&
else if( me->button() == Qt::LeftButton &&
me->modifiers() & Qt::ControlModifier )
{
// start drag-action
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void TrackContentWidget::updateBackground()

// draw lines
// vertical lines
pmp.setPen( QPen( gridColor(), 1 ) );
pmp.setPen( QPen( gridColor(), 1 ) );
for( float x = 0; x < w * 2; x += ppt )
{
pmp.drawLine( QLineF( x, 0.0, x, h ) );
Expand All @@ -1134,9 +1134,9 @@ void TrackContentWidget::updateBackground()
{
pmp.drawLine( QLineF( x, 0.0, x, h ) );
}

// horizontal line
pmp.setPen( QPen( gridColor(), 1 ) );
pmp.setPen( QPen( gridColor(), 1 ) );
pmp.drawLine( 0, h-1, w*2, h-1 );

pmp.end();
Expand Down Expand Up @@ -1319,7 +1319,7 @@ MidiTime TrackContentWidget::getPosition( int mouseX )
*/
void TrackContentWidget::dragEnterEvent( QDragEnterEvent * dee )
{
MidiTime tcoPos = MidiTime( getPosition( dee->pos().x() ).getTact(), 0 );
MidiTime tcoPos = getPosition( dee->pos().x() );
if( canPasteSelection( tcoPos, dee ) == false )
{
dee->ignore();
Expand Down Expand Up @@ -1862,7 +1862,7 @@ void TrackOperationsWidget::updateMenu()
toMenu->addAction( embed::getIconPixmap( "cancel", 16, 16 ),
tr( "Remove this track" ),
this, SLOT( removeTrack() ) );

if( ! m_trackView->trackContainerView()->fixedTCOs() )
{
toMenu->addAction( tr( "Clear this track" ), this, SLOT( clearTrack() ) );
Expand Down Expand Up @@ -2787,12 +2787,12 @@ void TrackView::mouseMoveEvent( QMouseEvent * me )
else if( m_action == MoveTrack )
{
// look which track-widget the mouse-cursor is over
const int yPos =
const int yPos =
m_trackContainerView->contentWidget()->mapFromGlobal( me->globalPos() ).y();
const TrackView * trackAtY = m_trackContainerView->trackViewAt( yPos );

// debug code
// qDebug( "y position %d", yPos );
// debug code
// qDebug( "y position %d", yPos );

// a track-widget not equal to ourself?
if( trackAtY != NULL && trackAtY != this )
Expand Down
41 changes: 28 additions & 13 deletions src/tracks/SampleTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ SampleTCO::SampleTCO( Track * _track ) :
SampleTCO::~SampleTCO()
{
SampleTrack * sampletrack = dynamic_cast<SampleTrack*>( getTrack() );
if( sampletrack)
if ( sampletrack )
{
sampletrack->updateTcos();
}
Expand All @@ -118,10 +118,7 @@ SampleTCO::~SampleTCO()

void SampleTCO::changeLength( const MidiTime & _length )
{
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 ) );
TrackContentObject::changeLength( qMax( static_cast<int>( _length ), 1 ) );
}


Expand All @@ -147,8 +144,19 @@ void SampleTCO::setSampleBuffer( SampleBuffer* sb )

void SampleTCO::setSampleFile( const QString & _sf )
{
m_sampleBuffer->setAudioFile( _sf );
changeLength( (int) ( m_sampleBuffer->frames() / Engine::framesPerTick() ) );
int length;
Spekular marked this conversation as resolved.
Show resolved Hide resolved
if ( _sf.isEmpty() )
{ //When creating an empty sample pattern make it a bar long
float nom = Engine::getSong()->getTimeSigModel().getNumerator();
float den = Engine::getSong()->getTimeSigModel().getDenominator();
length = DefaultTicksPerTact * ( nom / den );
}
else
{ //Otherwise set it to the sample's length
m_sampleBuffer->setAudioFile( _sf );
length = sampleLength();
Spekular marked this conversation as resolved.
Show resolved Hide resolved
}
changeLength(length);

emit sampleChanged();
emit playbackPositionChanged();
Expand Down Expand Up @@ -440,8 +448,15 @@ void SampleTCOView::mouseReleaseEvent(QMouseEvent *_me)
void SampleTCOView::mouseDoubleClickEvent( QMouseEvent * )
{
QString af = m_tco->m_sampleBuffer->openAudioFile();
if( af != "" && af != m_tco->m_sampleBuffer->audioFile() )
{

if ( af.isEmpty() ) {} //Don't do anything if no file is loaded
else if ( af == m_tco->m_sampleBuffer->audioFile() )
{ //Instead of reloading the existing file, just reset the size
Spekular marked this conversation as resolved.
Show resolved Hide resolved
int length = (int) ( m_tco->m_sampleBuffer->frames() / Engine::framesPerTick() );
m_tco->changeLength(length);
}
else
{ //Otherwise load the new file as ususal
m_tco->setSampleFile( af );
Engine::getSong()->setModified();
}
Expand All @@ -462,7 +477,7 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )

setNeedsUpdate( false );

m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size()
m_paintPixmap = m_paintPixmap.isNull() == true || m_paintPixmap.size() != size()
? QPixmap( size() ) : m_paintPixmap;

QPainter p( &m_paintPixmap );
Expand All @@ -472,7 +487,7 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )
bool muted = m_tco->getTrack()->isMuted() || m_tco->isMuted();

// state: selected, muted, normal
c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
c = isSelected() ? selectedColor() : ( muted ? mutedBackgroundColor()
: painter.background().color() );

lingrad.setColorAt( 1, c.darker( 300 ) );
Expand Down Expand Up @@ -511,7 +526,7 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )

// inner border
p.setPen( c.lighter( 160 ) );
p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH,
p.drawRect( 1, 1, rect().right() - TCO_BORDER_WIDTH,
rect().bottom() - TCO_BORDER_WIDTH );

// outer border
Expand All @@ -527,7 +542,7 @@ void SampleTCOView::paintEvent( QPaintEvent * pe )
embed::getIconPixmap( "muted", size, size ) );
}

// recording sample tracks is not possible at the moment
// recording sample tracks is not possible at the moment

/* if( m_tco->isRecord() )
{
Expand Down