root/branches/transport_redesign_2/libs/hydrogen/src/note.cpp @ 1077

Revision 1077, 5.4 KB (checked in by gabriel@…, 4 years ago)

Convert Sampler to new transport.

All compile except Hydrogen and Sampler. Note that there are
several things not implemented (like SeqScriptIterator?).

Sampler would compile except for a reference to Song* for the tracking
outputs.

RevLine 
[3]1/*
2 * Hydrogen
[73]3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
[3]4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
[7]23#include <hydrogen/note.h>
[13]24#include <hydrogen/instrument.h>
[3]25
26#include <cassert>
[77]27#include <cstdlib>
[3]28
[73]29namespace H2Core
30{
[3]31
32Note::Note(
[73]33    Instrument *pInstrument,
34    float velocity,
35    float fPan_L,
36    float fPan_R,
37    int nLength,
38    float fPitch,
39    NoteKey key
[3]40)
[73]41                : Object( "Note" )
[1077]42                , m_nSilenceOffset( 0 )
43                , m_nReleaseOffset( 0 )
[73]44                , m_fSamplePosition( 0.0 )
45                , m_noteKey( key )
46                , m_fCutoff( 1.0 )
47                , m_fResonance( 0.0 )
48                , m_fBandPassFilterBuffer_L( 0.0 )
49                , m_fBandPassFilterBuffer_R( 0.0 )
50                , m_fLowPassFilterBuffer_L( 0.0 )
51                , m_fLowPassFilterBuffer_R( 0.0 )
[1077]52                , m_nHumanizeDelay( 0 )
[73]53                , __velocity( velocity )
[371]54                , __leadlag( 0.0 )
[3]55{
[54]56        set_pan_l( fPan_L );
57        set_pan_r( fPan_R );
[817]58        set_length( nLength );
[7]59
[53]60        set_instrument( pInstrument );
[54]61        set_pitch( fPitch );
[3]62}
63
64
65
66
67Note::Note( const Note* pNote )
[73]68                : Object( "Note" )
[3]69{
[1077]70        m_nSilenceOffset          = pNote->m_nSilenceOffset;
71        m_nReleaseOffset          = pNote->m_nReleaseOffset;
72        m_fSamplePosition         = pNote->m_fSamplePosition;
73        m_noteKey                 = pNote->m_noteKey;
74        // m_adsr copied in set_instrument()
75        m_fCutoff                 = pNote->m_fCutoff;
76        m_fResonance              = pNote->m_fResonance;
77        m_fBandPassFilterBuffer_L = pNote->m_fBandPassFilterBuffer_L;
78        m_fBandPassFilterBuffer_R = pNote->m_fBandPassFilterBuffer_R;
79        m_fLowPassFilterBuffer_L  = pNote->m_fLowPassFilterBuffer_L;
80        m_fLowPassFilterBuffer_R  = pNote->m_fLowPassFilterBuffer_R;
81        m_nHumanizeDelay          = pNote->m_nHumanizeDelay;
82        set_instrument(             pNote->__instrument );
83        __velocity                = pNote->get_velocity();
84        set_pan_l(                  pNote->get_pan_l() );
85        set_pan_r(                  pNote->get_pan_r() );
86        set_leadlag(                pNote->get_leadlag() );
87        set_length(                 pNote->get_length() );
88        set_pitch(                  pNote->get_pitch() );
[3]89}
90
91
92
93Note::~Note()
94{
95        //infoLog("DESTROY");
96        //delete m_pADSR;
97}
98
99
100
[53]101void Note::set_instrument( Instrument* instrument )
[3]102{
[53]103        if ( instrument == NULL ) {
[3]104                return;
105        }
106
[53]107        __instrument = instrument;
[73]108        assert( __instrument->get_adsr() );
109        m_adsr = ADSR( *( __instrument->get_adsr() ) );
[3]110
[73]111        /*
112                if ( pInstrument->m_pADSR == NULL ) {
113                        ERRORLOG( "NULL ADSR? Instrument: " + pInstrument->m_sName );
[3]114                }
[73]115                else {
116                        INFOLOG( "copio l'adsr dallo strumento" );
117                        if ( m_pADSR ) {
118                                WARNINGLOG( "Replacing an existing ADSR" );
119                                delete m_pADSR;
120                                m_pADSR = NULL;
121                        }
122                        m_pADSR = new ADSR( *(m_pInstrument->m_pADSR) );
123                }
124        */
[3]125}
126
127
128
[1077]129void Note::dumpInfo() const
[3]130{
[1074]131        INFOLOG( "humanize offset" + to_string(m_nHumanizeDelay) + "\t instr: " + __instrument->get_name()+ "\t key: " + keyToString( m_noteKey ) + "\t pitch: " + to_string( get_pitch() ) );
[3]132}
133
134
135
[127]136NoteKey Note::stringToKey( const QString& str )
[3]137{
138        NoteKey key;
139
[127]140        QString sKey = str.left( str.length() - 1 );
141        QString sOct = str.mid( str.length() - 1, str.length() );
142        int nOctave = sOct.toInt();
[3]143
144//      _INFOLOG( "skey: " + sKey );
145//      _INFOLOG( "sOct: " + sOct );
[57]146//      _INFOLOG( "nOctave: " + to_string( nOctave ) );
[3]147
148        if ( sKey == "C" ) {
149                key.m_key = NoteKey::C;
[73]150        } else if ( sKey == "Cs" ) {
[3]151                key.m_key = NoteKey::Cs;
[73]152        } else if ( sKey == "D" ) {
[3]153                key.m_key = NoteKey::D;
[73]154        } else if ( sKey == "Ef" ) {
[3]155                key.m_key = NoteKey::Ef;
[73]156        } else if ( sKey == "E" ) {
[3]157                key.m_key = NoteKey::E;
[73]158        } else if ( sKey == "F" ) {
[3]159                key.m_key = NoteKey::F;
[73]160        } else if ( sKey == "Fs" ) {
[3]161                key.m_key = NoteKey::Fs;
[73]162        } else if ( sKey == "G" ) {
[3]163                key.m_key = NoteKey::G;
[73]164        } else if ( sKey == "Af" ) {
[3]165                key.m_key = NoteKey::Af;
[73]166        } else if ( sKey == "A" ) {
[3]167                key.m_key = NoteKey::A;
[73]168        } else if ( sKey == "Bf" ) {
[3]169                key.m_key = NoteKey::Bf;
[73]170        } else if ( sKey == "B" ) {
[3]171                key.m_key = NoteKey::B;
[73]172        } else {
[3]173                _ERRORLOG( "Unhandled key: " + sKey );
174        }
175        key.m_nOctave = nOctave;
176
177        return key;
178}
179
180
181
[127]182QString Note::keyToString( NoteKey key )
[3]183{
[127]184        QString sKey;
[3]185
186        switch ( key.m_key ) {
[73]187        case NoteKey::C:
188                sKey = "C";
189                break;
190        case NoteKey::Cs:
191                sKey = "Cs";
192                break;
193        case NoteKey::D:
194                sKey = "D";
195                break;
196        case NoteKey::Ef:
197                sKey = "Ef";
198                break;
199        case NoteKey::E:
200                sKey = "E";
201                break;
202        case NoteKey::F:
203                sKey = "F";
204                break;
205        case NoteKey::Fs:
206                sKey = "Fs";
207                break;
208        case NoteKey::G:
209                sKey = "G";
210                break;
211        case NoteKey::Af:
212                sKey = "Af";
213                break;
214        case NoteKey::A:
215                sKey = "A";
216                break;
217        case NoteKey::Bf:
218                sKey = "Bf";
219                break;
220        case NoteKey::B:
221                sKey = "B";
222                break;
[3]223
224        }
225
[57]226        sKey += to_string( key.m_nOctave );
[3]227
228        return sKey;
229}
230
[53]231
232Note* Note::copy()
233{
234        Note* note = new Note(
[73]235            get_instrument(),
236            get_velocity(),
237            get_pan_l(),
238            get_pan_r(),
[817]239            get_length(),
[73]240            get_pitch(),
241            m_noteKey
[53]242        );
243
[210]244        note->set_leadlag(get_leadlag());
[53]245
246
247        return note;
248}
249
250
[3]251};
Note: See TracBrowser for help on using the browser.