*** empty log message ***
[chuck-blob.git] / v2 / skini.h
blobc4a82e68873b877540dc22be77fa9f694d3adfbb
1 /***************************************************/
2 /*! \class Skini
3 \brief STK SKINI parsing class
5 This class parses SKINI formatted text
6 messages. It can be used to parse individual
7 messages or it can be passed an entire file.
8 The SKINI specification is Perry's and his
9 alone, but it's all text so it shouldn't be too
10 hard to figure out.
12 SKINI (Synthesis toolKit Instrument Network
13 Interface) is like MIDI, but allows for
14 floating-point control changes, note numbers,
15 etc. The following example causes a sharp
16 middle C to be played with a velocity of 111.132:
18 \code
19 noteOn 60.01 111.132
20 \endcode
22 \sa \ref skini
24 by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
26 /***************************************************/
28 #ifndef SKINI_H
29 #define SKINI_H
31 //#include "Stk.h"
32 #include "ugen_stk.h"
33 #include <vector>
34 #include <string>
35 #include <fstream>
37 // from skini.msg
39 /*********************************************************/
41 Definition of SKINI Message Types and Special Symbols
42 Synthesis toolKit Instrument Network Interface
44 These symbols should have the form:
46 \c __SK_<name>_
48 where <name> is the string used in the SKINI stream.
50 by Perry R. Cook, 1995 - 2004.
52 /*********************************************************/
54 #define NOPE -32767
55 #define YEP 1
56 #define SK_DBL -32766
57 #define SK_INT -32765
58 #define SK_STR -32764
59 #define __SK_Exit_ 999
61 /***** MIDI COMPATIBLE MESSAGES *****/
62 /*** (Status bytes for channel=0) ***/
64 #define __SK_NoteOff_ 128
65 #define __SK_NoteOn_ 144
66 #define __SK_PolyPressure_ 160
67 #define __SK_ControlChange_ 176
68 #define __SK_ProgramChange_ 192
69 #define __SK_AfterTouch_ 208
70 #define __SK_ChannelPressure_ __SK_AfterTouch_
71 #define __SK_PitchWheel_ 224
72 #define __SK_PitchBend_ __SK_PitchWheel_
73 #define __SK_PitchChange_ 49
75 #define __SK_Clock_ 248
76 #define __SK_SongStart_ 250
77 #define __SK_Continue_ 251
78 #define __SK_SongStop_ 252
79 #define __SK_ActiveSensing_ 254
80 #define __SK_SystemReset_ 255
82 #define __SK_Volume_ 7
83 #define __SK_ModWheel_ 1
84 #define __SK_Modulation_ __SK_ModWheel_
85 #define __SK_Breath_ 2
86 #define __SK_FootControl_ 4
87 #define __SK_Portamento_ 65
88 #define __SK_Balance_ 8
89 #define __SK_Pan_ 10
90 #define __SK_Sustain_ 64
91 #define __SK_Damper_ __SK_Sustain_
92 #define __SK_Expression_ 11
94 #define __SK_AfterTouch_Cont_ 128
95 #define __SK_ModFrequency_ __SK_Expression_
97 #define __SK_ProphesyRibbon_ 16
98 #define __SK_ProphesyWheelUp_ 2
99 #define __SK_ProphesyWheelDown_ 3
100 #define __SK_ProphesyPedal_ 18
101 #define __SK_ProphesyKnob1_ 21
102 #define __SK_ProphesyKnob2_ 22
104 /*** Instrument Family Specific ***/
106 #define __SK_NoiseLevel_ __SK_FootControl_
108 #define __SK_PickPosition_ __SK_FootControl_
109 #define __SK_StringDamping_ __SK_Expression_
110 #define __SK_StringDetune_ __SK_ModWheel_
111 #define __SK_BodySize_ __SK_Breath_
112 #define __SK_BowPressure_ __SK_Breath_
113 #define __SK_BowPosition_ __SK_PickPosition_
114 #define __SK_BowBeta_ __SK_BowPosition_
116 #define __SK_ReedStiffness_ __SK_Breath_
117 #define __SK_ReedRestPos_ __SK_FootControl_
119 #define __SK_FluteEmbouchure_ __SK_Breath_
120 #define __SK_JetDelay_ __SK_FluteEmbouchure_
122 #define __SK_LipTension_ __SK_Breath_
123 #define __SK_SlideLength_ __SK_FootControl_
125 #define __SK_StrikePosition_ __SK_PickPosition_
126 #define __SK_StickHardness_ __SK_Breath_
128 #define __SK_TrillDepth_ 1051
129 #define __SK_TrillSpeed_ 1052
130 #define __SK_StrumSpeed_ __SK_TrillSpeed_
131 #define __SK_RollSpeed_ __SK_TrillSpeed_
133 #define __SK_FilterQ_ __SK_Breath_
134 #define __SK_FilterFreq_ 1062
135 #define __SK_FilterSweepRate_ __SK_FootControl_
137 #define __SK_ShakerInst_ 1071
138 #define __SK_ShakerEnergy_ __SK_Breath_
139 #define __SK_ShakerDamping_ __SK_ModFrequency_
140 #define __SK_ShakerNumObjects_ __SK_FootControl_
142 #define __SK_Strumming_ 1090
143 #define __SK_NotStrumming_ 1091
144 #define __SK_Trilling_ 1092
145 #define __SK_NotTrilling_ 1093
146 #define __SK_Rolling_ __SK_Strumming_
147 #define __SK_NotRolling_ __SK_NotStrumming_
149 #define __SK_PlayerSkill_ 2001
150 #define __SK_Chord_ 2002
151 #define __SK_ChordOff_ 2003
153 #define __SK_SINGER_FilePath_ 3000
154 #define __SK_SINGER_Frequency_ 3001
155 #define __SK_SINGER_NoteName_ 3002
156 #define __SK_SINGER_Shape_ 3003
157 #define __SK_SINGER_Glot_ 3004
158 #define __SK_SINGER_VoicedUnVoiced_ 3005
159 #define __SK_SINGER_Synthesize_ 3006
160 #define __SK_SINGER_Silence_ 3007
161 #define __SK_SINGER_VibratoAmt_ __SK_ModWheel_
162 #define __SK_SINGER_RndVibAmt_ 3008
163 #define __SK_SINGER_VibFreq_ __SK_Expression_
165 // end of skini.msg
168 // from skini.tbl
169 #define __SK_MaxMsgTypes_ 80
171 struct SkiniSpec { char messageString[32];
172 long type;
173 long data2;
174 long data3;
177 /* SEE COMMENT BLOCK AT BOTTOM FOR FIELDS AND USES */
178 /* MessageString , type, data2, data3 */
179 //break;
180 //return;
181 //goto later;
182 extern struct SkiniSpec skini_msgs[__SK_MaxMsgTypes_];
185 class Skini //: public Stk
187 public:
189 //! A message structure to store and pass parsed SKINI messages.
190 struct Message {
191 long type; /*!< The message type, as defined in SKINI.msg. */
192 long channel; /*!< The message channel (not limited to 16!). */
193 float time; /*!< The message time stamp in seconds (delta or absolute). */
194 std::vector<float> floatValues; /*!< The message values read as floats (values are type-specific). */
195 std::vector<long> intValues; /*!< The message values read as ints (number and values are type-specific). */
196 std::string remainder; /*!< Any remaining message data, read as ascii text. */
198 // Default constructor.
199 Message()
200 :type(0), channel(0), time(0.0), floatValues(2), intValues(2) {}
203 //! Default constructor.
204 Skini();
206 //! Class destructor
207 ~Skini();
209 //! Set a SKINI formatted file for reading.
211 If the file is successfully opened, this function returns \e
212 true. Otherwise, \e false is returned.
214 bool setFile( std::string fileName );
216 //! Parse the next file message (if a file is loaded) and return the message type.
218 This function skips over lines in a file which cannot be
219 parsed. A type value equal to zero in the referenced message
220 structure (and the returned value) indicates the file end is
221 reached or no file is open for reading.
223 long nextMessage( Skini::Message& message );
225 //! Attempt to parse the given string and returning the message type.
227 A type value equal to zero in the referenced message structure
228 indicates an invalid message.
230 long parseString( std::string& line, Skini::Message& message );
232 //! Attempt to write to file.
234 Given limited information instead of a whole message
236 bool write_message( long type, float time, long channel, float data1, float data2 );
238 //! Close file_
239 void close_file();
241 //! Return the SKINI type string for the given type value.
242 static std::string whatsThisType(long type);
244 //! Return the SKINI controller string for the given controller number.
245 static std::string whatsThisController(long number);
247 protected:
249 void tokenize( const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters );
251 std::fstream file_;
254 static const double Midi2Pitch[129] = {
255 8.18,8.66,9.18,9.72,10.30,10.91,11.56,12.25,
256 12.98,13.75,14.57,15.43,16.35,17.32,18.35,19.45,
257 20.60,21.83,23.12,24.50,25.96,27.50,29.14,30.87,
258 32.70,34.65,36.71,38.89,41.20,43.65,46.25,49.00,
259 51.91,55.00,58.27,61.74,65.41,69.30,73.42,77.78,
260 82.41,87.31,92.50,98.00,103.83,110.00,116.54,123.47,
261 130.81,138.59,146.83,155.56,164.81,174.61,185.00,196.00,
262 207.65,220.00,233.08,246.94,261.63,277.18,293.66,311.13,
263 329.63,349.23,369.99,392.00,415.30,440.00,466.16,493.88,
264 523.25,554.37,587.33,622.25,659.26,698.46,739.99,783.99,
265 830.61,880.00,932.33,987.77,1046.50,1108.73,1174.66,1244.51,
266 1318.51,1396.91,1479.98,1567.98,1661.22,1760.00,1864.66,1975.53,
267 2093.00,2217.46,2349.32,2489.02,2637.02,2793.83,2959.96,3135.96,
268 3322.44,3520.00,3729.31,3951.07,4186.01,4434.92,4698.64,4978.03,
269 5274.04,5587.65,5919.91,6271.93,6644.88,7040.00,7458.62,7902.13,
270 8372.02,8869.84,9397.27,9956.06,10548.08,11175.30,11839.82,12543.85,
271 13289.75};
273 #endif