Skip to content

Commit

Permalink
Update Pattern and AutomationPattern length (LMMS#3037)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasp00 authored Sep 17, 2016
1 parent 48cc3bb commit 41b930e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 69 deletions.
3 changes: 2 additions & 1 deletion include/AutomationPattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class EXPORT AutomationPattern : public TrackContentObject
}
void setTension( QString _new_tension );

virtual MidiTime length() const;
MidiTime timeMapLength() const;
void updateLength();

MidiTime putValue( const MidiTime & _time, const float _value,
const bool _quant_pos = true );
Expand Down
13 changes: 6 additions & 7 deletions include/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class EXPORT Pattern : public TrackContentObject

void init();


virtual MidiTime length() const;
MidiTime beatPatternLength() const;
void updateLength();

// note management
Note * addNote( const Note & _new_note, const bool _quant_pos = true );
Expand All @@ -74,8 +72,6 @@ class EXPORT Pattern : public TrackContentObject

Note * noteAtStep( int _step );

Note * rearrangeNote( Note * _note_to_proc,
const bool _quant_pos = true );
void rearrangeAllNotes();
void clearNotes();

Expand All @@ -92,8 +88,6 @@ class EXPORT Pattern : public TrackContentObject
{
return m_patternType;
}
void setType( PatternTypes _new_pattern_type );
void checkType();


// next/previous track based on position in the containing track
Expand Down Expand Up @@ -135,6 +129,11 @@ protected slots:


private:
MidiTime beatPatternLength() const;

void setType( PatternTypes _new_pattern_type );
void checkType();

void resizeToFirstTrack();

InstrumentTrack * m_instrumentTrack;
Expand Down
28 changes: 19 additions & 9 deletions src/core/AutomationPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ const AutomatableModel * AutomationPattern::firstObject() const




MidiTime AutomationPattern::length() const
MidiTime AutomationPattern::timeMapLength() const
{
if( m_timeMap.isEmpty() ) return 0;
timeMap::const_iterator it = m_timeMap.end();
Expand All @@ -197,6 +196,14 @@ MidiTime AutomationPattern::length() const



void AutomationPattern::updateLength()
{
changeLength( timeMapLength() );
}




MidiTime AutomationPattern::putValue( const MidiTime & _time,
const float _value,
const bool _quant_pos )
Expand All @@ -219,7 +226,7 @@ MidiTime AutomationPattern::putValue( const MidiTime & _time,
// automation track as the user can't resize this pattern
if( getTrack() && getTrack()->type() == Track::HiddenAutomationTrack )
{
changeLength( length() );
updateLength();
}

emit dataChanged();
Expand Down Expand Up @@ -248,10 +255,9 @@ void AutomationPattern::removeValue( const MidiTime & _time,
}
generateTangents(it, 3);

if( getTrack() &&
getTrack()->type() == Track::HiddenAutomationTrack )
if( getTrack() && getTrack()->type() == Track::HiddenAutomationTrack )
{
changeLength( length() );
updateLength();
}

emit dataChanged();
Expand Down Expand Up @@ -514,7 +520,7 @@ void AutomationPattern::flipX( int length )
void AutomationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
_this.setAttribute( "pos", startPosition() );
_this.setAttribute( "len", TrackContentObject::length() );
_this.setAttribute( "len", length() );
_this.setAttribute( "name", name() );
_this.setAttribute( "prog", QString::number( progressionType() ) );
_this.setAttribute( "tens", QString::number( getTension() ) );
Expand Down Expand Up @@ -578,9 +584,13 @@ void AutomationPattern::loadSettings( const QDomElement & _this )
int len = _this.attribute( "len" ).toInt();
if( len <= 0 )
{
len = length();
// TODO: Handle with an upgrade method
updateLength();
}
else
{
changeLength( len );
}
changeLength( len );
generateTangents();
}

Expand Down
1 change: 0 additions & 1 deletion src/core/SamplePlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "Engine.h"
#include "InstrumentTrack.h"
#include "Mixer.h"
#include "Pattern.h"
#include "SampleBuffer.h"
#include "SampleTrack.h"

Expand Down
3 changes: 1 addition & 2 deletions src/core/SampleRecordHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SampleRecordHandle.cpp - implementation of class SampleRecordHandle
*
* Copyright (c) 2008 Csaba Hruska <csaba.hruska/at/gmail.com>
*
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
Expand All @@ -28,7 +28,6 @@
#include "Engine.h"
#include "InstrumentTrack.h"
#include "Mixer.h"
#include "Pattern.h"
#include "SampleBuffer.h"
#include "SampleTrack.h"
#include "debug.h"
Expand Down
7 changes: 3 additions & 4 deletions src/gui/AutomationPatternView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ void AutomationPatternView::flipY()

void AutomationPatternView::flipX()
{
//m_pat->flipX( m_pat->length() );
m_pat->flipX( m_pat->TrackContentObject::length() );
m_pat->flipX( m_pat->length() );
update();
}

Expand Down Expand Up @@ -269,7 +268,7 @@ void AutomationPatternView::paintEvent( QPaintEvent * )

const float ppt = fixedTCOs() ?
( parentWidget()->width() - 2 * TCO_BORDER_WIDTH )
/ (float) m_pat->length().getTact() :
/ (float) m_pat->timeMapLength().getTact() :
pixelsPerTact();

const int x_base = TCO_BORDER_WIDTH;
Expand Down Expand Up @@ -341,7 +340,7 @@ void AutomationPatternView::paintEvent( QPaintEvent * )
const int lineSize = 3;
p.setPen( c.darker( 300 ) );

for( tact_t t = 1; t < m_pat->length().getTact(); ++t )
for( tact_t t = 1; t < m_pat->timeMapLength().getTact(); ++t )
{
const int tx = x_base + static_cast<int>( ppt * t ) - 2;
if( tx < ( width() - TCO_BORDER_WIDTH * 2 ) )
Expand Down
26 changes: 13 additions & 13 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,6 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
{
is_new_note = true;
m_pattern->addJournalCheckPoint();
m_pattern->setType( Pattern::MelodyPattern );

// then set new note

Expand Down Expand Up @@ -2426,7 +2425,18 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
{
if( note->selected() )
{
if( ! ( shift && ! m_startedWithShift ) )
if( shift && ! m_startedWithShift )
{
// quick resize, toggled by holding shift after starting a note move, but not before
int ticks_new = note->oldLength().getTicks() + off_ticks;
if( ticks_new <= 0 )
{
ticks_new = 1;
}
note->setLength( MidiTime( ticks_new ) );
m_lenOfNewNotes = note->length();
}
else
{
// moving note
int pos_ticks = note->oldPos().getTicks() + off_ticks;
Expand All @@ -2441,17 +2451,6 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
note->setPos( MidiTime( pos_ticks ) );
note->setKey( key_num );
}
else if( shift && ! m_startedWithShift )
{
// quick resize, toggled by holding shift after starting a note move, but not before
int ticks_new = note->oldLength().getTicks() + off_ticks;
if( ticks_new <= 0 )
{
ticks_new = 1;
}
note->setLength( MidiTime( ticks_new ) );
m_lenOfNewNotes = note->length();
}
}
}
}
Expand Down Expand Up @@ -2563,6 +2562,7 @@ void PianoRoll::dragNotes( int x, int y, bool alt, bool shift, bool ctrl )
}
}

m_pattern->updateLength();
m_pattern->dataChanged();
Engine::getSong()->setModified();
}
Expand Down
49 changes: 17 additions & 32 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,20 @@ void Pattern::init()
this, SLOT( changeTimeSignature() ) );
saveJournallingState( false );

changeLength( length() );
updateLength();
restoreJournallingState();
}




MidiTime Pattern::length() const
void Pattern::updateLength()
{
if( m_patternType == BeatPattern )
{
return beatPatternLength();
changeLength( beatPatternLength() );
updateBBTrack();
return;
}

tick_t max_length = MidiTime::ticksPerTact();
Expand All @@ -176,8 +178,9 @@ MidiTime Pattern::length() const
( *it )->endPos() );
}
}
return MidiTime( max_length ).nextFullTact() *
MidiTime::ticksPerTact();
changeLength( MidiTime( max_length ).nextFullTact() *
MidiTime::ticksPerTact() );
updateBBTrack();
}


Expand Down Expand Up @@ -242,12 +245,10 @@ Note * Pattern::addNote( const Note & _new_note, const bool _quant_pos )
instrumentTrack()->unlock();

checkType();
changeLength( length() );
updateLength();

emit dataChanged();

updateBBTrack();

return new_note;
}

Expand All @@ -271,11 +272,9 @@ void Pattern::removeNote( Note * _note_to_del )
instrumentTrack()->unlock();

checkType();
changeLength( length() );
updateLength();

emit dataChanged();

updateBBTrack();
}


Expand All @@ -296,17 +295,6 @@ Note * Pattern::noteAtStep( int _step )
}


Note * Pattern::rearrangeNote( Note * _note_to_proc, const bool _quant_pos )
{
// just rearrange the position of the note by removing it and adding
// a copy of it -> addNote inserts it at the correct position
Note copy_of_note( *_note_to_proc );
removeNote( _note_to_proc );

return addNote( copy_of_note, _quant_pos );
}



void Pattern::rearrangeAllNotes()
{
Expand Down Expand Up @@ -382,12 +370,12 @@ void Pattern::checkType()
{
if( ( *it )->length() > 0 )
{
setType( Pattern::MelodyPattern );
setType( MelodyPattern );
return;
}
++it;
}
setType( Pattern::BeatPattern );
setType( BeatPattern );
}


Expand All @@ -409,7 +397,6 @@ void Pattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
_this.setAttribute( "pos", startPosition() );
}
_this.setAttribute( "len", length() );
_this.setAttribute( "muted", isMuted() );
_this.setAttribute( "steps", m_steps );

Expand All @@ -433,7 +420,6 @@ void Pattern::loadSettings( const QDomElement & _this )
{
movePosition( _this.attribute( "pos" ).toInt() );
}
changeLength( MidiTime( _this.attribute( "len" ).toInt() ) );
if( _this.attribute( "muted" ).toInt() != isMuted() )
{
toggleMute();
Expand Down Expand Up @@ -461,10 +447,9 @@ void Pattern::loadSettings( const QDomElement & _this )
}

checkType();
updateLength();

emit dataChanged();

updateBBTrack();
}


Expand Down Expand Up @@ -508,8 +493,8 @@ void Pattern::clear()
void Pattern::addSteps()
{
m_steps += MidiTime::stepsPerTact();
updateLength();
emit dataChanged();
updateBBTrack();
}

void Pattern::cloneSteps()
Expand All @@ -529,8 +514,8 @@ void Pattern::cloneSteps()
newNote->setVolume( toCopy->getVolume() );
}
}
updateLength();
emit dataChanged();
updateBBTrack();
}


Expand All @@ -546,9 +531,9 @@ void Pattern::removeSteps()
setStep( i, false );
}
m_steps -= n;
updateLength();
emit dataChanged();
}
updateBBTrack();
}


Expand Down Expand Up @@ -609,7 +594,7 @@ void Pattern::changeTimeSignature()
last_pos = last_pos.nextFullTact() * MidiTime::ticksPerTact();
m_steps = qMax<tick_t>( MidiTime::stepsPerTact(),
last_pos.getTact() * MidiTime::stepsPerTact() );
updateBBTrack();
updateLength();
}


Expand Down

0 comments on commit 41b930e

Please sign in to comment.