home *** CD-ROM | disk | FTP | other *** search
/ Sony Community Place / BROWSER / APP / cpb20prD1b.exe / DATA.Z / tv.java < prev    next >
Encoding:
Java Source  |  1997-05-14  |  7.4 KB  |  280 lines

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