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

Update Pattern.cpp #3325

Closed
wants to merge 2 commits into from
Closed
Changes from all 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
71 changes: 29 additions & 42 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
#include "MainWindow.h"


QPixmap * PatternView::s_stepBtnOn0 = NULL;
QPixmap * PatternView::s_stepBtnOn200 = NULL;
QPixmap * PatternView::s_stepBtnOn = NULL;
QPixmap * PatternView::s_stepBtnOff = NULL;
QPixmap * PatternView::s_stepBtnOffLight = NULL;

Expand Down Expand Up @@ -104,6 +103,8 @@ Pattern::Pattern( const Pattern& other ) :
}




Pattern::~Pattern()
{
emit destroyedPattern( this );
Expand Down Expand Up @@ -211,6 +212,9 @@ MidiTime Pattern::beatPatternLength() const
return MidiTime( max_length ).nextFullTact() * MidiTime::ticksPerTact();
}




Note * Pattern::addNote( const Note & _new_note, const bool _quant_pos )
{
Note * new_note = new Note( _new_note );
Expand Down Expand Up @@ -296,6 +300,7 @@ Note * Pattern::noteAtStep( int _step )




void Pattern::rearrangeAllNotes()
{
// sort notes by start time
Expand All @@ -304,6 +309,7 @@ void Pattern::rearrangeAllNotes()




void Pattern::clearNotes()
{
instrumentTrack()->lock();
Expand Down Expand Up @@ -492,11 +498,15 @@ void Pattern::clear()

void Pattern::addSteps()
{
m_steps += MidiTime::stepsPerTact();
Song* s = Engine::getSong();
m_steps += s->getTimeSigModel().getNumerator() * s->getTimeSigModel().getDenominator();
updateLength();
emit dataChanged();
}




void Pattern::cloneSteps()
{
int oldLength = m_steps;
Expand All @@ -523,7 +533,8 @@ void Pattern::cloneSteps()

void Pattern::removeSteps()
{
int n = MidiTime::stepsPerTact();
Song* s = Engine::getSong();
int n = s->getTimeSigModel().getNumerator() * s->getTimeSigModel().getDenominator();
if( n < m_steps )
{
for( int i = m_steps - n; i < m_steps; ++i )
Expand Down Expand Up @@ -581,26 +592,14 @@ bool Pattern::empty()

void Pattern::changeTimeSignature()
{
MidiTime last_pos = MidiTime::ticksPerTact() - 1;
for( NoteVector::ConstIterator cit = m_notes.begin();
cit != m_notes.end(); ++cit )
{
if( ( *cit )->length() < 0 && ( *cit )->pos() > last_pos )
{
last_pos = ( *cit )->pos()+MidiTime::ticksPerTact() /
MidiTime::stepsPerTact();
}
}
last_pos = last_pos.nextFullTact() * MidiTime::ticksPerTact();
m_steps = qMax<tick_t>( MidiTime::stepsPerTact(),
last_pos.getTact() * MidiTime::stepsPerTact() );
Song* s = Engine::getSong();
m_steps = s->getTimeSigModel().getNumerator() * s->getTimeSigModel().getDenominator();
updateLength();
}





PatternView::PatternView( Pattern* pattern, TrackView* parent ) :
TrackContentObjectView( pattern, parent ),
m_pat( pattern ),
Expand All @@ -609,16 +608,10 @@ PatternView::PatternView( Pattern* pattern, TrackView* parent ) :
connect( gui->pianoRoll(), SIGNAL( currentPatternChanged() ),
this, SLOT( update() ) );

if( s_stepBtnOn0 == NULL )
{
s_stepBtnOn0 = new QPixmap( embed::getIconPixmap(
"step_btn_on_0" ) );
}

if( s_stepBtnOn200 == NULL )
if( s_stepBtnOn == NULL )
{
s_stepBtnOn200 = new QPixmap( embed::getIconPixmap(
"step_btn_on_200" ) );
s_stepBtnOn = new QPixmap( embed::getIconPixmap(
"step_btn_on_100" ) );
}

if( s_stepBtnOff == NULL )
Expand All @@ -641,16 +634,13 @@ PatternView::PatternView( Pattern* pattern, TrackView* parent ) :





PatternView::~PatternView()
{
}





void PatternView::update()
{
if ( m_pat->m_patternType == Pattern::BeatPattern )
Expand Down Expand Up @@ -793,6 +783,9 @@ void PatternView::mousePressEvent( QMouseEvent * _me )
}
}




void PatternView::mouseDoubleClickEvent(QMouseEvent *_me)
{
if( _me->button() != Qt::LeftButton )
Expand Down Expand Up @@ -999,21 +992,16 @@ void PatternView::paintEvent( QPaintEvent * )
else if( beatPattern && ( fixedTCOs() || ppt >= 96
|| m_pat->m_steps != MidiTime::stepsPerTact() ) )
{
QPixmap stepon0;
QPixmap stepon200;
QPixmap stepon;
QPixmap stepoff;
QPixmap stepoffl;
const int steps = qMax( 1,
m_pat->m_steps );
const int w = width() - 2 * TCO_BORDER_WIDTH;

// scale step graphics to fit the beat pattern length
stepon0 = s_stepBtnOn0->scaled( w / steps,
s_stepBtnOn0->height(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation );
stepon200 = s_stepBtnOn200->scaled( w / steps,
s_stepBtnOn200->height(),
stepon = s_stepBtnOn->scaled( w / steps,
s_stepBtnOn->height(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation );
stepoff = s_stepBtnOff->scaled( w / steps,
Expand All @@ -1032,17 +1020,16 @@ void PatternView::paintEvent( QPaintEvent * )
// figure out x and y coordinates for step graphic
const int x = TCO_BORDER_WIDTH + static_cast<int>( it * w / steps );
const int y = height() - s_stepBtnOff->height() - 1;

Song* s = Engine::getSong();
if( n )
{
const int vol = n->getVolume();
p.drawPixmap( x, y, stepoffl );
p.drawPixmap( x, y, stepon0 );
p.setOpacity( sqrt( vol / 200.0 ) );
p.drawPixmap( x, y, stepon200 );
p.drawPixmap( x, y, stepon );
p.setOpacity( 1 );
}
else if( ( it / 4 ) % 2 )
else if( ( it / s->getTimeSigModel().getDenominator() ) % 2 )
{
p.drawPixmap( x, y, stepoffl );
}
Expand Down