string_container.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "string_container.h"
  25. stringContainer::stringContainer(const float _pitch,
  26. const sample_rate_t _sample_rate,
  27. const int _buffer_length,
  28. const int _strings ) :
  29. m_pitch( _pitch ),
  30. m_sampleRate( _sample_rate ),
  31. m_bufferLength( _buffer_length )
  32. {
  33. for( int i = 0; i < _strings; i++ )
  34. {
  35. m_exists.append( false );
  36. }
  37. }
  38. void stringContainer::addString(int _harm,
  39. const float _pick,
  40. const float _pickup,
  41. const float * _impulse,
  42. const float _randomize,
  43. const float _string_loss,
  44. const float _detune,
  45. const int _oversample,
  46. const bool _state,
  47. const int _id )
  48. {
  49. float harm;
  50. switch( _harm )
  51. {
  52. case 0:
  53. harm = 0.25f;
  54. break;
  55. case 1:
  56. harm = 0.5f;
  57. break;
  58. case 2:
  59. harm = 1.0f;
  60. break;
  61. case 3:
  62. harm = 2.0f;
  63. break;
  64. case 4:
  65. harm = 3.0f;
  66. break;
  67. case 5:
  68. harm = 4.0f;
  69. break;
  70. case 6:
  71. harm = 5.0f;
  72. break;
  73. case 7:
  74. harm = 6.0f;
  75. break;
  76. case 8:
  77. harm = 7.0f;
  78. break;
  79. default:
  80. harm = 1.0f;
  81. }
  82. m_strings.append( new vibratingString( m_pitch * harm,
  83. _pick,
  84. _pickup,
  85. const_cast<float*>(_impulse),
  86. m_bufferLength,
  87. m_sampleRate,
  88. _oversample,
  89. _randomize,
  90. _string_loss,
  91. _detune,
  92. _state ) );
  93. m_exists[_id] = true;
  94. }