againeditor.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 // Project     : VST SDK
00003 // Version     : 3.0
00004 //
00005 // Category    : Examples
00006 // Filename    : againeditor.cpp
00007 // Created by  : Steinberg, 04/2005
00008 // Modified    : $Date: 2008/01/15 11:29:30 $
00009 // Description : AGain Editor Example for VST 3.0 using VSTGUI 3.5
00010 //-----------------------------------------------------------------------------
00011 // LICENSE
00012 // © 2008, Steinberg Media Technologies GmbH, All Rights Reserved
00013 //-----------------------------------------------------------------------------
00014 // This Software Development Kit may not be distributed in parts or its entirety  
00015 // without prior written agreement by Steinberg Media Technologies GmbH. 
00016 // This SDK must not be used to re-engineer or manipulate any technology used  
00017 // in any Steinberg or Third-party application or software module, 
00018 // unless permitted by law.
00019 // Neither the name of the Steinberg Media Technologies nor the names of its
00020 // contributors may be used to endorse or promote products derived from this 
00021 // software without specific prior written permission.
00022 // 
00023 // THIS SDK IS PROVIDED BY STEINBERG MEDIA TECHNOLOGIES GMBH "AS IS" AND
00024 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00025 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00026 // IN NO EVENT SHALL STEINBERG MEDIA TECHNOLOGIES GMBH BE LIABLE FOR ANY DIRECT, 
00027 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00028 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
00030 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00031 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00032 // OF THE POSSIBILITY OF SUCH DAMAGE.
00033 //-----------------------------------------------------------------------------
00034 
00035 #include "againeditor.h"
00036 #include "againcontroller.h"
00037 #include "againparamids.h"
00038 
00039 #include <stdio.h>
00040 #include <math.h>
00041 
00042 //------------------------------------------------------------------------
00043 enum
00044 {
00045         // UI size
00046         kEditorWidth  = 350,
00047         kEditorHeight = 120
00048 };
00049 
00050 //------------------------------------------------------------------------
00051 // CTextButton - define a simple text button
00052 //------------------------------------------------------------------------
00053 class CTextButton: public CControl
00054 {
00055 public:
00056 //------------------------------------------------------------------------
00057         CTextButton (const CRect& size, CControlListener* listener = 0, long tag = 0, const char* _title = 0)
00058         : CControl (size, listener, tag)
00059         {
00060                 strcpy (title, _title ? _title : "");
00061         }
00062 
00064         virtual void draw (CDrawContext* pContext)
00065         {
00066                 pContext->setFillColor (kGreyCColor);
00067                 pContext->setFrameColor (kBlackCColor);
00068                 pContext->drawRect (size, kDrawFilledAndStroked);
00069                 pContext->setFont (kNormalFont);
00070                 pContext->setFontColor (kBlackCColor);
00071                 pContext->drawString (title, size);
00072         }
00073 
00074         virtual CMouseEventResult onMouseDown (CPoint& where, const long& buttons)
00075         {
00076                 if (listener)
00077                         listener->valueChanged (this);
00078                 return kMouseEventHandled;
00079         }
00080 
00081         CLASS_METHODS (CTextButton, CControl)
00082 //------------------------------------------------------------------------
00083 protected:
00084         char title[256];
00085 };
00086 
00087 
00088 //------------------------------------------------------------------------
00089 // AGainEditorView Implementation
00090 //------------------------------------------------------------------------
00091 AGainEditorView::AGainEditorView (void* controller)
00092 : VSTGUIEditor (controller)
00093 , textEdit (0)
00094 , gainSlider (0)
00095 , gainTextEdit (0)
00096 , vuMeter (0)
00097 , lastVuMeterValue (0.f)
00098 {
00099         setIdleRate (50); // 1000ms/50ms = 20Hz
00100 }
00101 
00102 //------------------------------------------------------------------------
00103 tresult PLUGIN_API AGainEditorView::onSize (ViewRect* newSize)
00104 {
00105         tresult res = EditorView::onSize (newSize);
00106         return res;
00107 }
00108 
00109 //------------------------------------------------------------------------
00110 bool AGainEditorView::open (void* parent)
00111 {
00112         if (frame) // already attached!
00113                 return false;
00114 
00115         // add dependency
00116         if (controller)
00117                 ((AGainController*)controller)->addDependentView (this);
00118 
00119         CRect editorSize (0, 0, kEditorWidth, kEditorHeight);
00120 
00121         frame = new CFrame (editorSize, parent, this);
00122         frame->setBackgroundColor (kGreyCColor);
00123 
00124         //---Test communication between Component and Controller------
00125         CRect size (0, 0, 200, 20);
00126         size.offset (10, 10);
00127         textEdit = new CTextEdit (size, this, 'Text', "Hello World!", 0, k3DOut);
00128         frame->addView (textEdit);
00129 
00130         size (0, 0, 50, 20);
00131         size.offset (220, 10);
00132         frame->addView (new CTextButton (size, this, 'Send', "Send!"));
00133         //-----------------------------------------------------------
00134 
00135         //---Gain--------------------
00136 
00137         //---Gain Label--------
00138         size (0, 0, 30, 18);
00139         size.offset (10, 40);
00140         CTextLabel* label = new CTextLabel (size, "Gain", 0, kShadowText);
00141         frame->addView (label);
00142 
00143         //---Gain slider-------
00144         CBitmap* handle = new CBitmap ("slider_handle.bmp");
00145         CBitmap* background = new CBitmap ("slider_background.bmp");
00146 
00147         handle->setTransparentColor (kWhiteCColor);
00148 
00149         size (0, 0, 130, 18);
00150         size.offset (45, 40);
00151         CPoint offset;
00152         CPoint offsetHandle (0, 2);
00153         gainSlider = new CHorizontalSlider (size, this, 'Gain', offsetHandle, size.getWidth (), handle, background, offset, kLeft); 
00154         frame->addView (gainSlider);
00155         handle->forget ();
00156         background->forget ();
00157 
00158         //---Gain Textedit--------
00159         size (0, 0, 40, 18);
00160         size.offset (50 + gainSlider->getWidth (), 40);
00161         gainTextEdit = new CTextEdit (size, this, 'GaiT', "", 0, k3DIn);
00162         gainTextEdit->setFont (kNormalFontSmall);
00163         frame->addView (gainTextEdit);
00164 
00165 
00166         //---VuMeter--------------------
00167         CBitmap* onBitmap = new CBitmap ("vu_on.bmp");
00168         CBitmap* offBitmap = new CBitmap ("vu_off.bmp");
00169                  
00170         size (0, 0, 12, 105);
00171         size.offset (290, 10);
00172         vuMeter = new CVuMeter (size, onBitmap, offBitmap, 26, kVertical);
00173         frame->addView (vuMeter);
00174         onBitmap->forget ();
00175         offBitmap->forget ();
00176 
00177         // sync UI controls with controller parameter values
00178         AGainController* controller = (AGainController*)getController ();
00179         ParamValue value = controller->getParamNormalized (kGainId);
00180         update (kGainId, value);
00181 
00182         messageTextChanged ();
00183 
00184         return true;
00185 }
00186 
00187 //------------------------------------------------------------------------
00188 void AGainEditorView::messageTextChanged ()
00189 {
00190         AGainController* controller = (AGainController*)getController ();
00191         UString text (controller->getDefaultMessageText (), -1);
00192         char asciiText[128];
00193         text.toAscii (asciiText, 128);
00194         textEdit->setText (asciiText);
00195 }
00196 
00197 //------------------------------------------------------------------------
00198 void PLUGIN_API AGainEditorView::close ()
00199 {
00200         // remove dependency
00201         if (controller)
00202                 ((AGainController*)controller)->removeDependentView (this);
00203 
00204         if (frame)
00205         {
00206                 delete frame;
00207                 frame = 0;
00208         }
00209         
00210         textEdit = 0;
00211         gainSlider = 0;
00212         gainTextEdit = 0;
00213         vuMeter = 0;
00214 }
00215 
00216 //------------------------------------------------------------------------
00217 void AGainEditorView::valueChanged (CControl* pControl)
00218 {
00219         switch (pControl->getTag ())
00220         {
00221                 //------------------
00222                 case 'Send':
00223                 {
00224                         char text[256] = {0};
00225                         textEdit->getText (text);
00226                         controller->sendTextMessage (text);
00227 
00228                         static bool bgToggle = false;
00229                         frame->setBackgroundColor (bgToggle ? kRedCColor : kGreyCColor);
00230                         frame->invalid ();
00231                         bgToggle = !bgToggle;
00232                 }       break;
00233 
00234                 //------------------
00235                 case 'Gain':
00236                 {
00237                         controller->setParamNormalized (kGainId, pControl->getValue ());
00238                         controller->performEdit (kGainId, pControl->getValue ());
00239                 }       break;
00240 
00241                 //------------------
00242                 case 'GaiT':
00243                 {
00244                         char text[128];
00245                         gainTextEdit->getText (text);
00246                         String128 string;
00247                         Steinberg::UString (string, 128).fromAscii (text);
00248                         ParamValue valueNormalized;
00249                         controller->getParamValueByString (kGainId, string, valueNormalized);
00250                         
00251                         gainSlider->setValue ((float)valueNormalized);
00252                         valueChanged (gainSlider);
00253                         gainSlider->invalid ();
00254                 }       break;
00255 
00256                 //------------------
00257                 case 'Text':
00258                 {
00259                         String128 string;
00260                         char text[128];
00261                         textEdit->getText (text);
00262                         UString (string, 128).fromAscii (text);
00263                         AGainController* controller = (AGainController*)getController ();
00264                         controller->setDefaultMessageText (string);
00265                 }       break;
00266         }               
00267 }
00268 
00269 //------------------------------------------------------------------------
00270 void AGainEditorView::controlBeginEdit (CControl* pControl)
00271 {
00272         switch (pControl->getTag ())
00273         {
00274                 //------------------
00275                 case 'Gain':
00276                 {
00277                         controller->beginEdit (kGainId);
00278                 }       break;
00279         }
00280 }
00281 
00282 //------------------------------------------------------------------------
00283 void AGainEditorView::controlEndEdit (CControl* pControl)
00284 {
00285         switch (pControl->getTag ())
00286         {
00287                 //------------------
00288                 case 'Gain':
00289                 {
00290                         controller->endEdit (kGainId);
00291                 }       break;
00292         }
00293 }
00294 
00295 //------------------------------------------------------------------------
00296 void AGainEditorView::update (ParamID tag, ParamValue value)
00297 {
00298         switch (tag)
00299         {
00300                 //------------------
00301                 case kGainId:
00302                         if (gainSlider)
00303                         {
00304                                 gainSlider->setValue ((float)value);
00305                                                                 
00306                                 if (gainTextEdit)
00307                                 {
00308                                         String128 string;
00309                                         controller->getParamStringByValue (kGainId, value, string);
00310                                         char text[128];
00311                                         Steinberg::UString (string, 128).toAscii (text, 128);
00312                                         gainTextEdit->setText (text);
00313                                 }
00314                         }
00315                         break;
00316 
00317                 //------------------
00318                 case kVuPPMId:
00319                         lastVuMeterValue = (float)value;
00320                         break;
00321         }
00322 }
00323 
00324 //------------------------------------------------------------------------
00325 CMessageResult AGainEditorView::notify (CBaseObject* sender, const char* message)
00326 {
00327         if (message == CVSTGUITimer::kMsgTimer)
00328         {
00329                 if (vuMeter)
00330                 {
00331                         vuMeter->setValue (1.f - ((lastVuMeterValue - 1.f) * (lastVuMeterValue - 1.f)));
00332                         lastVuMeterValue = 0.f;
00333                 }
00334         }
00335         return VSTGUIEditor::notify (sender, message);
00336 }
Empty

Copyright ©2008 Steinberg Media Technologies. All Rights Reserved.