From 41b930eb66ac05340ea5a8f120ee7090bb18886e Mon Sep 17 00:00:00 2001 From: Javier Serrano Polo Date: Sat, 17 Sep 2016 23:51:00 +0000 Subject: [PATCH] Update Pattern and AutomationPattern length (#3037) --- include/AutomationPattern.h | 3 +- include/Pattern.h | 13 ++++---- src/core/AutomationPattern.cpp | 28 ++++++++++++------ src/core/SamplePlayHandle.cpp | 1 - src/core/SampleRecordHandle.cpp | 3 +- src/gui/AutomationPatternView.cpp | 7 ++--- src/gui/editors/PianoRoll.cpp | 26 ++++++++-------- src/tracks/Pattern.cpp | 49 +++++++++++-------------------- 8 files changed, 61 insertions(+), 69 deletions(-) diff --git a/include/AutomationPattern.h b/include/AutomationPattern.h index 58127d02c9c..1ac6dced15a 100644 --- a/include/AutomationPattern.h +++ b/include/AutomationPattern.h @@ -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 ); diff --git a/include/Pattern.h b/include/Pattern.h index 6270f390d6a..cb5464539da 100644 --- a/include/Pattern.h +++ b/include/Pattern.h @@ -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 ); @@ -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(); @@ -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 @@ -135,6 +129,11 @@ protected slots: private: + MidiTime beatPatternLength() const; + + void setType( PatternTypes _new_pattern_type ); + void checkType(); + void resizeToFirstTrack(); InstrumentTrack * m_instrumentTrack; diff --git a/src/core/AutomationPattern.cpp b/src/core/AutomationPattern.cpp index 12db6dc2eb6..fc9fc42a9a1 100644 --- a/src/core/AutomationPattern.cpp +++ b/src/core/AutomationPattern.cpp @@ -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(); @@ -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 ) @@ -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(); @@ -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(); @@ -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() ) ); @@ -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(); } diff --git a/src/core/SamplePlayHandle.cpp b/src/core/SamplePlayHandle.cpp index 0d222583bba..b7bbb036231 100644 --- a/src/core/SamplePlayHandle.cpp +++ b/src/core/SamplePlayHandle.cpp @@ -28,7 +28,6 @@ #include "Engine.h" #include "InstrumentTrack.h" #include "Mixer.h" -#include "Pattern.h" #include "SampleBuffer.h" #include "SampleTrack.h" diff --git a/src/core/SampleRecordHandle.cpp b/src/core/SampleRecordHandle.cpp index a082b2f5d7a..19c840bc192 100644 --- a/src/core/SampleRecordHandle.cpp +++ b/src/core/SampleRecordHandle.cpp @@ -2,7 +2,7 @@ * SampleRecordHandle.cpp - implementation of class SampleRecordHandle * * Copyright (c) 2008 Csaba Hruska - * + * * This file is part of LMMS - http://lmms.io * * This program is free software; you can redistribute it and/or @@ -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" diff --git a/src/gui/AutomationPatternView.cpp b/src/gui/AutomationPatternView.cpp index a4faac5501f..d2b4382b34d 100644 --- a/src/gui/AutomationPatternView.cpp +++ b/src/gui/AutomationPatternView.cpp @@ -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(); } @@ -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; @@ -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( ppt * t ) - 2; if( tx < ( width() - TCO_BORDER_WIDTH * 2 ) ) diff --git a/src/gui/editors/PianoRoll.cpp b/src/gui/editors/PianoRoll.cpp index 3e66a5c594a..9d456476dab 100644 --- a/src/gui/editors/PianoRoll.cpp +++ b/src/gui/editors/PianoRoll.cpp @@ -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 @@ -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; @@ -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(); - } } } } @@ -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(); } diff --git a/src/tracks/Pattern.cpp b/src/tracks/Pattern.cpp index 47385af0149..b8f648a27ee 100644 --- a/src/tracks/Pattern.cpp +++ b/src/tracks/Pattern.cpp @@ -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(); @@ -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(); } @@ -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; } @@ -271,11 +272,9 @@ void Pattern::removeNote( Note * _note_to_del ) instrumentTrack()->unlock(); checkType(); - changeLength( length() ); + updateLength(); emit dataChanged(); - - updateBBTrack(); } @@ -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() { @@ -382,12 +370,12 @@ void Pattern::checkType() { if( ( *it )->length() > 0 ) { - setType( Pattern::MelodyPattern ); + setType( MelodyPattern ); return; } ++it; } - setType( Pattern::BeatPattern ); + setType( BeatPattern ); } @@ -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 ); @@ -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(); @@ -461,10 +447,9 @@ void Pattern::loadSettings( const QDomElement & _this ) } checkType(); + updateLength(); emit dataChanged(); - - updateBBTrack(); } @@ -508,8 +493,8 @@ void Pattern::clear() void Pattern::addSteps() { m_steps += MidiTime::stepsPerTact(); + updateLength(); emit dataChanged(); - updateBBTrack(); } void Pattern::cloneSteps() @@ -529,8 +514,8 @@ void Pattern::cloneSteps() newNote->setVolume( toCopy->getVolume() ); } } + updateLength(); emit dataChanged(); - updateBBTrack(); } @@ -546,9 +531,9 @@ void Pattern::removeSteps() setStep( i, false ); } m_steps -= n; + updateLength(); emit dataChanged(); } - updateBBTrack(); } @@ -609,7 +594,7 @@ void Pattern::changeTimeSignature() last_pos = last_pos.nextFullTact() * MidiTime::ticksPerTact(); m_steps = qMax( MidiTime::stepsPerTact(), last_pos.getTact() * MidiTime::stepsPerTact() ); - updateBBTrack(); + updateLength(); }