2 * note.cpp - implementation of class note
4 * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
26 #include <QtXml/QDomElement>
31 #include "DetuningHelper.h"
32 #include "templates.h"
38 note::note( const midiTime
& _length
, const midiTime
& _pos
,
39 int _key
, volume_t _volume
, panning_t _panning
,
40 DetuningHelper
* _detuning
) :
42 m_oldKey( tLimit( _key
, 0, NumKeys
) ),
44 m_oldLength( _length
),
46 m_key( tLimit( _key
, 0, NumKeys
) ),
47 m_volume( tLimit( _volume
, MinVolume
, MaxVolume
) ),
48 m_panning( tLimit( _panning
, PanningLeft
, PanningRight
) ),
53 //saveJournallingState( false );
54 // setJournalling( false );
57 m_detuning
= sharedObject::ref( _detuning
);
63 //restoreJournallingState();
69 note::note( const note
& _note
) :
70 SerializingObject( _note
),
71 m_selected( _note
.m_selected
),
72 m_oldKey( _note
.m_oldKey
),
73 m_oldPos( _note
.m_oldPos
),
74 m_oldLength( _note
.m_oldLength
),
75 m_isPlaying( _note
.m_isPlaying
),
77 m_volume( _note
.m_volume
),
78 m_panning( _note
.m_panning
),
79 m_length( _note
.m_length
),
83 if( _note
.m_detuning
)
85 m_detuning
= sharedObject::ref( _note
.m_detuning
);
100 sharedObject::unref( m_detuning
);
107 void note::setLength( const midiTime
& _length
)
109 // addJournalEntry( journalEntry( ChangeLength, m_length - _length ) );
116 void note::setPos( const midiTime
& _pos
)
118 // addJournalEntry( journalEntry( ChangePosition, m_pos - _pos ) );
125 void note::setKey( const int _key
)
127 const int k
= tLimit( _key
, 0, NumKeys
);
128 // addJournalEntry( journalEntry( ChangeKey, m_key - k ) );
135 void note::setVolume( const volume_t _volume
)
137 const volume_t v
= tLimit( _volume
, MinVolume
, MaxVolume
);
138 // addJournalEntry( journalEntry( ChangeVolume, (int) m_volume - v ) );
145 void note::setPanning( const panning_t _panning
)
147 const panning_t p
= tLimit( _panning
, PanningLeft
, PanningRight
);
148 // addJournalEntry( journalEntry( ChangePanning, (int) m_panning - p ) );
155 midiTime
note::quantized( const midiTime
& _m
, const int _q_grid
)
157 float p
= ( (float) _m
/ _q_grid
);
158 if( p
- floorf( p
) < 0.5f
)
160 return( static_cast<int>( p
) * _q_grid
);
162 return( static_cast<int>( p
+ 1 ) * _q_grid
);
168 void note::quantizeLength( const int _q_grid
)
170 setLength( quantized( length(), _q_grid
) );
173 setLength( _q_grid
);
180 void note::quantizePos( const int _q_grid
)
182 setPos( quantized( pos(), _q_grid
) );
188 void note::saveSettings( QDomDocument
& _doc
, QDomElement
& _this
)
190 _this
.setAttribute( "key", m_key
);
191 _this
.setAttribute( "vol", m_volume
);
192 _this
.setAttribute( "pan", m_panning
);
193 _this
.setAttribute( "len", m_length
);
194 _this
.setAttribute( "pos", m_pos
);
197 m_detuning
->saveSettings( _doc
, _this
);
204 void note::loadSettings( const QDomElement
& _this
)
206 const int old_key
= _this
.attribute( "tone" ).toInt() +
207 _this
.attribute( "oct" ).toInt() * KeysPerOctave
;
208 m_key
= qMax( old_key
, _this
.attribute( "key" ).toInt() );
209 m_volume
= _this
.attribute( "vol" ).toInt();
210 m_panning
= _this
.attribute( "pan" ).toInt();
211 m_length
= _this
.attribute( "len" ).toInt();
212 m_pos
= _this
.attribute( "pos" ).toInt();
213 if( _this
.hasChildNodes() )
215 m_detuning
->loadSettings( _this
);
222 /*void note::undoStep( journalEntry & _je )
224 saveJournallingState( false );
225 switch( static_cast<Actions>( _je.actionID() ) )
228 setKey( key() - _je.data().toInt() );
232 setVolume( getVolume() - _je.data().toInt() );
236 setPanning( getPanning() - _je.data().toInt() );
240 setLength( length() - _je.data().toInt() );
244 setPos( pos() - _je.data().toInt() );
247 restoreJournallingState();
253 void note::redoStep( journalEntry & _je )
255 journalEntry je( _je.actionID(), -_je.data().toInt() );
262 void note::editDetuningPattern()
264 m_detuning
->automationPattern()->openInAutomationEditor();
270 void note::createDetuning()
272 m_detuning
= new DetuningHelper
;
273 (void) m_detuning
->automationPattern();
274 m_detuning
->setRange( -MaxDetuning
, MaxDetuning
, 0.1f
);
280 bool note::hasDetuningInfo() const
282 return m_detuning
&& m_detuning
->hasAutomation();