1 /*
2  * string_container.cpp - contains a collection of strings
3  *
4  * Copyright (c) 2006 Danny McRae <khjklujn/at/yahoo/com>
5  *
6  * This file is part of LMMS - https://lmms.io
7  *
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.
12  *
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.
17  *
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.
22  *
23  */
24 
25 #include "string_container.h"
26 
27 
stringContainer(const float _pitch,const sample_rate_t _sample_rate,const int _buffer_length,const int _strings)28 stringContainer::stringContainer(const float _pitch,
29 				const sample_rate_t _sample_rate,
30 				const int _buffer_length,
31 				const int _strings ) :
32 	m_pitch( _pitch ),
33 	m_sampleRate( _sample_rate ),
34 	m_bufferLength( _buffer_length )
35 {
36 	for( int i = 0; i < _strings; i++ )
37 	{
38 		m_exists.append( false );
39 	}
40 }
41 
42 
43 
44 
addString(int _harm,const float _pick,const float _pickup,const float * _impulse,const float _randomize,const float _string_loss,const float _detune,const int _oversample,const bool _state,const int _id)45 void stringContainer::addString(int _harm,
46 				const float _pick,
47 				const float _pickup,
48 				const float * _impulse,
49 				const float _randomize,
50 				const float _string_loss,
51 				const float _detune,
52 				const int _oversample,
53 				const bool _state,
54 				const int _id )
55 {
56 	float harm;
57 	switch( _harm )
58 	{
59 		case 0:
60 			harm = 0.25f;
61 			break;
62 		case 1:
63 			harm = 0.5f;
64 			break;
65 		case 2:
66 			harm = 1.0f;
67 			break;
68 		case 3:
69 			harm = 2.0f;
70 			break;
71 		case 4:
72 			harm = 3.0f;
73 			break;
74 		case 5:
75 			harm = 4.0f;
76 			break;
77 		case 6:
78 			harm = 5.0f;
79 			break;
80 		case 7:
81 			harm = 6.0f;
82 			break;
83 		case 8:
84 			harm = 7.0f;
85 			break;
86 		default:
87 			harm = 1.0f;
88 	}
89 
90 	m_strings.append( new vibratingString(	m_pitch * harm,
91 						_pick,
92 						_pickup,
93 						const_cast<float*>(_impulse),
94 						m_bufferLength,
95 						m_sampleRate,
96 						_oversample,
97 						_randomize,
98 						_string_loss,
99 						_detune,
100 						_state ) );
101 	m_exists[_id] = true;
102 }
103