home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / inventorTemplates1.1.2 / AudioNode.c++ next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.1 KB  |  227 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include <Inventor/SoDB.h>
  19. #include "AudioNode.h"
  20.  
  21. SO_SUBNODE_ID_VARS(AudioNode);
  22. SO_SUBNODE_FIELD_VARS(AudioNode);
  23. SO_SUBNODE_ID_METHODS(AudioNode);
  24. SO_SUBNODE_FIELD_METHODS(AudioNode);
  25. SO_SF_ENUM_VARS(AudioNode, 2);
  26.  
  27.  
  28. void
  29. AudioNode::initClass() {
  30.     SO_SUBNODE_INIT_ID(AudioNode, "AudioNode", SoNode);
  31. }
  32.  
  33. AudioNode::AudioNode() {
  34.     SO_SUBNODE_BEGIN_PROTOTYPE(AudioNode);
  35.     SO_SUBNODE_INIT_FIELDS(AudioNode);
  36.     SO_SUBNODE_ADD_FIELD(filename,  (""));
  37.     SO_SUBNODE_ADD_FIELD(timeLength, (0.0));
  38.     SO_SUBNODE_ADD_FIELD(inTime, (0.0));
  39.     SO_SUBNODE_ADD_FIELD(outTime, (0.0));
  40.     SO_SUBNODE_ADD_FIELD(maxOutputLevel, (1.0));
  41.     SO_SUBNODE_ADD_FIELD(rude, (NOPE));
  42.     SO_SUBNODE_ADD_FIELD(loop, (NOPE));
  43.     SO_SUBNODE_ADD_FIELD(sproc, (YUP));
  44.     SO_SF_ENUM_SET(AudioNode, 0, YUP, "YUP");
  45.     SO_SF_ENUM_SET(AudioNode, 1, NOPE, "NOPE");
  46.     SO_SUBNODE_END_PROTOTYPE();
  47.     SO_SUBNODE_INIT_FROM_FIELD_DATA();
  48.     SO_SF_ENUM_SET_ENUMS(AudioNode, loop, 2);
  49.     SO_SF_ENUM_SET_ENUMS(AudioNode, rude, 2);
  50.     SO_SF_ENUM_SET_ENUMS(AudioNode, sproc, 2);
  51.  
  52.     // set old versions of fields for datacb
  53.     oldtimeLength = timeLength.getValue();
  54.     oldinTime = inTime.getValue();
  55.     oldoutTime = outTime.getValue();
  56.     oldmaxOutputLevel = maxOutputLevel.getValue();
  57.     OldFilename = filename.getValue();
  58.     fnamechange = tlchange = itchange = otchange = molchange = 0;
  59.  
  60.     // set the DATA sensor
  61.     dsensor = new SoDataSensor(AudioNode::DataCB, this);
  62.     dsensor->attach(this);
  63.     dsensor->setDelay(FALSE);
  64.     dsensor->schedule();
  65.  
  66.     pc = NULL;
  67. }
  68.  
  69. AudioNode::~AudioNode() {
  70. #ifdef DEBUG
  71.     fprintf(stderr, "~AudioNode\n");
  72. #endif
  73.   dsensor->unschedule();
  74. }    
  75.  
  76. void
  77. AudioNode::DataCB(void *objPtr, SoSensor *)
  78. {
  79. #ifdef DEBUG
  80.     fprintf(stderr, "AudioNode::DataCB\n");
  81. #endif
  82.  
  83.     AudioNode *obj = (AudioNode *) objPtr;
  84.  
  85.     if (obj->filename.getValue() != obj->OldFilename) {
  86.     obj->OldFilename = obj->filename.getValue();
  87.     obj->fnamechange = 1;
  88. #ifdef DEBUG
  89.     fprintf(stderr, "filename changed\n");
  90. #endif
  91.     }
  92.     if (obj->timeLength.getValue() != obj->oldtimeLength) {
  93.     obj->oldtimeLength = obj->timeLength.getValue();
  94.     obj->tlchange = 1;
  95. #ifdef DEBUG
  96.     fprintf(stderr, "timelength changed\n");
  97. #endif
  98.     }
  99.     if (obj->inTime.getValue() != obj->oldinTime) {
  100.     obj->oldinTime = obj->inTime.getValue();
  101.     obj->itchange = 1;
  102. #ifdef DEBUG
  103.     fprintf(stderr, "inTime changed\n");
  104. #endif
  105.     }
  106.     if (obj->outTime.getValue() != obj->oldoutTime) {
  107.     obj->oldoutTime = obj->outTime.getValue();
  108.     obj->otchange = 1;
  109. #ifdef DEBUG
  110.     fprintf(stderr, "outTime changed\n");
  111. #endif
  112.     }
  113.     if (obj->maxOutputLevel.getValue() != obj->oldmaxOutputLevel) {
  114.     obj->oldmaxOutputLevel = obj->maxOutputLevel.getValue();
  115.     obj->molchange = 1;
  116. #ifdef DEBUG
  117.     fprintf(stderr, "max output changed\n");
  118. #endif
  119.     }
  120.  
  121. }
  122.  
  123. void AudioNode::play()
  124. {
  125. #ifdef DEBUG
  126.     fprintf(stderr, "play()\n");
  127. #endif
  128.     if (!pc) {
  129.     pc = new PlayClass((char *) (filename.getValue()).getString());
  130.     }
  131.     // add stuff here to set pc fields
  132.     if (fnamechange) {
  133.     pc->setFilename((char *) (filename.getValue()).getString());
  134.     fnamechange = 0;
  135.     }
  136.     if (tlchange) {
  137.     pc->setTime((double) timeLength.getValue());
  138.     tlchange = 0;
  139.     }
  140.     if (itchange) {
  141.     pc->setInTime((double) inTime.getValue());
  142.     itchange = 0;
  143.     }
  144.     if (otchange) {
  145.     pc->setOutTime((double) outTime.getValue());
  146.     otchange = 0;
  147.     }
  148.     if (molchange) {
  149.     pc->setMaxOutputLevel((double) maxOutputLevel.getValue());
  150.     molchange = 0;
  151.     }
  152.  
  153.     if (rude.getValue() == YUP) {
  154.     pc->setRude(TRUE);
  155.     } else {
  156.     pc->setRude(FALSE);
  157.     }
  158.  
  159.     if (loop.getValue() == YUP) {
  160.     pc->setLoop(TRUE);
  161.     } else {
  162.     pc->setLoop(FALSE);
  163.     }
  164.  
  165.     if (sproc.getValue() == YUP) {
  166.     pc->start();
  167.     } else {
  168.     pc->beginPlaying();
  169.     }
  170. }
  171.  
  172. void AudioNode::stop()
  173. {
  174. #ifdef DEBUG
  175.     fprintf(stderr, "stop()\n");
  176. #endif
  177.     if (!pc) return;
  178.  
  179.     pc->stop();
  180. }
  181.  
  182. void AudioNode::fade()
  183. {
  184. #ifdef DEBUG
  185.     fprintf(stderr, "stop()\n");
  186. #endif
  187.     if (!pc) return;
  188.  
  189.     pc->fadeOut();
  190. }
  191.  
  192. void AudioNode::pause()
  193. {
  194. #ifdef DEBUG
  195.     fprintf(stderr, "unpause()\n");
  196. #endif
  197.     if (!pc) return;
  198.  
  199.     pc->pause();
  200. }
  201.  
  202. void AudioNode::unpause()
  203. {
  204. #ifdef DEBUG
  205.     fprintf(stderr, "unpause()\n");
  206. #endif
  207.     if (!pc) return;
  208.  
  209.     pc->unpause();
  210. }
  211.  
  212. int AudioNode::donep()
  213. {
  214.    // add stuff here to really check if done
  215.    return pc->donep();
  216. }
  217.  
  218. void AudioNode::setNoDone(short nd)
  219. {
  220. #ifdef DEBUG
  221.     fprintf(stderr, "setNoDone()\n");
  222. #endif
  223.     if (!pc) return;
  224.  
  225.     pc->setNoDone(nd);
  226. }
  227.