1 /* 2 ZynAddSubFX - a software synthesizer 3 4 Control.h - Defines a variable that can be controled from a frontend 5 6 Copyright (C) 2009 Harald Hvaal 7 Author: Harald Hvaal 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License (version 2 or later) for more details. 18 19 You should have received a copy of the GNU General Public License (version 2) 20 along with this program; if not, write to the Free Software Foundation, 21 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 */ 23 24 #ifndef _CONTROL_H_ 25 #define _CONTROL_H_ 26 27 #include <string> 28 29 class Control 30 { 31 public: 32 /** 33 * The parent is the logical owner of this control. Parent should only 34 * be null for the root node. 35 * The id is a string uniquely identifying this control within the 36 * context of the parent control. No spaces or dots are allowed in this 37 * id. 38 * Children id's are denoted by <parent-id>.<children-id>, so that one 39 * can refer to any control in the hierarchy by separating them with 40 * dots. Example: Main.AddSynth.FrequencyLFO.Amplitude 41 */ 42 Control(Control *parent, string id); 43 44 /** 45 * Will recursively get the XML representation for all the subcontrols. 46 * Used for saving to file and copy-pasting settings 47 */ 48 string getXMLRepresentation(); 49 50 /** 51 * Set the value of this (and possibly subcomponents as well) based on 52 * a xml description. 53 */ 54 void restoreFromXML(string xml); 55 56 /** 57 * Register a controluser. This will cause this user to be notified 58 * whenever the contents of the control changes. 59 */ 60 void registerControlUser(ControlUser *user); 61 62 /** 63 * This should return a string representation of the controls internal 64 * value 65 */ 66 virtual string getStringRepresentation() = 0; 67 }; 68 69 class FloatControl:public Control 70 { 71 public: 72 /** 73 * Set the value of this control. If the ControlUser variable is set, 74 * then this user will not be updated with the new value. This is to 75 * avoid setting a value being set back to the source that set it 76 * (which would be redundant, or possibly causing infinite setValue 77 * loops). 78 * NOTE: this function is thread-safe (using a mutex internally) 79 */ 80 void setValue(float value, ControlUser *user = NULL); 81 82 /** 83 * Reimplemented from Control 84 */ 85 virtual string getStringRepresentation(); 86 87 float value(); 88 }; 89 90 class ControlUser 91 { 92 public: 93 /** 94 * Pure virtual method, to notify the controluser that the value has 95 * been changed internally, and needs to be read again. 96 */ 97 virtual void controlUpdated(Control *control) = 0; 98 }; 99 100 #endif /* _CONTROL_H_ */ 101