1 /************************** BEGIN AUUI.h **************************/ 2 /************************************************************************ 3 FAUST Audio Unit UI 4 Copyright (C) 2013 Reza Payami 5 All rights reserved. 6 ----------------------------BSD License------------------------------ 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions 9 are met: 10 11 * Redistributions of source code must retain the above copyright 12 notice, this list of conditions and the following disclaimer. 13 * Redistributions in binary form must reproduce the above 14 copyright notice, this list of conditions and the following 15 disclaimer in the documentation and/or other materials provided 16 with the distribution. 17 * Neither the name of Remy Muller nor the names of its 18 contributors may be used to endorse or promote products derived 19 from this software without specific prior written permission. 20 21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 32 OF THE POSSIBILITY OF SUCH DAMAGE. 33 34 ----------------------------Audio Unit SDK---------------------------------- 35 In order to compile a AU (TM) Synth plugin with this architecture file 36 you will need the proprietary AU SDK from Apple. Please check 37 the corresponding license. 38 ************************************************************************/ 39 40 #include <set> 41 42 #include "faust/gui/UI.h" 43 #include "faust/gui/MetaDataUI.h" 44 45 using namespace std; 46 47 class auUI; 48 49 struct auUIObject { 50 51 string fLabel; 52 FAUSTFLOAT* fZone; 53 rangeauUIObject54 FAUSTFLOAT range(FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT val) 55 { // AU parameters are normalized in the range [0;1] 56 val = min + val * (max - min); 57 return (val < min) ? min : (val > max) ? max : val; 58 } 59 auUIObjectauUIObject60 auUIObject(const char* label, FAUSTFLOAT* zone): fLabel(label), fZone(zone) 61 {} 62 ~auUIObjectauUIObject63 virtual ~auUIObject() 64 {} 65 GetNameauUIObject66 virtual void GetName(char *text) 67 { 68 std::strcpy(text, fLabel.c_str()); 69 } 70 SetValueauUIObject71 virtual void SetValue(double f) 72 { 73 *fZone = range(0.0f, 1.0f, FAUSTFLOAT(f)); 74 } 75 GetValueauUIObject76 virtual FAUSTFLOAT GetValue() 77 { 78 return *fZone; 79 } 80 GetDisplayauUIObject81 virtual void GetDisplay(char *text) 82 { 83 std::sprintf(text, "%f", *fZone); 84 } 85 GetIDauUIObject86 virtual long GetID() 87 { /* returns the sum of all the ASCII characters contained in the parameter's label */ 88 int i; 89 long acc; 90 for (i = 0, acc = 0; i < fLabel.length(); i++) 91 acc += (fLabel.c_str())[i]; 92 return acc; 93 } 94 }; 95 96 /**********************************************************************************/ 97 struct auToggleButton: public auUIObject { 98 auToggleButtonauToggleButton99 auToggleButton(const char* label, FAUSTFLOAT* zone) : 100 auUIObject(label, zone) 101 {} 102 ~auToggleButtonauToggleButton103 virtual ~auToggleButton() 104 {} 105 GetValueauToggleButton106 virtual FAUSTFLOAT GetValue() 107 { 108 return *fZone; 109 } 110 SetValueauToggleButton111 virtual void SetValue(double f) 112 { 113 *fZone = (f > 0.5f) ? 1.0f : 0.0f; 114 } 115 GetDisplayauToggleButton116 virtual void GetDisplay(char *text) 117 { 118 (*fZone > 0.5f) ? std::strcpy(text, "ON") : std::strcpy(text, "OFF"); 119 } 120 121 }; 122 123 /**********************************************************************************/ 124 struct auCheckButton: public auUIObject { 125 auCheckButtonauCheckButton126 auCheckButton(const char* label, FAUSTFLOAT* zone) : 127 auUIObject(label, zone) 128 {} 129 ~auCheckButtonauCheckButton130 virtual ~auCheckButton() 131 {} 132 GetValueauCheckButton133 virtual FAUSTFLOAT GetValue() 134 { 135 return *fZone; 136 } 137 SetValueauCheckButton138 virtual void SetValue(double f) 139 { 140 *fZone = (f > 0.5f) ? 1.0f : 0.0f; 141 } 142 GetDisplayauCheckButton143 virtual void GetDisplay(char *text) 144 { 145 (*fZone > 0.5f) ? std::strcpy(text, "ON") : std::strcpy(text, "OFF"); 146 } 147 148 }; 149 150 /**********************************************************************************/ 151 struct auButton: public auUIObject { 152 auButtonauButton153 auButton(const char* label, FAUSTFLOAT* zone) : 154 auUIObject(label, zone) 155 {} 156 ~auButtonauButton157 virtual ~auButton() 158 {} 159 GetValueauButton160 virtual FAUSTFLOAT GetValue() 161 { 162 return *fZone; 163 } 164 SetValueauButton165 virtual void SetValue(double f) 166 { 167 *fZone = (f > 0.5f) ? 1.0f : 0.0f; 168 } 169 GetDisplayauButton170 virtual void GetDisplay(char *text) 171 { 172 (*fZone > 0.5f) ? std::strcpy(text, "ON") : std::strcpy(text, "OFF"); 173 } 174 175 }; 176 177 /**********************************************************************************/ 178 struct auSlider: public auUIObject { 179 180 FAUSTFLOAT fInit; 181 FAUSTFLOAT fMin; 182 FAUSTFLOAT fMax; 183 FAUSTFLOAT fStep; 184 bool fIsVertical; 185 auSliderauSlider186 auSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, 187 FAUSTFLOAT step, bool isVertical) : 188 auUIObject(label, zone), fInit(init), fMin(min), fMax(max), fStep(step), fIsVertical(isVertical) 189 {} 190 ~auSliderauSlider191 virtual ~auSlider() 192 {} 193 GetValueauSlider194 virtual FAUSTFLOAT GetValue() 195 { 196 return (*fZone - fMin) / (fMax - fMin); 197 } // normalize 198 SetValueauSlider199 virtual void SetValue(double f) 200 { 201 *fZone = range(fMin, fMax, FAUSTFLOAT(f)); 202 } // expand 203 204 }; 205 206 /**********************************************************************************/ 207 208 struct auBargraph: public auUIObject { 209 210 FAUSTFLOAT fInit; 211 FAUSTFLOAT fMin; 212 FAUSTFLOAT fMax; 213 FAUSTFLOAT fStep; 214 bool fIsVertical; 215 auBargraphauBargraph216 auBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max, bool isVertical) : 217 auUIObject(label, zone), fMin(min), fMax(max), fIsVertical(isVertical) 218 {} 219 ~auBargraphauBargraph220 virtual ~auBargraph() 221 {} 222 GetValueauBargraph223 virtual FAUSTFLOAT GetValue() 224 { 225 return (*fZone - fMin) / (fMax - fMin); 226 } // normalize 227 SetValueauBargraph228 virtual void SetValue(double f) 229 { 230 *fZone = range(fMin, fMax, FAUSTFLOAT(f)); 231 } // expand 232 233 }; 234 235 /**********************************************************************************/ 236 237 struct auBox: public auUIObject { 238 239 vector<auUIObject*> fChildren; 240 bool fIsVertical; 241 auBox* parent; 242 auBoxauBox243 auBox(const char* label, auBox* inParent, bool inIsVertical) : 244 auUIObject(label, NULL), parent(inParent), fIsVertical(inIsVertical) 245 {} 246 ~auBoxauBox247 virtual ~auBox() 248 {} 249 addauBox250 void add(auUIObject* child) 251 { 252 fChildren.push_back(child); 253 } 254 255 }; 256 257 /**********************************************************************************/ 258 //eunum Direction {HORIZONTAL, VERTICAL}; //TODO 259 260 struct auUI: public UI, public MetaDataUI { 261 262 vector<auUIObject*> fUITable; 263 264 auBox* currentBox = NULL; 265 auBox* boundingBox = NULL; 266 auUIauUI267 auUI() 268 { 269 currentBox = boundingBox = new auBox("", NULL, true); 270 } 271 ~auUIauUI272 virtual ~auUI() 273 { 274 for (vector<auUIObject*>::iterator iter = fUITable.begin(); 275 iter != fUITable.end(); iter++) 276 delete *iter; 277 // TODO delete boxes 278 } 279 addButtonauUI280 void addButton(const char* label, FAUSTFLOAT* zone) 281 { 282 auButton* button = new auButton(label, zone); 283 fUITable.push_back(button); 284 currentBox->add(button); 285 } 286 openTabBoxauUI287 void openTabBox(const char* label) 288 {} 289 addCheckButtonauUI290 void addCheckButton(const char* label, FAUSTFLOAT* zone) 291 { 292 auCheckButton* checkButton= new auCheckButton(label, zone); 293 fUITable.push_back(checkButton); 294 currentBox->add(checkButton); 295 } 296 addVerticalSliderauUI297 void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) 298 { 299 auSlider* slider = new auSlider(label, zone, init, min, max, step, true); 300 fUITable.push_back(slider); 301 currentBox->add(slider); 302 } 303 addHorizontalSliderauUI304 void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) 305 { 306 auSlider* slider = new auSlider(label, zone, init, min, max, step, false); 307 fUITable.push_back(slider); 308 currentBox->add(slider); 309 } 310 addNumEntryauUI311 void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) 312 { 313 auSlider* slider = new auSlider(label, zone, init, min, max, step, false); 314 fUITable.push_back(slider); 315 currentBox->add(slider); 316 } 317 addHorizontalBargraphauUI318 void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) 319 { 320 auBargraph* bargraph = new auBargraph(label, zone, min, max, false); 321 fUITable.push_back(bargraph); 322 currentBox->add(bargraph); 323 } 324 addVerticalBargraphauUI325 void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) 326 { 327 auBargraph* bargraph = new auBargraph(label, zone, min, max, true); 328 fUITable.push_back(bargraph); 329 currentBox->add(bargraph); 330 } 331 addSoundfileauUI332 void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) {} 333 openHorizontalBoxauUI334 void openHorizontalBox(const char* label) 335 { 336 auBox* box = new auBox(label, currentBox, false); 337 currentBox->add(box); 338 currentBox = box; 339 } 340 openVerticalBoxauUI341 void openVerticalBox(const char* label) 342 { 343 auBox* box = new auBox(label, currentBox, true); 344 currentBox->add(box); 345 currentBox = box; 346 } 347 closeBoxauUI348 void closeBox() 349 { 350 if (currentBox) { //TODO else? 351 currentBox = currentBox->parent; 352 } 353 } 354 SetValueauUI355 void SetValue(int index, double f) 356 { 357 assert(index < fUITable.size()); 358 fUITable[index]->SetValue(f); 359 } 360 GetValueauUI361 FAUSTFLOAT GetValue(long index) 362 { 363 assert(index < fUITable.size()); 364 return fUITable[index]->GetValue(); 365 } 366 GetDisplayauUI367 void GetDisplay(long index, char *text) 368 { 369 assert(index < fUITable.size()); 370 fUITable[index]->GetDisplay(text); 371 } 372 GetNameauUI373 void GetName(long index, char *text) 374 { 375 assert(index < fUITable.size()); 376 fUITable[index]->GetName(text); 377 } 378 GetNumParamsauUI379 long GetNumParams() 380 { 381 return fUITable.size(); 382 } 383 makeIDauUI384 long makeID() 385 /* Creates a (unique) id by summing all the parameter's labels, 386 * then wrapping it in the range [0;maxNumberOfId] and adding 387 * this number to the offset made by the Four Character ID: 'FAUS' 388 */ 389 { 390 const long maxNumberOfId = 128; 391 long baseid = 'FAUS'; 392 long id = 0; 393 for (int i = 0; i < fUITable.size(); i++) 394 id += fUITable[i]->GetID(); 395 return baseid + id % maxNumberOfId; 396 } 397 addNumDisplayauUI398 void addNumDisplay(char* label, FAUSTFLOAT* zone, int precision) 399 {} 400 addTextDisplayauUI401 void addTextDisplay(char* label, FAUSTFLOAT* zone, char* names[], FAUSTFLOAT min, FAUSTFLOAT max) 402 {} 403 404 }; 405 406 407 /************************** END AUUI.h **************************/ 408