~ubuntu-branches/ubuntu/precise/lmms/precise-proposed

« back to all changes in this revision

Viewing changes to src/core/effect.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-12 13:32:32 UTC
  • mfrom: (1.1.9 upstream) (3.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20101112133232-vdld83iyji8srqti
Tags: 0.4.7-2ubuntu1
* Re-sync with Debian (LP: #606533):
  - Replace build-dep on libwine-dev with libwine-dev-unstable to build
    against the newer Wine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * effect.cpp - base-class for effects
3
 
 *
4
 
 * Copyright (c) 2006-2007 Danny McRae <khjklujn/at/users.sourceforge.net>
5
 
 * Copyright (c) 2006-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6
 
 * 
7
 
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or
10
 
 * modify it under the terms of the GNU General Public
11
 
 * License as published by the Free Software Foundation; either
12
 
 * version 2 of the License, or (at your option) any later version.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
 * General Public License for more details.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public
20
 
 * License along with this program (see COPYING); if not, write to the
21
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22
 
 * Boston, MA 02110-1301 USA.
23
 
 *
24
 
 */
25
 
 
26
 
 
27
 
#include <QtXml/QDomElement>
28
 
 
29
 
#include <cstdio>
30
 
 
31
 
#include "effect.h"
32
 
#include "engine.h"
33
 
#include "dummy_effect.h"
34
 
#include "effect_chain.h"
35
 
#include "effect_view.h"
36
 
 
37
 
 
38
 
effect::effect( const plugin::descriptor * _desc,
39
 
                        model * _parent,
40
 
                        const descriptor::subPluginFeatures::key * _key ) :
41
 
        plugin( _desc, _parent ),
42
 
        m_key( _key ? *_key : descriptor::subPluginFeatures::key()  ),
43
 
        m_processors( 1 ),
44
 
        m_okay( TRUE ),
45
 
        m_noRun( FALSE ),
46
 
        m_running( FALSE ),
47
 
        m_bufferCount( 0 ),
48
 
        m_enabledModel( TRUE, this, tr( "Effect enabled" ) ),
49
 
        m_wetDryModel( 1.0f, -1.0f, 1.0f, 0.01f, this, tr( "Wet/Dry mix" ) ),
50
 
        m_gateModel( 0.0f, 0.0f, 1.0f, 0.01f, this, tr( "Gate" ) ),
51
 
        m_autoQuitModel( 1.0f, 1.0f, 8000.0f, 100.0f, 1.0f, this, tr( "Decay" ) )
52
 
{
53
 
        m_srcState[0] = m_srcState[1] = NULL;
54
 
        reinitSRC();
55
 
}
56
 
 
57
 
 
58
 
 
59
 
 
60
 
effect::~effect()
61
 
{
62
 
        for( int i = 0; i < 2; ++i )
63
 
        {
64
 
                if( m_srcState[i] != NULL )
65
 
                {
66
 
                        src_delete( m_srcState[i] );
67
 
                }
68
 
        }
69
 
}
70
 
 
71
 
 
72
 
 
73
 
 
74
 
void effect::saveSettings( QDomDocument & _doc, QDomElement & _this )
75
 
{
76
 
        m_enabledModel.saveSettings( _doc, _this, "on" );
77
 
        m_wetDryModel.saveSettings( _doc, _this, "wet" );
78
 
        m_autoQuitModel.saveSettings( _doc, _this, "autoquit" );
79
 
        m_gateModel.saveSettings( _doc, _this, "gate" );
80
 
        getControls()->saveState( _doc, _this );
81
 
}
82
 
 
83
 
 
84
 
 
85
 
 
86
 
void effect::loadSettings( const QDomElement & _this )
87
 
{
88
 
        m_enabledModel.loadSettings( _this, "on" );
89
 
        m_wetDryModel.loadSettings( _this, "wet" );
90
 
        m_autoQuitModel.loadSettings( _this, "autoquit" );
91
 
        m_gateModel.loadSettings( _this, "gate" );
92
 
 
93
 
        QDomNode node = _this.firstChild();
94
 
        while( !node.isNull() )
95
 
        {
96
 
                if( node.isElement() )
97
 
                {
98
 
                        if( getControls()->nodeName() == node.nodeName() )
99
 
                        {
100
 
                                getControls()->restoreState( node.toElement() );
101
 
                        }
102
 
                }
103
 
                node = node.nextSibling();
104
 
        }
105
 
}
106
 
 
107
 
 
108
 
 
109
 
 
110
 
 
111
 
effect * effect::instantiate( const QString & _plugin_name,
112
 
                                model * _parent,
113
 
                                descriptor::subPluginFeatures::key * _key )
114
 
{
115
 
        plugin * p = plugin::instantiate( _plugin_name, _parent, _key );
116
 
        // check whether instantiated plugin is an effect
117
 
        if( dynamic_cast<effect *>( p ) != NULL )
118
 
        {
119
 
                // everything ok, so return pointer
120
 
                return( dynamic_cast<effect *>( p ) );
121
 
        }
122
 
 
123
 
        // not quite... so delete plugin and return dummy effect
124
 
        delete p;
125
 
        return( new dummyEffect( _parent ) );
126
 
}
127
 
 
128
 
 
129
 
 
130
 
 
131
 
void effect::checkGate( double _out_sum )
132
 
{
133
 
        // Check whether we need to continue processing input.  Restart the
134
 
        // counter if the threshold has been exceeded.
135
 
        if( _out_sum <= getGate()+0.000001 )
136
 
        {
137
 
                incrementBufferCount();
138
 
                if( getBufferCount() > getTimeout() )
139
 
                {
140
 
                        stopRunning();
141
 
                        resetBufferCount();
142
 
                }
143
 
        }
144
 
        else
145
 
        {
146
 
                resetBufferCount();
147
 
        }
148
 
}
149
 
 
150
 
 
151
 
 
152
 
 
153
 
pluginView * effect::instantiateView( QWidget * _parent )
154
 
{
155
 
        return( new effectView( this, _parent ) );
156
 
}
157
 
 
158
 
        
159
 
 
160
 
 
161
 
void effect::reinitSRC( void )
162
 
{
163
 
        for( int i = 0; i < 2; ++i )
164
 
        {
165
 
                if( m_srcState[i] != NULL )
166
 
                {
167
 
                        src_delete( m_srcState[i] );
168
 
                }
169
 
                int error;
170
 
                if( ( m_srcState[i] = src_new(
171
 
                        engine::getMixer()->currentQualitySettings().
172
 
                                                        libsrcInterpolation(),
173
 
                                        DEFAULT_CHANNELS, &error ) ) == NULL )
174
 
                {
175
 
                        fprintf( stderr, "Error: src_new() failed in effect.cpp!\n" );
176
 
                }
177
 
        }
178
 
}
179
 
 
180
 
 
181
 
 
182
 
 
183
 
void effect::resample( int _i, const sampleFrame * _src_buf,
184
 
                                                        sample_rate_t _src_sr,
185
 
                                sampleFrame * _dst_buf, sample_rate_t _dst_sr,
186
 
                                                                f_cnt_t _frames )
187
 
{
188
 
        if( m_srcState[_i] == NULL )
189
 
        {
190
 
                return;
191
 
        }
192
 
        m_srcData[_i].input_frames = _frames;
193
 
        m_srcData[_i].output_frames = engine::getMixer()->framesPerPeriod();
194
 
        m_srcData[_i].data_in = (float *) _src_buf[0];
195
 
        m_srcData[_i].data_out = _dst_buf[0];
196
 
        m_srcData[_i].src_ratio = (double) _dst_sr / _src_sr;
197
 
        m_srcData[_i].end_of_input = 0;
198
 
        int error;
199
 
        if( ( error = src_process( m_srcState[_i], &m_srcData[_i] ) ) )
200
 
        {
201
 
                fprintf( stderr, "effect::resample(): error while resampling: %s\n",
202
 
                                                        src_strerror( error ) );
203
 
        }
204
 
}
205
 
 
206