mirror of
https://github.com/LMMS/lmms.git
synced 2026-05-24 06:37:52 -04:00
More Automation refactoring
This commit is contained in:
@@ -68,8 +68,6 @@ public:
|
||||
return m_pattern != nullptr;
|
||||
}
|
||||
|
||||
int quantization() const;
|
||||
|
||||
virtual void saveSettings(QDomDocument & doc, QDomElement & parent);
|
||||
virtual void loadSettings(const QDomElement & parent);
|
||||
QString nodeName() const
|
||||
@@ -147,6 +145,8 @@ protected slots:
|
||||
void zoomingXChanged();
|
||||
void zoomingYChanged();
|
||||
|
||||
/// Updates the pattern's quantization using the current user selected value.
|
||||
void setQuantization();
|
||||
|
||||
private:
|
||||
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
void setCurrentPattern(AutomationPattern* pattern);
|
||||
const AutomationPattern* currentPattern();
|
||||
|
||||
int quantization() const;
|
||||
void open(AutomationPattern* pattern);
|
||||
|
||||
AutomationEditor* m_editor;
|
||||
|
||||
|
||||
@@ -136,15 +136,8 @@ public:
|
||||
virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
|
||||
virtual void loadSettings( const QDomElement & _this );
|
||||
|
||||
static inline const QString classNodeName()
|
||||
{
|
||||
return "automationpattern";
|
||||
}
|
||||
|
||||
inline virtual QString nodeName() const
|
||||
{
|
||||
return classNodeName();
|
||||
}
|
||||
static const QString classNodeName() { return "automationpattern"; }
|
||||
QString nodeName() const { return classNodeName(); }
|
||||
|
||||
void processMidiTime( const MidiTime & _time );
|
||||
|
||||
@@ -156,19 +149,14 @@ public:
|
||||
static AutomationPattern * globalAutomationPattern( AutomatableModel * _m );
|
||||
static void resolveAllIDs();
|
||||
|
||||
bool isRecording() const
|
||||
{
|
||||
return m_isRecording;
|
||||
}
|
||||
|
||||
void setRecording( const bool b )
|
||||
{
|
||||
m_isRecording = b;
|
||||
}
|
||||
bool isRecording() const { return m_isRecording; }
|
||||
void setRecording( const bool b ) { m_isRecording = b; }
|
||||
|
||||
static int quantization() { return s_quantization; }
|
||||
static void setQuantization(int q) { s_quantization = q; }
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void openInAutomationEditor();
|
||||
void objectDestroyed( jo_id_t );
|
||||
|
||||
private:
|
||||
@@ -192,6 +180,8 @@ private:
|
||||
bool m_isRecording;
|
||||
float m_lastRecordedValue;
|
||||
|
||||
static int s_quantization;
|
||||
|
||||
static const float DEFAULT_MIN_VALUE;
|
||||
static const float DEFAULT_MAX_VALUE;
|
||||
|
||||
|
||||
@@ -202,11 +202,10 @@ public:
|
||||
{
|
||||
return m_detuning;
|
||||
}
|
||||
|
||||
void editDetuningPattern();
|
||||
|
||||
bool hasDetuningInfo() const;
|
||||
|
||||
void createDetuning();
|
||||
|
||||
|
||||
protected:
|
||||
virtual void saveSettings( QDomDocument & _doc,
|
||||
@@ -228,10 +227,7 @@ private:
|
||||
MidiTime m_length;
|
||||
MidiTime m_pos;
|
||||
DetuningHelper * m_detuning;
|
||||
|
||||
void createDetuning();
|
||||
|
||||
} ;
|
||||
};
|
||||
|
||||
|
||||
typedef QVector<Note *> NoteVector;
|
||||
|
||||
@@ -25,12 +25,9 @@
|
||||
*/
|
||||
|
||||
#include <QDomElement>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
#include "AutomationPattern.h"
|
||||
#include "AutomationPatternView.h"
|
||||
#include "AutomationEditor.h"
|
||||
#include "AutomationTrack.h"
|
||||
#include "ProjectJournal.h"
|
||||
#include "BBTrackContainer.h"
|
||||
@@ -38,7 +35,7 @@
|
||||
#include "TextFloat.h"
|
||||
#include "embed.h"
|
||||
|
||||
|
||||
int AutomationPattern::s_quantization = 1;
|
||||
const float AutomationPattern::DEFAULT_MIN_VALUE = 0;
|
||||
const float AutomationPattern::DEFAULT_MAX_VALUE = 1;
|
||||
|
||||
@@ -181,10 +178,9 @@ MidiTime AutomationPattern::putValue( const MidiTime & _time,
|
||||
{
|
||||
cleanObjects();
|
||||
|
||||
MidiTime newTime = _quant_pos && Engine::automationEditor() ?
|
||||
Note::quantized( _time,
|
||||
Engine::automationEditor()->quantization() ) :
|
||||
_time;
|
||||
MidiTime newTime = _quant_pos ?
|
||||
Note::quantized( _time, quantization() ) :
|
||||
_time;
|
||||
|
||||
m_timeMap[newTime] = _value;
|
||||
timeMap::const_iterator it = m_timeMap.find( newTime );
|
||||
@@ -214,10 +210,9 @@ void AutomationPattern::removeValue( const MidiTime & _time,
|
||||
{
|
||||
cleanObjects();
|
||||
|
||||
MidiTime newTime = _quant_pos && Engine::automationEditor() ?
|
||||
Note::quantized( _time,
|
||||
Engine::automationEditor()->quantization() ) :
|
||||
_time;
|
||||
MidiTime newTime = _quant_pos ?
|
||||
Note::quantized( _time, quantization() ) :
|
||||
_time;
|
||||
|
||||
m_timeMap.remove( newTime );
|
||||
m_tangents.remove( newTime );
|
||||
@@ -254,10 +249,9 @@ MidiTime AutomationPattern::setDragValue( const MidiTime & _time, const float _v
|
||||
{
|
||||
if( m_dragging == false )
|
||||
{
|
||||
MidiTime newTime = _quant_pos && Engine::automationEditor() ?
|
||||
Note::quantized( _time,
|
||||
Engine::automationEditor()->quantization() ) :
|
||||
_time;
|
||||
MidiTime newTime = _quant_pos ?
|
||||
Note::quantized( _time, quantization() ) :
|
||||
_time;
|
||||
this->removeValue( newTime );
|
||||
m_oldTimeMap = m_timeMap;
|
||||
m_dragging = true;
|
||||
@@ -670,23 +664,6 @@ void AutomationPattern::clear()
|
||||
m_tangents.clear();
|
||||
|
||||
emit dataChanged();
|
||||
|
||||
if( Engine::automationEditor() &&
|
||||
Engine::automationEditor()->currentPattern() == this )
|
||||
{
|
||||
Engine::automationEditor()->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void AutomationPattern::openInAutomationEditor()
|
||||
{
|
||||
Engine::automationEditor()->setCurrentPattern( this );
|
||||
Engine::automationEditor()->parentWidget()->show();
|
||||
Engine::automationEditor()->show();
|
||||
Engine::automationEditor()->setFocus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -209,14 +209,6 @@ void Note::loadSettings( const QDomElement & _this )
|
||||
|
||||
|
||||
|
||||
void Note::editDetuningPattern()
|
||||
{
|
||||
createDetuning();
|
||||
m_detuning->automationPattern()->openInAutomationEditor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Note::createDetuning()
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "MainWindow.h"
|
||||
#include "StringPairDrag.h"
|
||||
|
||||
#include "AutomationEditor.h"
|
||||
|
||||
|
||||
|
||||
AutomatableModelView::AutomatableModelView( ::Model* model, QWidget* _this ) :
|
||||
@@ -224,7 +226,9 @@ void AutomatableModelViewSlots::removeConnection()
|
||||
|
||||
void AutomatableModelViewSlots::editSongGlobalAutomation()
|
||||
{
|
||||
AutomationPattern::globalAutomationPattern( m_amv->modelUntyped() )->openInAutomationEditor();
|
||||
Engine::automationEditor()->open(
|
||||
AutomationPattern::globalAutomationPattern(m_amv->modelUntyped())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ void AutomationPatternView::mouseDoubleClickEvent( QMouseEvent * _me )
|
||||
_me->ignore();
|
||||
return;
|
||||
}
|
||||
m_pat->openInAutomationEditor();
|
||||
Engine::automationEditor()->open(m_pat);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -118,6 +118,8 @@ AutomationEditor::AutomationEditor() :
|
||||
{
|
||||
m_quantizeModel.addItem( "1/" + QString::number( 1 << i ) );
|
||||
}
|
||||
|
||||
connect(&m_quantizeModel, SIGNAL(dataChanged()), this, SLOT(setQuantization()));
|
||||
m_quantizeModel.setValue( m_quantizeModel.findText( "1/16" ) );
|
||||
|
||||
// add time-line
|
||||
@@ -243,7 +245,6 @@ void AutomationEditor::updateAfterPatternChange()
|
||||
|
||||
if( !validPattern() )
|
||||
{
|
||||
setWindowTitle( tr( "Automation Editor - no pattern" ) );
|
||||
m_minLevel = m_maxLevel = m_scrollLevel = 0;
|
||||
m_step = 1;
|
||||
resizeEvent( NULL );
|
||||
@@ -259,8 +260,6 @@ void AutomationEditor::updateAfterPatternChange()
|
||||
// of levels and so on...)
|
||||
resizeEvent( NULL );
|
||||
|
||||
setWindowTitle( tr( "Automation Editor - %1" ).arg( m_pattern->name() ) );
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -374,22 +373,22 @@ void AutomationEditor::drawLine( int x0, float y0, int x1, float y1 )
|
||||
int xstep;
|
||||
int ystep;
|
||||
|
||||
if( deltax < quantization() )
|
||||
if( deltax < AutomationPattern::quantization() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
deltax /= quantization();
|
||||
deltax /= AutomationPattern::quantization();
|
||||
|
||||
float yscale = deltay / ( deltax );
|
||||
|
||||
if( x0 < x1)
|
||||
{
|
||||
xstep = quantization();
|
||||
xstep = AutomationPattern::quantization();
|
||||
}
|
||||
else
|
||||
{
|
||||
xstep = -( quantization() );
|
||||
xstep = -( AutomationPattern::quantization() );
|
||||
}
|
||||
|
||||
if( y0 < y1 )
|
||||
@@ -967,7 +966,7 @@ inline void AutomationEditor::drawAutomationPoint( QPainter & p, timeMap::iterat
|
||||
{
|
||||
int x = xCoordOfTick( it.key() );
|
||||
int y = yCoordOfLevel( it.value() );
|
||||
const int outerRadius = qBound( 2, ( m_ppt * quantization() ) / 576, 5 ); // man, getting this calculation right took forever
|
||||
const int outerRadius = qBound( 2, ( m_ppt * AutomationPattern::quantization() ) / 576, 5 ); // man, getting this calculation right took forever
|
||||
p.setPen( QPen( vertexColor().lighter( 200 ) ) );
|
||||
p.setBrush( QBrush( vertexColor() ) );
|
||||
p.drawEllipse( x - outerRadius, y - outerRadius, outerRadius * 2, outerRadius * 2 );
|
||||
@@ -1076,10 +1075,10 @@ void AutomationEditor::paintEvent(QPaintEvent * pe )
|
||||
// 3 independent loops, because quantization might not divide evenly into
|
||||
// exotic denominators (e.g. 7/11 time), which are allowed ATM.
|
||||
// First quantization grid...
|
||||
for( tick = m_currentPosition - m_currentPosition % quantization(),
|
||||
for( tick = m_currentPosition - m_currentPosition % AutomationPattern::quantization(),
|
||||
x = xCoordOfTick( tick );
|
||||
x<=width();
|
||||
tick += quantization(), x = xCoordOfTick( tick ) )
|
||||
tick += AutomationPattern::quantization(), x = xCoordOfTick( tick ) )
|
||||
{
|
||||
lineColor.setAlpha( 80 );
|
||||
p.setPen( lineColor );
|
||||
@@ -1910,9 +1909,10 @@ void AutomationEditor::zoomingYChanged()
|
||||
|
||||
|
||||
|
||||
int AutomationEditor::quantization() const
|
||||
void AutomationEditor::setQuantization()
|
||||
{
|
||||
return DefaultTicksPerTact / (1 << m_quantizeModel.value());
|
||||
int quantization = DefaultTicksPerTact / (1 << m_quantizeModel.value());;
|
||||
AutomationPattern::setQuantization(quantization);
|
||||
}
|
||||
|
||||
|
||||
@@ -2194,10 +2194,20 @@ AutomationEditorWindow::~AutomationEditorWindow()
|
||||
|
||||
void AutomationEditorWindow::setCurrentPattern(AutomationPattern* pattern)
|
||||
{
|
||||
if (currentPattern() != nullptr)
|
||||
{
|
||||
m_editor->m_pattern->disconnect(this);
|
||||
}
|
||||
|
||||
m_editor->setCurrentPattern(pattern);
|
||||
|
||||
if (pattern == nullptr)
|
||||
{
|
||||
setWindowTitle( tr( "Automation Editor - no pattern" ) );
|
||||
return;
|
||||
}
|
||||
|
||||
setWindowTitle( tr( "Automation Editor - %1" ).arg( m_editor->m_pattern->name() ) );
|
||||
|
||||
switch(m_editor->m_pattern->progressionType())
|
||||
{
|
||||
@@ -2212,6 +2222,7 @@ void AutomationEditorWindow::setCurrentPattern(AutomationPattern* pattern)
|
||||
break;
|
||||
}
|
||||
|
||||
connect(pattern, SIGNAL(dataChanged()), this, SLOT(update()));
|
||||
connect(pattern, SIGNAL(destroyed()), this, SLOT(clearCurrentPattern()));
|
||||
|
||||
emit currentPatternChanged();
|
||||
@@ -2223,10 +2234,12 @@ const AutomationPattern* AutomationEditorWindow::currentPattern()
|
||||
return m_editor->currentPattern();
|
||||
}
|
||||
|
||||
|
||||
int AutomationEditorWindow::quantization() const
|
||||
void AutomationEditorWindow::open(AutomationPattern* pattern)
|
||||
{
|
||||
return m_editor->quantization();
|
||||
setCurrentPattern(pattern);
|
||||
parentWidget()->show();
|
||||
show();
|
||||
setFocus();
|
||||
}
|
||||
|
||||
QSize AutomationEditorWindow::sizeHint() const
|
||||
@@ -2236,6 +2249,7 @@ QSize AutomationEditorWindow::sizeHint() const
|
||||
|
||||
void AutomationEditorWindow::clearCurrentPattern()
|
||||
{
|
||||
m_editor->m_pattern = nullptr;
|
||||
setCurrentPattern(nullptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "AutomationEditor.h"
|
||||
#include "ActionGroup.h"
|
||||
#include "ConfigManager.h"
|
||||
#include "PianoRoll.h"
|
||||
@@ -1210,7 +1211,9 @@ void PianoRoll::mousePressEvent(QMouseEvent * me )
|
||||
|
||||
if( m_editMode == ModeEditDetuning && noteUnderMouse() )
|
||||
{
|
||||
noteUnderMouse()->editDetuningPattern();
|
||||
Note* n = noteUnderMouse();
|
||||
if (n->detuning() == NULL) n->createDetuning();
|
||||
Engine::automationEditor()->open( noteUnderMouse()->detuning()->automationPattern() );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user