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
28 changes: 18 additions & 10 deletions src/tracks/SampleTrack.cpp
Expand Up @@ -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 == "") //When creating an empty sample pattern make it a bar long
Spekular marked this conversation as resolved.
Show resolved Hide resolved
{
float nom = Engine::getSong()->getTimeSigModel().getNumerator();
float den = Engine::getSong()->getTimeSigModel().getDenominator();
length = DefaultTicksPerTact * ( nom / den );
}
else //Otherwise set it to the samples length
Spekular marked this conversation as resolved.
Show resolved Hide resolved
{
m_sampleBuffer->setAudioFile( _sf );
length = (int) ( m_sampleBuffer->frames() / Engine::framesPerTick() ) ;
}
changeLength(length);

emit sampleChanged();
emit playbackPositionChanged();
Expand Down Expand Up @@ -462,7 +470,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 +480,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 +519,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 +535,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