home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / mmstereo / mltamp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  9.1 KB  |  213 lines

  1. /******************************************************************************
  2. * .FILE:         mltamp.cpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION:  Multimedia Stereo Sample:             Class Implementation   *
  5. *                                                                             *
  6. * .CLASSES:      Amp                                                          *
  7. *                AmpHandler                                                   *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. #include <ibase.hpp>
  26. #include <ireslib.hpp>
  27. #include "mmstereo.hpp"
  28. #include "mltamp.hpp"
  29.  
  30. /*------------------------------------------------------------------------------
  31. | Amp::Amp                                                                     |
  32. |                                                                              |
  33. |                                                                              |
  34. ------------------------------------------------------------------------------*/
  35. Amp::Amp( IMMAmpMixer*  aAmp1,
  36.           IMMAmpMixer*  aAmp2,
  37.           IMMAmpMixer*  aAmp3,
  38.           unsigned long windowid,
  39.           IWindow*      parent,
  40.           IWindow*      owner)
  41.    : IMultiCellCanvas(windowid,parent,owner),
  42.      name            (AMPNAMEID, this,owner),
  43.      slVolume        (SL_VOLUME_ID,this,this,IRectangle(),
  44.                       ICircularSlider::defaultStyle()
  45.                       | ICircularSlider::proportionalTicks ),
  46.      slBalance       (SL_BALANCE_ID,this,this,IRectangle(),
  47.                       ICircularSlider::defaultStyle()
  48.                       | ICircularSlider::proportionalTicks ),
  49.      slBass          (SL_BASS_ID,this,this,IRectangle(),
  50.                       ICircularSlider::defaultStyle()
  51.                       | ICircularSlider::proportionalTicks ),
  52.      slTreble        (SL_TREBLE_ID,this,this,IRectangle(),
  53.                       ICircularSlider::defaultStyle()
  54.                       | ICircularSlider::proportionalTicks ),
  55.      slPitch         (SL_PITCH_ID,this,this,IRectangle(),
  56.                       ICircularSlider::defaultStyle()
  57.                       | ICircularSlider::proportionalTicks ),
  58.      slGain          (SL_GAIN_ID,this,this,IRectangle(),
  59.                       ICircularSlider::defaultStyle()
  60.                       | ICircularSlider::proportionalTicks ),
  61.      pAmpMixer1(aAmp1),
  62.      pAmpMixer2(aAmp2),
  63.      pAmpMixer3(aAmp3),
  64.      ampHandler()
  65. {
  66.    IResourceLibrary reslib;
  67.  
  68.    //Set up the title
  69.    name.setText(reslib.loadString(TITLE_MIXER));
  70.    name.setForegroundColor     ( IColor(IColor::red)   );
  71.  
  72.    slVolume.setArmRange          (IRange(0,100));
  73.    slVolume.setRotationIncrement (10);
  74.    slVolume.setTickSpacing       (1);
  75.    slVolume.setText              (reslib.loadString(STR_VOLUME));
  76.    addToCell                     (&slVolume,     1, 1, 1, 1);
  77.  
  78.    slBalance.setArmRange         (IRange(0,100));
  79.    slBalance.setRotationIncrement(10);
  80.    slBalance.setTickSpacing      (1);
  81.    slBalance.setText             (reslib.loadString(STR_BALANCE));
  82.    addToCell                     (&slBalance,    2, 1, 1, 1);
  83.  
  84.    slBass.setArmRange            (IRange(0,100));
  85.    slBass.setRotationIncrement   (10);
  86.    slBass.setTickSpacing         (1);
  87.    slBass.setText                (reslib.loadString(STR_BASS));
  88.    addToCell                     (&slBass,       3, 1, 1, 1);
  89.  
  90.    slTreble.setArmRange          (IRange(0,100));
  91.    slTreble.setRotationIncrement (10);
  92.    slTreble.setTickSpacing       (1);
  93.    slTreble.setText              (reslib.loadString(STR_TREBLE));
  94.    addToCell                     (&slTreble,     4, 1, 1, 1);
  95.  
  96.    slPitch.setArmRange           (IRange(0,100));
  97.    slPitch.setRotationIncrement  (10);
  98.    slPitch.setTickSpacing        (1);
  99.    slPitch.setText               (reslib.loadString(STR_PITCH));
  100.    addToCell                     (&slPitch,      5, 1, 1, 1);
  101.  
  102.    slGain.setArmRange            (IRange(0,100));
  103.    slGain.setRotationIncrement   (10);
  104.    slGain.setTickSpacing         (1);
  105.    slGain.setText                (reslib.loadString(STR_GAIN));
  106.    addToCell                     (&slGain,       6, 1, 1, 1);
  107.  
  108.    addToCell                     (&name,         3, 2, 3, 1);
  109.  
  110.    ampHandler.handleEventsFor(this);
  111.    IMMAmpMixer* tempAmp = 0;
  112.    if (pAmpMixer3)
  113.       tempAmp=pAmpMixer3;
  114.    else if (pAmpMixer2)
  115.       tempAmp=pAmpMixer2;
  116.    else if (pAmpMixer1)
  117.       tempAmp=pAmpMixer1;
  118.    if (tempAmp)
  119.    {
  120.       slVolume.setValue (tempAmp->volume ());
  121.       slBalance.setValue(tempAmp->balance());
  122.       slBass.setValue   (tempAmp->bass   ());
  123.       slTreble.setValue (tempAmp->treble ());
  124.       slPitch.setValue  (tempAmp->pitch  ());
  125.       slGain.setValue   (tempAmp->gain   ());
  126.    } /* endif */
  127. }
  128.  
  129. /*------------------------------------------------------------------------------
  130. | AmpHandler::AmpHandler                                                       |
  131. |                                                                              |
  132. |                                                                              |
  133. ------------------------------------------------------------------------------*/
  134. AmpHandler::AmpHandler()
  135.           : AmpHandler::Inherited()
  136. {}
  137.  
  138.  
  139. /*------------------------------------------------------------------------------
  140. | AmpHandler::tracking                                                         |
  141. |                                                                              |
  142. |                                                                              |
  143. ------------------------------------------------------------------------------*/
  144. IBase::Boolean AmpHandler::moving   (IControlEvent& evt)
  145. {
  146.    Boolean result=false;
  147.    Amp* pAmp = (Amp*)(evt.window());
  148.    ICircularSlider* pSld = (ICircularSlider*)(evt.controlWindow());
  149.    short val = pSld->value();
  150.  
  151.    switch (evt.controlId())
  152.    {
  153.     case SL_VOLUME_ID:
  154.          if (pAmp->pAmpMixer1)
  155.            pAmp->pAmpMixer1->setVolume(val);
  156.          if (pAmp->pAmpMixer2)
  157.            pAmp->pAmpMixer2->setVolume(val);
  158.          if (pAmp->pAmpMixer3)
  159.             pAmp->pAmpMixer3->setVolume(val);
  160.          result = true;
  161.          break;
  162.     case SL_BALANCE_ID:
  163.          if (pAmp->pAmpMixer1)
  164.             pAmp->pAmpMixer1->setBalance(val);
  165.          if (pAmp->pAmpMixer2)
  166.             pAmp->pAmpMixer2->setBalance(val);
  167.          if (pAmp->pAmpMixer3)
  168.             pAmp->pAmpMixer3->setBalance(val);
  169.          //0 is full to the left and 100 is full to the right
  170.          result = true;
  171.          break;
  172.     case SL_BASS_ID:
  173.          if (pAmp->pAmpMixer1)
  174.             pAmp->pAmpMixer1->setBass(val);
  175.          if (pAmp->pAmpMixer2)
  176.             pAmp->pAmpMixer2->setBass(val);
  177.          if (pAmp->pAmpMixer3)
  178.             pAmp->pAmpMixer3->setBass(val);
  179.          result = true;
  180.          break;
  181.     case SL_TREBLE_ID:
  182.          if (pAmp->pAmpMixer1)
  183.             pAmp->pAmpMixer1->setTreble(val);
  184.          if (pAmp->pAmpMixer2)
  185.             pAmp->pAmpMixer2->setTreble(val);
  186.          if (pAmp->pAmpMixer3)
  187.             pAmp->pAmpMixer3->setTreble(val);
  188.          result = true;
  189.          break;
  190.     case SL_PITCH_ID:
  191.          if (pAmp->pAmpMixer1)
  192.             pAmp->pAmpMixer1->setPitch(val);
  193.          if (pAmp->pAmpMixer2)
  194.             pAmp->pAmpMixer2->setPitch(val);
  195.          if (pAmp->pAmpMixer3)
  196.             pAmp->pAmpMixer3->setPitch(val);
  197.          result = true;
  198.          break;
  199.     case SL_GAIN_ID:
  200.          if (pAmp->pAmpMixer1)
  201.             pAmp->pAmpMixer1->setGain(val);
  202.          if (pAmp->pAmpMixer2)
  203.             pAmp->pAmpMixer2->setGain(val);
  204.          if (pAmp->pAmpMixer3)
  205.             pAmp->pAmpMixer3->setGain(val);
  206.          result = true;
  207.          break;
  208.    } /* endswitch */
  209.  
  210.    return result;
  211. }
  212.  
  213.