From 98a984b94d50df751cf9c632fd3e118f1a56fffd Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 7 Jul 2008 08:34:02 +0000 Subject: [PATCH] * additionally provide frequency without pitch-wheel * added instrumentTrack::midiPitch() git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1292 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/instrument_track.h | 7 +++++++ include/note_play_handle.h | 7 +++++++ src/core/note_play_handle.cpp | 11 ++++++----- src/tracks/instrument_track.cpp | 8 +++----- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/instrument_track.h b/include/instrument_track.h index 2995eb75f..866259010 100644 --- a/include/instrument_track.h +++ b/include/instrument_track.h @@ -94,8 +94,15 @@ public: // name-stuff virtual void setName( const QString & _new_name ); + // translate key of given notePlayHandle to absolute key (i.e. + // add global master-pitch and base-note in piano) int masterKey( notePlayHandle * _n ) const; + // translate pitch to midi-pitch [0,16383] + inline int midiPitch( void ) const + { + return( (int)( ( m_pitchModel.value()+100 ) * 81.92 ) ); + } // play everything in given frame-range - creates note-play-handles virtual bool play( const midiTime & _start, const fpp_t _frames, diff --git a/include/note_play_handle.h b/include/note_play_handle.h index a2b83fad6..2c9d27eba 100644 --- a/include/note_play_handle.h +++ b/include/note_play_handle.h @@ -63,6 +63,12 @@ public: void updateFrequency( void ); + // returns frequency without pitch-wheel influence + float unpitchedFrequency( void ) const + { + return( m_unpitchedFrequency ); + } + virtual void play( bool _try_parallelizing, sampleFrame * _working_buffer ); @@ -318,6 +324,7 @@ private: f_cnt_t m_orig_frames; // original m_frames float m_frequency; + float m_unpitchedFrequency; baseDetuning * m_baseDetuning; diff --git a/src/core/note_play_handle.cpp b/src/core/note_play_handle.cpp index 6ad9516ff..fd1f4d179 100644 --- a/src/core/note_play_handle.cpp +++ b/src/core/note_play_handle.cpp @@ -434,12 +434,13 @@ void notePlayHandle::updateFrequency( void ) KeysPerOctave; const int base_octave = m_instrumentTrack->baseNoteModel()->value() / KeysPerOctave; - const float pitch = (float)( key() % KeysPerOctave - base_tone + + const float pitch = ( key() % KeysPerOctave - base_tone + engine::getSong()->masterPitch() ) / 12.0f + - (float)( key() / KeysPerOctave - base_octave ) + - m_baseDetuning->value() / 12.0f + - m_instrumentTrack->m_pitchModel.value() / ( 100 * 12.0 ); - m_frequency = BaseFreq * powf( 2.0f, pitch ); + ( key() / KeysPerOctave - base_octave ) + + m_baseDetuning->value() / 12.0f; + m_frequency = BaseFreq * powf( 2.0f, pitch + + m_instrumentTrack->m_pitchModel.value() / ( 100 * 12.0 ) ); + m_unpitchedFrequency = BaseFreq * powf( 2.0f, pitch ); for( notePlayHandleVector::iterator it = m_subNotes.begin(); it != m_subNotes.end(); ++it ) diff --git a/src/tracks/instrument_track.cpp b/src/tracks/instrument_track.cpp index e1d4d5e42..94da9ab24 100644 --- a/src/tracks/instrument_track.cpp +++ b/src/tracks/instrument_track.cpp @@ -279,12 +279,10 @@ void instrumentTrack::processInEvent( const midiEvent & _me, break; case MidiPitchBend: - if( !m_instrument->handleMidiEvent( _me, _time ) ) - { - m_pitchModel.setValue( m_pitchModel.minValue() + + m_instrument->handleMidiEvent( _me, _time ); + m_pitchModel.setValue( m_pitchModel.minValue() + _me.m_data.m_param[0] * m_pitchModel.range() / 16384 ); - } break; case MidiControlChange: @@ -367,7 +365,7 @@ QString instrumentTrack::instrumentName( void ) const { return( m_instrument->publicName() ); } - return( "" ); + return( QString::null ); }