Skip to content

Commit

Permalink
Seperate loops and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Umcaruje committed Jan 5, 2017
1 parent 506054d commit 560b2fa
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 89 deletions.
6 changes: 3 additions & 3 deletions data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ PianoRoll {
qproperty-barColor: #078f3a;
qproperty-markedSemitoneColor: #06170E;
/* Grid colors */
qproperty-barLineColor: #437053;
qproperty-lineColor: #292929;
qproperty-beatLineColor: #2a6548;
qproperty-lineColor16th: #292929;
qproperty-lineColor32nd: #1f1f1f;
qproperty-barLineColor: #437053;

/* Text on the white piano keys */
qproperty-textColor: #000;
qproperty-textColorLight: #0bd556;
Expand Down
13 changes: 5 additions & 8 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class PianoRoll : public QWidget
Q_OBJECT
Q_PROPERTY( QColor barLineColor READ barLineColor WRITE setBarLineColor )
Q_PROPERTY( QColor beatLineColor READ beatLineColor WRITE setBeatLineColor )
Q_PROPERTY( QColor lineColor16th READ lineColor16th WRITE setLineColor16th )
Q_PROPERTY( QColor lineColor32nd READ lineColor32nd WRITE setLineColor32nd )
Q_PROPERTY( QColor lineColor READ lineColor WRITE setLineColor )
Q_PROPERTY( QColor noteModeColor READ noteModeColor WRITE setNoteModeColor )
Q_PROPERTY( QColor noteColor READ noteColor WRITE setNoteColor )
Q_PROPERTY( QColor barColor READ barColor WRITE setBarColor )
Expand Down Expand Up @@ -117,10 +116,8 @@ class PianoRoll : public QWidget
void setBarLineColor( const QColor & c );
QColor beatLineColor() const;
void setBeatLineColor( const QColor & c );
QColor lineColor16th() const;
void setLineColor16th( const QColor & c );
QColor lineColor32nd() const;
void setLineColor32nd( const QColor & c );
QColor lineColor() const;
void setLineColor( const QColor & c );
QColor noteModeColor() const;
void setNoteModeColor( const QColor & c );
QColor noteColor() const;
Expand Down Expand Up @@ -166,6 +163,7 @@ class PianoRoll : public QWidget
void selectAll();
NoteVector getSelectedNotes();
void selectNotesOnKey();
int xCoordOfTick( int tick );

// for entering values with dblclick in the vol/pan bars
void enterValue( NoteVector* nv );
Expand Down Expand Up @@ -384,8 +382,7 @@ protected slots:
// qproperty fields
QColor m_barLineColor;
QColor m_beatLineColor;
QColor m_lineColor16th;
QColor m_lineColor32nd;
QColor m_lineColor;
QColor m_noteModeColor;
QColor m_noteColor;
QColor m_barColor;
Expand Down
171 changes: 93 additions & 78 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ PianoRoll::PianoRoll() :
m_scrollBack( false ),
m_barLineColor( 0, 0, 0 ),
m_beatLineColor( 0, 0, 0 ),
m_lineColor16th( 0, 0, 0 ),
m_lineColor32nd( 0, 0, 0 ),
m_lineColor( 0, 0, 0 ),
m_noteModeColor( 0, 0, 0 ),
m_noteColor( 0, 0, 0 ),
m_barColor( 0, 0, 0 ),
Expand Down Expand Up @@ -741,17 +740,11 @@ QColor PianoRoll::beatLineColor() const
void PianoRoll::setBeatLineColor( const QColor & c )
{ m_beatLineColor = c; }

QColor PianoRoll::lineColor16th() const
{ return m_lineColor16th; }
QColor PianoRoll::lineColor() const
{ return m_lineColor; }

void PianoRoll::setLineColor16th( const QColor & c )
{ m_lineColor16th = c; }

QColor PianoRoll::lineColor32nd() const
{ return m_lineColor32nd; }

void PianoRoll::setLineColor32nd( const QColor & c )
{ m_lineColor32nd = c; }
void PianoRoll::setLineColor( const QColor & c )
{ m_lineColor = c; }

QColor PianoRoll::noteModeColor() const
{ return m_noteModeColor; }
Expand Down Expand Up @@ -2595,6 +2588,12 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
Engine::getSong()->setModified();
}

int PianoRoll::xCoordOfTick(int tick )
{
return WHITE_KEY_WIDTH + ( ( tick - m_currentPosition )
* m_ppt / MidiTime::ticksPerTact() );
}

void PianoRoll::paintEvent(QPaintEvent * pe )
{
bool drawNoteNames = ConfigManager::inst()->value( "ui", "printnotelabels").toInt();
Expand All @@ -2605,26 +2604,12 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
style()->drawPrimitive( QStyle::PE_Widget, &opt, &p, this );

QBrush bgColor = p.background();
QColor horizCol = QColor( lineColor16th() );
QColor horizCol = QColor( lineColor() );
QColor horizColAccent = QColor( beatLineColor() );

// fill with bg color
p.fillRect( 0, 0, width(), height(), bgColor );

// alternating shades for better contrast
// count the bars which disappear on left by scrolling
int barCount = m_currentPosition / MidiTime::ticksPerTact();
int leftBars = m_currentPosition / m_ppt;

for ( int x = WHITE_KEY_WIDTH; x < width() + m_currentPosition; x += m_ppt, ++barCount )
{
if ( (barCount + leftBars) % 2 != 0 )
{
p.fillRect( x - m_currentPosition, PR_TOP_MARGIN, m_ppt,
height() - ( PR_BOTTOM_MARGIN + PR_TOP_MARGIN ), backgroundShade() );
}
}

// set font-size to 8
p.setFont( pointSize<8>( p.font() ) );

Expand Down Expand Up @@ -2730,7 +2715,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
y -= WHITE_KEY_BIG_HEIGHT;
}

// Draw horizontal grid lines
/* // Draw horizontal grid lines
// Draw the C line in a more prominent color
if( static_cast<Keys>( key % KeysPerOctave ) == Key_C )
{
Expand All @@ -2740,7 +2725,7 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
{
p.setPen( horizCol );
}
p.drawLine( WHITE_KEY_WIDTH, key_line_y, width(), key_line_y );
p.drawLine( WHITE_KEY_WIDTH, key_line_y, width(), key_line_y );*/

// Compute the corrections for the note names
int yCorrectionForNoteLabels = 0;
Expand Down Expand Up @@ -2881,62 +2866,92 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
width() - WHITE_KEY_WIDTH,
height() - PR_TOP_MARGIN - PR_BOTTOM_MARGIN );

// draw vertical raster

// triplet mode occurs if the note duration isn't a multiple of 3
bool triplets = ( quantization() % 3 != 0 );

int spt = MidiTime::stepsPerTact();
float pp16th = (float)m_ppt / spt;
int bpt = DefaultBeatsPerTact;
if ( triplets ) {
spt = static_cast<int>(1.5 * spt);
bpt = static_cast<int>(bpt * 2.0/3.0);
pp16th *= 2.0/3.0;
}

int tact_16th = m_currentPosition / bpt;

const int offset = ( m_currentPosition % bpt ) *
m_ppt / MidiTime::ticksPerTact();

bool show32nds = ( m_zoomingModel.value() > 3 );

// we need float here as odd time signatures might produce rounding
// errors else and thus an unusable grid
for( float x = WHITE_KEY_WIDTH - offset; x < width();
x += pp16th, ++tact_16th )
// draw the grid
if( hasValidPattern() )
{
if( x >= WHITE_KEY_WIDTH )
// Draw alternating shades on bars
// count the bars which disappear on left by scrolling
int barCount = m_currentPosition / MidiTime::ticksPerTact();
int leftBars = m_currentPosition / m_ppt;

for ( int x = WHITE_KEY_WIDTH; x < width() + m_currentPosition; x += m_ppt, ++barCount )
{
// every bar-start needs to be a bright line
if( tact_16th % spt == 0 )
{
p.setPen( barLineColor() );
}
// normal line
else if( tact_16th % 4 == 0 )
if ( (barCount + leftBars) % 2 != 0 )
{
p.setPen( beatLineColor() );
p.fillRect( x - m_currentPosition, PR_TOP_MARGIN, m_ppt,
height() - ( PR_BOTTOM_MARGIN + PR_TOP_MARGIN ), backgroundShade() );
}
// weak line
else
{
p.setPen( lineColor16th() );
}

p.drawLine( (int) x, PR_TOP_MARGIN, (int) x, height() - PR_BOTTOM_MARGIN );
}

// Draw the vertical quantization lines

int q, x, tick;

if ( m_zoomingModel.value() > 3 ) {
// If we're over 400% zoom, we allow all quantization level grids
q = quantization();
}
else if (quantization() % 3 != 0)
{
// If we're under 400% zoom, we allow quantization grid up to 1/24 for triplets
// to ensure a dense doesn't fill out the background
q = quantization() < 8 ? 8 : quantization();
}
else {
// If we're under 400% zoom, we allow quantization grid up to 1/32 for normal notes
q = quantization() < 6 ? 6 : quantization();
}
printf("%d\n", quantization());


for( tick = m_currentPosition - m_currentPosition % q, x = xCoordOfTick( tick );
x<=width();
tick += q, x = xCoordOfTick( tick ) )
{
p.setPen( lineColor() );
p.drawLine( x, PR_TOP_MARGIN, x, height() - PR_BOTTOM_MARGIN );
}

//key_line_y = keyAreaBottom() - 1;
key = m_startKey;
// Draw horizontal lines
for( int y = keyAreaBottom() + y_offset; y > PR_TOP_MARGIN;
y -= KEY_LINE_HEIGHT )
{
printf("%d\n", keyAreaBottom() );
p.setPen( lineColor() );
p.drawLine( WHITE_KEY_WIDTH, y, width(), y );
}

// Draw the vertical beat lines
int ticksPerBeat = DefaultTicksPerTact /
Engine::getSong()->getTimeSigModel().getDenominator();

// extra 32nd's line
if( show32nds )
{
p.setPen( lineColor32nd() );
p.drawLine( (int)(x + pp16th / 2) , PR_TOP_MARGIN,
(int)(x + pp16th / 2), height() - PR_BOTTOM_MARGIN );
}
// triplet mode occurs if the note quantization isn't a multiple of 3
if( quantization() % 3 != 0 )
{
ticksPerBeat = static_cast<int>(ticksPerBeat * 2.0/3.0);
}
}

for( tick = m_currentPosition - m_currentPosition % ticksPerBeat,
x = xCoordOfTick( tick );
x<=width();
tick += ticksPerBeat, x = xCoordOfTick( tick ) )
{
p.setPen( beatLineColor() );
p.drawLine( x, PR_TOP_MARGIN, x, height() - PR_BOTTOM_MARGIN );
}

// Draw the vertical bar lines
for( tick = m_currentPosition - m_currentPosition % MidiTime::ticksPerTact(),
x = xCoordOfTick( tick );
x<=width();
tick += MidiTime::ticksPerTact(), x = xCoordOfTick( tick ) )
{
p.setPen( barLineColor() );
p.drawLine( x, PR_TOP_MARGIN, x, height() - PR_BOTTOM_MARGIN );
}
}


// following code draws all notes in visible area
Expand Down

0 comments on commit 560b2fa

Please sign in to comment.