home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09962.iso / vrml / cp2b2x.exe / DATA.Z / tv.java < prev    next >
Text File  |  1996-06-21  |  7KB  |  247 lines

  1. /*-----------------------------------------------------------------------------
  2.  * Copyright(C) 1995,1996 Sony Corporation
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Sony Corporation;
  6.  * the contents of this file is not to be disclosed to third parties, copied
  7.  * or duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Sony Corporation.
  9.  *
  10.  * File:   tv.java
  11.  * Auther: sugino
  12.  *----------------------------------------------------------------------------*/
  13.  
  14. import vrml.*;
  15.  
  16. public class tv extends Script { 
  17.  
  18.     /* propertys */
  19.     /*************************/
  20.     /* channels/volume array */
  21.     /*************************/
  22.     SFFloat channels[] = new SFFloat[3];     /* channelp number shapes */
  23.     SFFloat volumes[]  = new SFFloat[10];    /* volume indicater shapes */
  24.     SFColor powerBtn;                        /* power button */
  25.     SFFloat chs[]      = new SFFloat[3];     /* monitor faces */
  26.     int MaxVolume ;    /* volume max */
  27.     int MaxChannel;    /* channel max */
  28.     int volume    ;    /* sound volume (0-9) */
  29.     int channel   ;    /* channel no(0-2) */
  30.     boolean powerOn ;  /* true the power is on */
  31.     int ignoreTimer ;
  32.     
  33.     SFBool tglTm = (SFBool)getEventOut("tglTm");
  34.     
  35.     SFTime bgm1Start = (SFTime) getEventOut("bgm1Start");
  36.     SFTime bgm1Stop = (SFTime) getEventOut("bgm1Stop");
  37.     
  38.     SFTime kachiStart = (SFTime) getEventOut("kachiStart");
  39.     SFFloat bgmVol = (SFFloat) getEventOut("bgmVol");
  40.  
  41.     /*************************************************
  42.     * constructor 
  43.     *************************************************/
  44.     public tv() {
  45.  
  46.     MaxVolume =10;  /* volume max */
  47.     MaxChannel=3 ;  /* channel max */
  48.     volume = 8 ;    /* sound volume (0-9) */
  49.     channel = 0;    /* channel no(0-2) */
  50.     powerOn = false;/* true the power is on */
  51.  
  52.     /* ---------------------------------------------
  53.      * initialize
  54.      * ------------------------------------------- */
  55.     /* reference to Channnel shapes */
  56.  
  57.     channels[0] = (SFFloat)getEventOut("ch1Shape");
  58.     channels[1] = (SFFloat)getEventOut("ch2Shape");
  59.     channels[2] = (SFFloat)getEventOut("ch3Shape");
  60.  
  61.     chs[0] = (SFFloat)getEventOut("ch1");
  62.     chs[1] = (SFFloat)getEventOut("ch2");
  63.     chs[2] = (SFFloat)getEventOut("ch3");
  64.  
  65.     /* reference to vol indicater shapes */
  66.     volumes[0] = (SFFloat)getEventOut("vol1Shape");
  67.     volumes[1] = (SFFloat)getEventOut("vol2Shape");
  68.     volumes[2] = (SFFloat)getEventOut("vol3Shape");
  69.     volumes[3] = (SFFloat)getEventOut("vol4Shape");
  70.     volumes[4] = (SFFloat)getEventOut("vol5Shape");
  71.     volumes[5] = (SFFloat)getEventOut("vol6Shape");
  72.     volumes[6] = (SFFloat)getEventOut("vol7Shape");
  73.     volumes[7] = (SFFloat)getEventOut("vol8Shape");
  74.     volumes[8] = (SFFloat)getEventOut("vol9Shape");
  75.     volumes[9] = (SFFloat)getEventOut("vol10Shape");
  76.  
  77.     /* reference to Power buttn shapes */
  78.     powerBtn  = (SFColor)getEventOut("powerShape");
  79.  
  80.     bgmVol.setValue((float)volume*0.1f);
  81.     }
  82.     
  83.     /*************************************************
  84.      * script methods
  85.      *************************************************/
  86.     public void     volDown (ConstSFBool  b, ConstSFTime t){
  87.         if(!powerOn) return ;
  88.     if(b.getValue()){return;}
  89.     /* System.out.println("volDown"); */
  90.     
  91.     volume--;
  92.     setVolume(volume);
  93.     showInfo();
  94.     /* TODO Ä└ì█é╔ë╣é≡âZâbâgé╖éΘ */
  95.     bgmVol.setValue((float)volume*0.1f);
  96.     }
  97.     public void     volUp (ConstSFBool  b, ConstSFTime t){
  98.         if(!powerOn) return ;
  99.     if(b.getValue()){return;}
  100.     /*     System.out.println("volUp"); */
  101.     volume++;
  102.     setVolume(volume);
  103.     showInfo();
  104.     bgmVol.setValue((float)volume*0.1f);
  105.     /* TODO Ä└ì█é╔ë╣é≡âZâbâgé╖éΘ */
  106.     }
  107.     public void     chUp (ConstSFBool  b, ConstSFTime t){
  108.         if(!powerOn) return ;
  109.     if(b.getValue()){return;}
  110.     /* System.out.println("chUp"); */
  111.     channel++;
  112.     setChannel(channel);
  113.     playTv();
  114.     showInfo();
  115.     }
  116.     public void     chDown (ConstSFBool  b, ConstSFTime t){
  117.         if(!powerOn) return ;
  118.     if(b.getValue()){return;}
  119.     /*     System.out.println("chDown"); */
  120.     channel--;
  121.     setChannel(channel);
  122.     playTv();
  123.     showInfo();
  124.     }
  125.     public void     tglPower (ConstSFBool  b, ConstSFTime t){
  126.     
  127.     if(b.getValue()){return;}
  128.     float f[] = new float[3];
  129.     
  130.     f[0]=f[1]=f[2]=0.0f;
  131.     if(powerOn) { 
  132.         /* turn Off power */
  133.         powerOn = false ;
  134.         f[0]=1.0f;
  135.         clearTv();
  136.         clearInfo();
  137.             bgm1Stop.setValue(t.getValue());
  138.     }
  139.     else {
  140.         powerOn = true ;
  141.         f[1]=1.0f;
  142.         playTv();
  143.         showInfo();
  144.             bgm1Start.setValue(t.getValue());
  145.     }
  146.     powerBtn.setValue(f);
  147.  
  148. /*    System.out.println("tglPower" + ff[0] + " " + 
  149.                ff[1] + " " + ff[2] ); */
  150.  
  151.     kachiStart.setValue(t.getValue()+1);
  152.     
  153.     }
  154.     public void turnOffInfo (ConstSFTime time, ConstSFTime t){
  155.  
  156.         if(0<ignoreTimer){
  157.         ignoreTimer--;
  158.             return ;
  159.         }
  160.     tglTm.setValue(false);
  161.         clearInfo();
  162.     clearVolume();
  163.     }
  164.  
  165.     void clearInfo(){
  166.         clearChannel();
  167.     clearVolume();
  168.     }
  169.     /*************************************************
  170.      * showInfo()
  171.      *************************************************/
  172.     void showInfo(){
  173.     setChannel(channel);
  174.     setVolume(volume);
  175.     ignoreTimer = 1;
  176.     tglTm.setValue(true);
  177.     }
  178.  
  179.     /*************************************************
  180.      * Clear TV
  181.      *************************************************/
  182.     void clearTv(){
  183.     for (int i=0;i<MaxChannel;i++){
  184.         chs[i].setValue(1.0f);
  185.     }
  186.     }
  187.     /*************************************************
  188.      * playTv
  189.      *************************************************/
  190.     void playTv(){
  191.     clearTv();
  192.     chs[channel].setValue(0.0f);
  193.     }
  194.     
  195.     /*************************************************
  196.      * Clear Channel shape
  197.      *************************************************/
  198.     void clearChannel(){
  199.     for (int i=0;i<MaxChannel;i++){
  200.         channels[i].setValue(1.0f);
  201.     }
  202.     }
  203.  
  204.     /*************************************************
  205.      * set volume shape
  206.      *************************************************/
  207.     void setChannel(int ch){
  208.     if(ch<0){ch =MaxChannel-1;}
  209.     if(ch>=MaxChannel){ch=0;}
  210.     
  211.     channel = ch ;
  212.     clearChannel();
  213.  
  214.     channels[ch].setValue(0.0f);        
  215.     }
  216.  
  217.     /*************************************************
  218.      * Clear Volume shape
  219.      *************************************************/
  220.     void clearVolume(){
  221.     for(int i=0;i<MaxVolume;i++){
  222.         /* disable volume */
  223.         volumes[i].setValue(1.0f);
  224.     }
  225.     }
  226.  
  227.     /*************************************************
  228.      * set volume shape
  229.      *************************************************/
  230.     void setVolume(int vol){
  231.     if(vol<0){vol =0;}
  232.     if(vol>MaxVolume){vol=MaxVolume;}
  233.     
  234.     volume = vol ;
  235.     clearVolume();
  236.  
  237.     for(int i=0;i<vol;i++){
  238.         volumes[i].setValue(0.0f);        
  239.     }
  240.     }
  241. }
  242.  
  243.  
  244.     
  245.  
  246.  
  247.