~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to src/core/envelope_tab_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Tobias Doerffel
  • Date: 2007-09-17 15:00:24 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070917150024-mo0zk4ks81jawqii
Tags: 0.3.0-1ubuntu1
* Resynchronized with Debian (LP: #139759, LP: #90806, LP: #102639,
  LP: #113447, LP: #121172, LP: #124890)
* reverted changes from 0.2.1-1.1ubuntu1 as upstream merged/included them

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * envelope_tab_widget.cpp - widget for use in envelope/lfo/filter-tab of
5
5
 *                           instrument-track-window
6
6
 *
7
 
 * Copyright (c) 2004-2006 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
7
 * Copyright (c) 2004-2007 Tobias Doerffel <tobydox/at/users.sourceforge.net>
8
8
 * 
9
9
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
10
10
 *
20
20
 *
21
21
 * You should have received a copy of the GNU General Public
22
22
 * License along with this program (see COPYING); if not, write to the
23
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24
 
 * Boston, MA 02111-1307, USA.
 
23
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
24
 * Boston, MA 02110-1301 USA.
25
25
 *
26
26
 */
27
27
 
41
41
 
42
42
 
43
43
#include "envelope_tab_widget.h"
 
44
#include "combobox.h"
 
45
#include "embed.h"
 
46
#include "engine.h"
44
47
#include "envelope_and_lfo_widget.h"
45
 
#include "note_play_handle.h"
46
 
#include "knob.h"
47
 
#include "pixmap_button.h"
48
48
#include "group_box.h"
49
 
#include "tab_widget.h"
50
 
#include "embed.h"
51
49
#include "gui_templates.h"
52
50
#include "instrument_track.h"
53
 
#include "combobox.h"
 
51
#include "knob.h"
 
52
#include "note_play_handle.h"
 
53
#include "tab_widget.h"
54
54
 
55
55
 
56
56
 
84
84
 
85
85
envelopeTabWidget::envelopeTabWidget( instrumentTrack * _instrument_track ) :
86
86
        QWidget( _instrument_track->tabWidgetParent() ),
87
 
        journallingObject( _instrument_track->eng() )
 
87
        m_instrumentTrack( _instrument_track )
88
88
{
89
89
 
90
90
        m_targetsTabWidget = new tabWidget( tr( "TARGET" ), this );
121
121
                m_envLFOWidgets[i] = new envelopeAndLFOWidget(
122
122
                                                        value_for_zero_amount,
123
123
                                                        m_targetsTabWidget,
124
 
                                                        eng(),
125
124
                                                        _instrument_track );
126
125
                m_targetsTabWidget->addTab( m_envLFOWidgets[i],
127
126
                                                tr( targetNames[i][0]
137
136
        }
138
137
        
139
138
        
140
 
        m_filterGroupBox = new groupBox( tr( "FILTER" ), this, eng(),
 
139
        m_filterGroupBox = new groupBox( tr( "FILTER" ), this,
141
140
                                                        _instrument_track );
142
141
        m_filterGroupBox->setGeometry( FILTER_GROUPBOX_X, FILTER_GROUPBOX_Y,
143
142
                                                FILTER_GROUPBOX_WIDTH,
144
143
                                                FILTER_GROUPBOX_HEIGHT );
145
144
 
146
145
        m_filterComboBox = new comboBox( m_filterGroupBox, tr( "Filter type" ),
147
 
                                                eng(), _instrument_track );
 
146
                                                        _instrument_track );
148
147
        m_filterComboBox->setGeometry( 14, 22, 120, 22 );
149
148
        m_filterComboBox->setFont( pointSize<8>( m_filterComboBox->font() ) );
150
149
 
178
177
 
179
178
        m_filterCutKnob = new knob( knobBright_26, m_filterGroupBox,
180
179
                                                tr( "cutoff-frequency" ),
181
 
                                                eng(), _instrument_track );
 
180
                                                _instrument_track );
182
181
        m_filterCutKnob->setLabel( tr( "CUTOFF" ) );
183
182
        m_filterCutKnob->setRange( 0.0, 14000.0, 1.0 );
184
183
        m_filterCutKnob->move( 140, 18 );
198
197
                        "frequencies below cutoff-frequency and so on..." ) );
199
198
 
200
199
        m_filterResKnob = new knob( knobBright_26, m_filterGroupBox,
201
 
                                                tr( "Q/Resonance" ),
202
 
                                                eng(), _instrument_track );
 
200
                                                        tr( "Q/Resonance" ),
 
201
                                                        _instrument_track );
203
202
        m_filterResKnob->setLabel( tr( "Q/RESO" ) );
204
 
        m_filterResKnob->setRange( 0.01, 10.0, 0.01 );
 
203
        m_filterResKnob->setRange( basicFilters<>::minQ(), 10.0, 0.01 );
205
204
        m_filterResKnob->move( 190, 18 );
206
205
        m_filterResKnob->setInitValue( 0.5 );
207
206
        m_filterResKnob->setHintText( tr( "Q/Resonance:" ) + " ", "" );
235
234
 
236
235
        if( _n->released() == FALSE )
237
236
        {
238
 
                release_begin += eng()->getMixer()->framesPerAudioBuffer();
 
237
                release_begin += engine::getMixer()->framesPerPeriod();
239
238
        }
240
239
 
241
 
        return( m_envLFOWidgets[VOLUME]->level( _frame, release_begin, 0 ) );
 
240
        float volume_level;
 
241
        m_envLFOWidgets[VOLUME]->fillLevel( &volume_level, _frame,
 
242
                                                        release_begin, 1 );
 
243
 
 
244
        return( volume_level );
242
245
}
243
246
 
244
247
 
245
248
 
246
249
 
247
250
void envelopeTabWidget::processAudioBuffer( sampleFrame * _ab,
248
 
                                                        const fpab_t _frames,
 
251
                                                        const fpp_t _frames,
249
252
                                                        notePlayHandle * _n )
250
253
{
251
 
        f_cnt_t total_frames = _n->totalFramesPlayed();
 
254
        const f_cnt_t total_frames = _n->totalFramesPlayed();
252
255
        f_cnt_t release_begin = total_frames - _n->releaseFramesDone() +
253
256
                                                _n->framesBeforeRelease();
254
257
 
255
258
        if( _n->released() == FALSE )
256
259
        {
257
 
                release_begin += eng()->getMixer()->framesPerAudioBuffer();
 
260
                release_begin += engine::getMixer()->framesPerPeriod();
258
261
        }
259
262
 
260
263
        // because of optimizations, there's special code for several cases:
261
 
        //      - volume-, cut- and res-lfo/envelope active
262
 
        //      - volume- and cut-lfo/envelope active
263
 
        //      - volume- and res-lfo/envelope active
 
264
        //      - cut- and res-lfo/envelope active
264
265
        //      - cut-lfo/envelope active
265
266
        //      - res-lfo/envelope active
266
 
        //      - volume-lfo/envelope active
267
267
        //      - no lfo/envelope active but filter is used
268
 
        // now there's a lot of similar code but I didn't found a way to
269
 
        // generalize it yet... may be later we could do that
270
 
        // by using preprocessor and macro-expansion... (like in oscillator.cpp)
271
268
 
272
269
        // only use filter, if it is really needed
273
270
 
274
 
        if( _n->m_filter == NULL )
275
 
        {
276
 
                _n->m_filter = new basicFilters<>(
277
 
                                        eng()->getMixer()->sampleRate() );
278
 
        }
279
 
 
280
271
        if( m_filterGroupBox->isActive() )
281
272
        {
282
273
                int old_filter_cut = 0;
283
274
                int old_filter_res = 0;
284
275
 
285
 
                basicFilters<>::filterTypes filter =
286
 
                                basicFilters<>::getFilterType(
287
 
                                        m_filterComboBox->value() );
288
 
 
289
 
                if( m_envLFOWidgets[VOLUME]->used() &&
290
 
                        m_envLFOWidgets[CUT]->used() &&
 
276
                if( _n->m_filter == NULL )
 
277
                {
 
278
                        _n->m_filter = new basicFilters<>(
 
279
                                        engine::getMixer()->sampleRate() );
 
280
                }
 
281
                _n->m_filter->setFilterType( m_filterComboBox->value() );
 
282
 
 
283
                float * cut_buf = NULL;
 
284
                float * res_buf = NULL;
 
285
 
 
286
                if( m_envLFOWidgets[CUT]->used() )
 
287
                {
 
288
                        cut_buf = new float[_frames];
 
289
                        m_envLFOWidgets[CUT]->fillLevel( cut_buf, total_frames,
 
290
                                                release_begin, _frames );
 
291
                }
 
292
                if( m_envLFOWidgets[RES]->used() )
 
293
                {
 
294
                        res_buf = new float[_frames];
 
295
                        m_envLFOWidgets[RES]->fillLevel( res_buf, total_frames,
 
296
                                                release_begin, _frames );
 
297
                }
 
298
 
 
299
                if( m_envLFOWidgets[CUT]->used() &&
291
300
                        m_envLFOWidgets[RES]->used() )
292
301
                {
293
 
                        for( fpab_t frame = 0; frame < _frames;
294
 
                                                ++frame, ++total_frames )
 
302
                        for( fpp_t frame = 0; frame < _frames; ++frame )
295
303
                        {
296
 
                                float new_cut_val = m_envLFOWidgets[CUT]->level( total_frames, release_begin, frame );
297
 
                                new_cut_val = envelopeAndLFOWidget::expKnobVal( new_cut_val ) * CUT_FREQ_MULTIPLIER +
 
304
                                float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
298
305
                                                m_filterCutKnob->value();
299
306
 
300
307
                                float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
301
 
                                                        m_envLFOWidgets[RES]->level( total_frames, release_begin, frame );
 
308
                                                        res_buf[frame];
302
309
 
303
310
                                if( static_cast<int>( new_cut_val ) != old_filter_cut ||
304
311
                                        static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
305
312
                                {
306
 
                                        _n->m_filter->calcFilterCoeffs( filter, new_cut_val, new_res_val );
307
 
                                        old_filter_cut = static_cast<int>( new_cut_val );
308
 
                                        old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
309
 
                                }
310
 
 
311
 
                                float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
312
 
                                vol_level = vol_level*vol_level;
313
 
 
314
 
                                for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
315
 
                                {
316
 
                                        _ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
317
 
                                }
318
 
                        }
319
 
                }
320
 
                else if( m_envLFOWidgets[VOLUME]->used() && m_envLFOWidgets[CUT]->used() )
321
 
                {
322
 
                        for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
323
 
                        {
324
 
                                float new_cut_val = m_envLFOWidgets[CUT]->level( total_frames, release_begin, frame );
325
 
                                new_cut_val = envelopeAndLFOWidget::expKnobVal( new_cut_val ) * CUT_FREQ_MULTIPLIER +
326
 
                                                m_filterCutKnob->value();
327
 
 
328
 
                                if( static_cast<int>( new_cut_val ) != old_filter_cut )
329
 
                                {
330
 
                                        _n->m_filter->calcFilterCoeffs( filter, new_cut_val, m_filterResKnob->value() );
331
 
                                        old_filter_cut = static_cast<int>( new_cut_val );
332
 
                                }
333
 
 
334
 
                                float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
335
 
                                vol_level = vol_level*vol_level;
336
 
 
337
 
                                for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
338
 
                                {
339
 
                                        _ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
340
 
                                }
341
 
                        }
342
 
                }
343
 
                else if( m_envLFOWidgets[VOLUME]->used() && m_envLFOWidgets[RES]->used() )
344
 
                {
345
 
 
346
 
                        for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
347
 
                        {
348
 
                                float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
349
 
                                                        m_envLFOWidgets[RES]->level( total_frames, release_begin, frame );
350
 
 
351
 
                                if( static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
352
 
                                {
353
 
                                        _n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), new_res_val );
354
 
                                        old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
355
 
                                }
356
 
 
357
 
                                float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
358
 
                                vol_level = vol_level*vol_level;
359
 
 
360
 
                                for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
361
 
                                {
362
 
                                        _ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
363
 
                                }
364
 
                        }
365
 
 
 
313
                                        _n->m_filter->calcFilterCoeffs( new_cut_val, new_res_val );
 
314
                                        old_filter_cut = static_cast<int>( new_cut_val );
 
315
                                        old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
 
316
                                }
 
317
 
 
318
                                for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
 
319
                                {
 
320
                                        _ab[frame][chnl] = _n->m_filter->update( _ab[frame][chnl], chnl );
 
321
                                }
 
322
                        }
366
323
                }
367
324
                else if( m_envLFOWidgets[CUT]->used() )
368
325
                {
369
 
                        for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
 
326
                        for( fpp_t frame = 0; frame < _frames; ++frame )
370
327
                        {
371
 
                                float new_cut_val = m_envLFOWidgets[CUT]->level( total_frames, release_begin, frame );
372
 
                                new_cut_val = envelopeAndLFOWidget::expKnobVal( new_cut_val ) * CUT_FREQ_MULTIPLIER +
 
328
                                float new_cut_val = envelopeAndLFOWidget::expKnobVal( cut_buf[frame] ) * CUT_FREQ_MULTIPLIER +
373
329
                                                m_filterCutKnob->value();
374
330
 
375
331
                                if( static_cast<int>( new_cut_val ) != old_filter_cut )
376
332
                                {
377
 
                                        _n->m_filter->calcFilterCoeffs( filter, new_cut_val, m_filterResKnob->value() );
 
333
                                        _n->m_filter->calcFilterCoeffs( new_cut_val, m_filterResKnob->value() );
378
334
                                        old_filter_cut = static_cast<int>( new_cut_val );
379
335
                                }
380
336
 
386
342
                }
387
343
                else if( m_envLFOWidgets[RES]->used() )
388
344
                {
389
 
                        for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
 
345
                        for( fpp_t frame = 0; frame < _frames; ++frame )
390
346
                        {
391
347
                                float new_res_val = m_filterResKnob->value() + RES_MULTIPLIER *
392
 
                                                        m_envLFOWidgets[RES]->level( total_frames, release_begin, frame );
 
348
                                                        res_buf[frame];
393
349
 
394
350
                                if( static_cast<int>( new_res_val*RES_PRECISION ) != old_filter_res )
395
351
                                {
396
 
                                        _n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), new_res_val );
 
352
                                        _n->m_filter->calcFilterCoeffs( m_filterCutKnob->value(), new_res_val );
397
353
                                        old_filter_res = static_cast<int>( new_res_val*RES_PRECISION );
398
354
                                }
399
355
 
403
359
                                }
404
360
                        }
405
361
                }
406
 
                else if( m_envLFOWidgets[VOLUME]->used() )
407
 
                {
408
 
                        _n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), m_filterResKnob->value() );
409
 
 
410
 
                        for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
411
 
                        {
412
 
                                float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
413
 
                                vol_level = vol_level*vol_level;
414
 
 
415
 
                                for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
416
 
                                {
417
 
                                        _ab[frame][chnl] = vol_level * _n->m_filter->update( _ab[frame][chnl], chnl );
418
 
                                }
419
 
                        }
420
 
                }
421
362
                else
422
363
                {
423
 
                        _n->m_filter->calcFilterCoeffs( filter, m_filterCutKnob->value(), m_filterResKnob->value() );
 
364
                        _n->m_filter->calcFilterCoeffs( m_filterCutKnob->value(), m_filterResKnob->value() );
424
365
 
425
 
                        for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
 
366
                        for( fpp_t frame = 0; frame < _frames; ++frame )
426
367
                        {
427
368
                                for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
428
369
                                {
430
371
                                }
431
372
                        }
432
373
                }
 
374
 
 
375
                delete[] cut_buf;
 
376
                delete[] res_buf;
433
377
        }
434
 
        else if( m_envLFOWidgets[VOLUME]->used() /*&& m_envLFOWidgets[PANNING]->used() == FALSE*/ )
 
378
 
 
379
        if( m_envLFOWidgets[VOLUME]->used() )
435
380
        {
436
 
                // only use volume-envelope...
437
 
                for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
 
381
                float * vol_buf = new float[_frames];
 
382
                m_envLFOWidgets[VOLUME]->fillLevel( vol_buf, total_frames,
 
383
                                                release_begin, _frames );
 
384
 
 
385
                for( fpp_t frame = 0; frame < _frames; ++frame )
438
386
                {
439
 
                        float vol_level = m_envLFOWidgets[VOLUME]->level( total_frames, release_begin, frame );
440
 
                        vol_level = vol_level*vol_level;
441
 
                        for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
 
387
                        float vol_level = vol_buf[frame];
 
388
                        vol_level = vol_level * vol_level;
 
389
                        for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS;
 
390
                                                                        ++chnl )
442
391
                        {
443
392
                                _ab[frame][chnl] = vol_level * _ab[frame][chnl];
444
393
                        }
445
394
                }
 
395
                delete[] vol_buf;
446
396
        }
 
397
 
447
398
/*      else if( m_envLFOWidgets[VOLUME]->used() == FALSE && m_envLFOWidgets[PANNING]->used() )
448
399
        {
449
400
                // only use panning-envelope...
450
 
                for( fpab_t frame = 0; frame < _frames; ++frame, ++total_frames )
 
401
                for( fpp_t frame = 0; frame < _frames; ++frame )
451
402
                {
452
 
                        float vol_level = m_envLFOWidgets[PANNING]->level( total_frames, release_begin, frame );
 
403
                        float vol_level = pan_buf[frame];
453
404
                        vol_level = vol_level*vol_level;
454
405
                        for( ch_cnt_t chnl = 0; chnl < DEFAULT_CHANNELS; ++chnl )
455
406
                        {
487
438
{
488
439
        f_cnt_t ret_val = m_envLFOWidgets[VOLUME]->used() ?
489
440
                                        m_envLFOWidgets[VOLUME]->m_rFrames : 0;
 
441
        if( m_instrumentTrack->getInstrument()->desiredReleaseFrames() >
 
442
                                                                ret_val )
 
443
        {
 
444
                ret_val = m_instrumentTrack->getInstrument()->
 
445
                                                        desiredReleaseFrames();
 
446
        }
 
447
 
490
448
        if( m_envLFOWidgets[VOLUME]->used() == FALSE )
491
449
        {
492
450
                for( int i = VOLUME+1; i < TARGET_COUNT; ++i )
509
467
        m_filterComboBox->saveSettings( _doc, _this, "ftype" );
510
468
        m_filterCutKnob->saveSettings( _doc, _this, "fcut" );
511
469
        m_filterResKnob->saveSettings( _doc, _this, "fres" );
512
 
        _this.setAttribute( "fwet", m_filterGroupBox->isActive() );
 
470
        m_filterGroupBox->saveSettings( _doc, _this, "fwet" );
513
471
 
514
472
        for( int i = 0; i < TARGET_COUNT; ++i )
515
473
        {
527
485
        m_filterComboBox->loadSettings( _this, "ftype" );
528
486
        m_filterCutKnob->loadSettings( _this, "fcut" );
529
487
        m_filterResKnob->loadSettings( _this, "fres" );
530
 
/*      m_filterState->setChecked( _this.attribute( "fwet" ).toInt() );*/
531
 
        m_filterGroupBox->setState( _this.attribute( "fwet" ).toInt() );
 
488
        m_filterGroupBox->loadSettings( _this, "fwet" );
532
489
 
533
490
        QDomNode node = _this.firstChild();
534
491
        while( !node.isNull() )