You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.3KB

  1. #ifndef STK_SKINI_H
  2. #define STK_SKINI_H
  3. #include "Stk.h"
  4. #include <vector>
  5. #include <string>
  6. #include <fstream>
  7. namespace stk {
  8. /***************************************************/
  9. /*! \class Skini
  10. \brief STK SKINI parsing class
  11. This class parses SKINI formatted text
  12. messages. It can be used to parse individual
  13. messages or it can be passed an entire file.
  14. The SKINI specification is Perry's and his
  15. alone, but it's all text so it shouldn't be too
  16. hard to figure out.
  17. SKINI (Synthesis toolKit Instrument Network
  18. Interface) is like MIDI, but allows for
  19. floating-point control changes, note numbers,
  20. etc. The following example causes a sharp
  21. middle C to be played with a velocity of 111.132:
  22. \code
  23. noteOn 60.01 111.132
  24. \endcode
  25. \sa \ref skini
  26. by Perry R. Cook and Gary P. Scavone, 1995--2017.
  27. */
  28. /***************************************************/
  29. class Skini : public Stk
  30. {
  31. public:
  32. //! A message structure to store and pass parsed SKINI messages.
  33. struct Message {
  34. long type; /*!< The message type, as defined in SKINImsg.h. */
  35. long channel; /*!< The message channel (not limited to 16!). */
  36. StkFloat time; /*!< The message time stamp in seconds (delta or absolute). */
  37. std::vector<StkFloat> floatValues; /*!< The message values read as floats (values are type-specific). */
  38. std::vector<long> intValues; /*!< The message values read as ints (number and values are type-specific). */
  39. std::string remainder; /*!< Any remaining message data, read as ascii text. */
  40. // Default constructor.
  41. Message()
  42. :type(0), channel(0), time(0.0), floatValues(2), intValues(2) {}
  43. };
  44. //! Default constructor.
  45. Skini();
  46. //! Class destructor
  47. ~Skini();
  48. //! Set a SKINI formatted file for reading.
  49. /*!
  50. If the file is successfully opened, this function returns \e
  51. true. Otherwise, \e false is returned.
  52. */
  53. bool setFile( std::string fileName );
  54. //! Parse the next file message (if a file is loaded) and return the message type.
  55. /*!
  56. This function skips over lines in a file which cannot be
  57. parsed. A type value equal to zero in the referenced message
  58. structure (and the returned value) indicates the file end is
  59. reached or no file is open for reading.
  60. */
  61. long nextMessage( Skini::Message& message );
  62. //! Attempt to parse the given string and returning the message type.
  63. /*!
  64. A type value equal to zero in the referenced message structure
  65. indicates an invalid message.
  66. */
  67. long parseString( std::string& line, Skini::Message& message );
  68. //! Return the SKINI type string for the given type value.
  69. static std::string whatsThisType(long type);
  70. //! Return the SKINI controller string for the given controller number.
  71. static std::string whatsThisController(long number);
  72. protected:
  73. void tokenize( const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters );
  74. std::ifstream file_;
  75. };
  76. //! A static table of equal-tempered MIDI to frequency (Hz) values.
  77. static const double Midi2Pitch[129] = {
  78. 8.176, 8.662, 9.177, 9.723, 10.301, 10.913, 11.562, 12.25,
  79. 12.978, 13.75, 14.568, 15.434, 16.352, 17.324, 18.354, 19.445,
  80. 20.602, 21.827, 23.125, 24.50, 25.957, 27.50, 29.135, 30.868,
  81. 32.703, 34.648, 36.708, 38.891, 41.203, 43.654, 46.249, 49.0,
  82. 51.913, 55.0, 58.271, 61.735, 65.406, 69.296, 73.416, 77.782,
  83. 82.407, 87.307, 92.499, 97.999, 103.826, 110.0, 116.541, 123.471,
  84. 130.813, 138.591, 146.832, 155.563, 164.814, 174.614, 184.997, 195.998,
  85. 207.652, 220.0, 233.082, 246.942, 261.626, 277.183, 293.665, 311.127,
  86. 329.628, 349.228, 369.994, 391.995, 415.305, 440.0, 466.164, 493.883,
  87. 523.251, 554.365, 587.33, 622.254, 659.255, 698.456, 739.989, 783.991,
  88. 830.609, 880.0, 932.328, 987.767, 1046.502, 1108.731, 1174.659, 1244.508,
  89. 1318.51, 1396.913, 1479.978, 1567.982, 1661.219, 1760.0, 1864.655, 1975.533,
  90. 2093.005, 2217.461, 2349.318, 2489.016, 2637.02, 2793.826, 2959.955, 3135.963,
  91. 3322.438, 3520.0, 3729.31, 3951.066, 4186.009, 4434.922, 4698.636, 4978.032,
  92. 5274.041, 5587.652, 5919.911, 6271.927, 6644.875, 7040.0, 7458.62, 7902.133,
  93. 8372.018, 8869.844, 9397.273, 9956.063, 10548.082, 11175.303, 11839.822, 12543.854,
  94. 13289.75};
  95. } // stk namespace
  96. #endif