1
#ifndef SINGLE_SOURCE_COMPILE
4
* automation_pattern.cpp - implementation of class automationPattern which
7
* Copyright (c) 2006-2007 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
9
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
11
* This program is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU General Public
13
* License as published by the Free Software Foundation; either
14
* version 2 of the License, or (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* General Public License for more details.
21
* You should have received a copy of the GNU General Public
22
* License along with this program (see COPYING); if not, write to the
23
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24
* Boston, MA 02110-1301 USA.
29
#include "qt3support.h"
43
#include "automation_pattern.h"
44
#include "automation_editor.h"
46
#include "level_object.h"
48
#include "templates.h"
54
automationPattern::automationPattern( track * _track, levelObject * _object ) :
57
m_update_first( TRUE ),
65
automationPattern::automationPattern( const automationPattern & _pat_to_copy ) :
68
m_track( _pat_to_copy.m_track ),
69
m_object( _pat_to_copy.m_object ),
70
m_update_first( _pat_to_copy.m_update_first ),
71
m_dynamic( _pat_to_copy.m_dynamic )
73
for( timeMap::const_iterator it = _pat_to_copy.m_time_map.begin();
74
it != _pat_to_copy.m_time_map.end(); ++it )
76
m_time_map[it.key()] = it.value();
79
if( m_dynamic && m_track )
81
m_track->addAutomationPattern( this );
88
automationPattern::automationPattern( const automationPattern & _pat_to_copy,
89
levelObject * _object ) :
90
m_track( _pat_to_copy.m_track ),
92
m_update_first( _pat_to_copy.m_update_first ),
93
m_dynamic( _pat_to_copy.m_dynamic )
95
for( timeMap::const_iterator it = _pat_to_copy.m_time_map.begin();
96
it != _pat_to_copy.m_time_map.end(); ++it )
98
m_time_map[it.key()] = it.value();
101
if( m_dynamic && m_track )
103
m_track->addAutomationPattern( this );
110
automationPattern::~automationPattern()
112
if( m_dynamic && m_track )
114
m_track->removeAutomationPattern( this );
117
if( engine::getAutomationEditor()
118
&& engine::getAutomationEditor()->currentPattern() == this )
120
engine::getAutomationEditor()->setCurrentPattern( NULL );
128
midiTime automationPattern::length( void ) const
130
Sint32 max_length = 0;
132
for( timeMap::const_iterator it = m_time_map.begin();
133
it != m_time_map.end();
136
max_length = tMax<Sint32>( max_length, -it.key() );
138
if( max_length % 64 == 0 )
140
return( midiTime( tMax<Sint32>( max_length, 64 ) ) );
142
return( midiTime( tMax( midiTime( max_length ).getTact() + 1, 1 ),
149
midiTime automationPattern::putValue( const midiTime & _time, const int _value,
150
const bool _quant_pos )
152
midiTime new_time = _quant_pos ?
153
note::quantized( _time,
154
engine::getAutomationEditor()->quantization() ) :
157
m_time_map[-new_time] = _value;
159
if( !m_dynamic && new_time != 0 )
164
m_track->addAutomationPattern( this );
174
void automationPattern::removeValue( const midiTime & _time )
178
m_time_map.remove( -_time );
180
if( m_time_map.size() == 1 )
183
m_object->setLevel( m_time_map[0] );
186
m_track->removeAutomationPattern( this );
195
void automationPattern::clear( void )
198
if( engine::getAutomationEditor()->currentPattern() == this )
200
engine::getAutomationEditor()->update();
207
int automationPattern::valueAt( const midiTime & _time )
209
return( m_time_map.lowerBound( -_time ).value() );
215
void automationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this )
217
for( timeMap::iterator it = m_time_map.begin(); it != m_time_map.end();
220
QDomElement element = _doc.createElement( "time" );
221
element.setAttribute( "pos", -it.key() );
222
element.setAttribute( "value", m_object->levelToLabel(
224
_this.appendChild( element );
231
void automationPattern::loadSettings( const QDomElement & _this )
235
for( QDomNode node = _this.firstChild(); !node.isNull();
236
node = node.nextSibling() )
238
QDomElement element = node.toElement();
239
if( element.isNull() || element.tagName() != "time" )
243
m_time_map[-element.attribute( "pos" ).toInt()]
244
= m_object->labelToLevel(
245
element.attribute( "value" ) );
253
m_track->addAutomationPattern( this );
261
void automationPattern::openInAutomationEditor( void )
263
engine::getAutomationEditor()->setCurrentPattern( this );
264
engine::getAutomationEditor()->show();
265
engine::getAutomationEditor()->setFocus();
271
const QString automationPattern::name( void )
275
QString widget_name = dynamic_cast<QWidget *>( m_object )
277
return( m_track->name() + " - " + widget_name );
281
return( m_object->displayName() );
288
void automationPattern::processMidiTime( const midiTime & _time )
292
m_object->setLevel( m_time_map.lowerBound( -_time ).value() );
299
#include "automation_pattern.moc"