Files
lmms/src/tracks/AutomationTrack.cpp
Lukas W 5f4cdac802 Merge branch 'master' into rename
Conflicts:
	src/core/Song.cpp
	src/gui/LfoControllerDialog.cpp
	src/tracks/InstrumentTrack.cpp
2014-11-26 11:45:55 +01:00

195 lines
4.2 KiB
C++

/*
* AutomationTrack.cpp - AutomationTrack handles automation of objects without
* a track
*
* Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
*
* This file is part of LMMS - http://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include "AutomationTrack.h"
#include "AutomationPattern.h"
#include "Engine.h"
#include "embed.h"
#include "ProjectJournal.h"
#include "StringPairDrag.h"
#include "TrackContainerView.h"
#include "TrackLabelButton.h"
AutomationTrack::AutomationTrack( TrackContainer* tc, bool _hidden ) :
Track( _hidden ? HiddenAutomationTrack : Track::AutomationTrack, tc )
{
setName( tr( "Automation track" ) );
}
AutomationTrack::~AutomationTrack()
{
}
bool AutomationTrack::play( const MidiTime & _start, const fpp_t _frames,
const f_cnt_t _frame_base, int _tco_num )
{
if( isMuted() )
{
return false;
}
tcoVector tcos;
if( _tco_num >= 0 )
{
TrackContentObject * tco = getTCO( _tco_num );
tcos.push_back( tco );
}
else
{
getTCOsInRange( tcos, _start, _start + static_cast<int>(
_frames / Engine::framesPerTick()) );
}
for( tcoVector::iterator it = tcos.begin(); it != tcos.end(); ++it )
{
AutomationPattern * p = dynamic_cast<AutomationPattern *>( *it );
if( p == NULL || ( *it )->isMuted() )
{
continue;
}
MidiTime cur_start = _start;
if( _tco_num < 0 )
{
cur_start -= p->startPosition();
}
p->processMidiTime( cur_start );
}
return false;
}
TrackView * AutomationTrack::createView( TrackContainerView* tcv )
{
return new AutomationTrackView( this, tcv );
}
TrackContentObject * AutomationTrack::createTCO( const MidiTime & )
{
return new AutomationPattern( this );
}
void AutomationTrack::saveTrackSpecificSettings( QDomDocument & _doc,
QDomElement & _this )
{
}
void AutomationTrack::loadTrackSpecificSettings( const QDomElement & _this )
{
// just in case something somehow wrent wrong...
if( type() == HiddenAutomationTrack )
{
setMuted( false );
}
}
AutomationTrackView::AutomationTrackView( AutomationTrack * _at, TrackContainerView* tcv ) :
TrackView( _at, tcv )
{
setFixedHeight( 32 );
TrackLabelButton * tlb = new TrackLabelButton( this,
getTrackSettingsWidget() );
tlb->setIcon( embed::getIconPixmap( "automation_track" ) );
tlb->move( 3, 1 );
tlb->show();
setModel( _at );
}
AutomationTrackView::~AutomationTrackView()
{
}
void AutomationTrackView::dragEnterEvent( QDragEnterEvent * _dee )
{
StringPairDrag::processDragEnterEvent( _dee, "automatable_model" );
}
void AutomationTrackView::dropEvent( QDropEvent * _de )
{
QString type = StringPairDrag::decodeKey( _de );
QString val = StringPairDrag::decodeValue( _de );
if( type == "automatable_model" )
{
AutomatableModel * mod = dynamic_cast<AutomatableModel *>(
Engine::projectJournal()->
journallingObject( val.toInt() ) );
if( mod != NULL )
{
MidiTime pos = MidiTime( trackContainerView()->
currentPosition() +
( _de->pos().x() -
getTrackContentWidget()->x() ) *
MidiTime::ticksPerTact() /
static_cast<int>( trackContainerView()->pixelsPerTact() ) )
.toAbsoluteTact();
if( pos.getTicks() < 0 )
{
pos.setTicks( 0 );
}
TrackContentObject * tco = getTrack()->createTCO( pos );
AutomationPattern * pat = dynamic_cast<AutomationPattern *>( tco );
pat->addObject( mod );
pat->movePosition( pos );
}
}
update();
}