Update Pattern and AutomationPattern length (#3037)

This commit is contained in:
Javier Serrano Polo
2016-09-17 23:51:00 +00:00
committed by GitHub
parent 48cc3bb5ef
commit 41b930eb66
8 changed files with 61 additions and 69 deletions

View File

@@ -73,7 +73,8 @@ public:
}
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 );

View File

@@ -63,9 +63,7 @@ public:
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 @@ public:
Note * noteAtStep( int _step );
Note * rearrangeNote( Note * _note_to_proc,
const bool _quant_pos = true );
void rearrangeAllNotes();
void clearNotes();
@@ -92,8 +88,6 @@ public:
{
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;

View File

@@ -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();
}

View File

@@ -28,7 +28,6 @@
#include "Engine.h"
#include "InstrumentTrack.h"
#include "Mixer.h"
#include "Pattern.h"
#include "SampleBuffer.h"
#include "SampleTrack.h"

View File

@@ -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
@@ -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"

View File

@@ -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<int>( ppt * t ) - 2;
if( tx < ( width() - TCO_BORDER_WIDTH * 2 ) )

View File

@@ -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();
}

View File

@@ -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<tick_t>( MidiTime::stepsPerTact(),
last_pos.getTact() * MidiTime::stepsPerTact() );
updateBBTrack();
updateLength();
}