home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !FALCON / NOCREW / MP2_0997.ZIP / mp2_0997 / src / mp2event.c < prev    next >
C/C++ Source or Header  |  1998-11-08  |  16KB  |  750 lines

  1. #include <tos.h>
  2. #include <vdi.h>
  3. #include <aes.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #include "aesextra.h"
  9.  
  10. #include "mp2audio.h"
  11. #include "window.h"
  12. #include "mp2ctrl.h"
  13. #include "mp2info.h"
  14. #include "console.h"
  15. #include "libshoe.h"
  16. #include "version.h"
  17. #include "stream.h"
  18. #include "replay.h"
  19.  
  20. /* Functions in this module */
  21. void main_event_loop(void);
  22. void bg_event_loop(void);
  23. void fg_event_loop(void);
  24. int ev2_loop(WINDFORM *, int, int);
  25. void toggle_object(WINDFORM *,int,int);
  26. int handle_message(int *);
  27. char *do_dragdrop(int *, int);
  28. void update_objects(WINDFORM *,int,int, int *);
  29. int do_formstuff(int);
  30. long calc_time(void);
  31. void update_time(void);
  32. void unquote(char *);
  33.  
  34. /* global variables */
  35. int fgbg,closed_acc=0,looping=0;
  36. int fgexit=0, display_time=0;
  37. char *app_name="MP2AUDIO";
  38.  
  39. /* global variables from mp2file.c */
  40. extern char path[512], filename[512];
  41.  
  42. /* global variables from main.c */
  43. extern int time_slice, count_dir;
  44. extern int replay,quit;
  45. extern long buffer,left;
  46. extern int acc_id,app_id;
  47. extern char *buffer_mem;
  48.  
  49. /* Functions from bifs.c */
  50. extern void call_control_key(char c);
  51.  
  52. /* Functions from mp2info.c */
  53. extern int getmp2info(int);
  54. extern void show_mp2_error(int);
  55.  
  56. /* Functions from console.c */
  57. extern void initialize_console(int w, int h);
  58. extern void prompt_console(int key, int delta);
  59. extern void redraw_console(int *xywh, int row);
  60. extern void print_line(char *text);
  61.  
  62. #define FG 1
  63. #define BG 0
  64.  
  65. #define max(a,b) ((a)>(b)?(a):(b))
  66. #define min(a,b) ((a)<(b)?(a):(b))
  67.  
  68. typedef struct { int x1,y1,x2,y2; } CORDS2;
  69.  
  70. int quit_program()
  71. {
  72.     window_close(WIND_CTRL);
  73.     fgexit = 1;
  74.     return 1;
  75. }
  76.  
  77. void main_event_loop()
  78. {
  79.     fgbg=(_app?FG:BG);
  80.     
  81.     while(!quit) {
  82.         if(closed_acc) {
  83.             evnt_timer(1000,0);
  84. #ifdef DEBUG
  85.             form_alert(1,"[1][ACC reopened][Ok]");
  86. #endif
  87.             window_create(WIND_CTRL);
  88.             closed_acc=0;
  89.         }
  90.         if(fgbg==FG)
  91.             fg_event_loop();
  92.         else if(fgbg==BG)
  93.             bg_event_loop();
  94.     }
  95. }
  96.  
  97. /* No form window is open */
  98. void bg_event_loop()
  99. {
  100.     int x,y,kstate,key,clicks,event,state;
  101.     int pipe[8];
  102.  
  103.  
  104. #ifdef DEBUG
  105.     form_alert(1,"[1][ACC bg][Ok]");
  106. #endif
  107.     do {
  108.         event = evnt_multi( MU_MESAG | MU_TIMER,
  109.                             2, 0x1, 1,
  110.                             0, 0, 0, 0, 0,
  111.                             0, 0, 0, 0, 0,
  112.                             pipe,
  113.                             time_slice, 0,
  114.                             &x, &y, &state, &kstate, &key, &clicks );
  115.  
  116.         if (event & MU_TIMER)
  117.             if (replay) {
  118.                 stream_load(0);
  119.                 update_time();
  120.             }
  121.  
  122.         if (event & MU_MESAG)
  123.             handle_message(pipe); /* no window to handle */
  124.             
  125.     } while ((fgbg==BG) && !closed_acc);
  126. }
  127.  
  128. /* Form window open */
  129. void fg_event_loop()
  130. {
  131.     int x,y,kstate,key,clicks,event,state;
  132.     int pipe[8];
  133.     int tmph;
  134.     
  135.     fgexit = 0;
  136.     
  137.     window_open(WIND_CTRL);
  138.  
  139. #ifdef DEBUG
  140.     form_alert(1,"[1][ACC fg][Ok]");
  141. #endif
  142.     do {
  143.         event = evnt_multi( MU_MESAG | MU_TIMER | MU_BUTTON | MU_KEYBD,
  144.                             1, 0x3, 0x1,
  145.                             0, 0, 0, 0, 0,
  146.                             0, 0, 0, 0, 0,
  147.                             pipe,
  148.                             time_slice, 0,
  149.                             &x, &y, &state, &kstate, &key, &clicks );
  150.  
  151.         if (event & MU_TIMER)
  152.             if (replay) {
  153.                 stream_load(0);
  154.                 update_time();
  155.             }
  156.  
  157.         if(event & MU_KEYBD) {
  158.             if(kstate & 0x04)
  159.                 call_control_key((char)(key&0xff)-1+(kstate&0x3?'A':'a'));
  160.             else {
  161.                 wind_get(0, WF_TOP, &tmph);
  162.                 if(tmph == windforms[WIND_SHOE].whandle)
  163.                     prompt_console(key, 1);
  164.             }
  165. #if 0
  166.             do_formstuff(obj_id);
  167. #endif
  168.         }
  169.     
  170.         if(!fgexit) {
  171.             if (event & MU_MESAG)
  172.                 fgexit=handle_message(pipe);
  173.     
  174.             if (event & MU_BUTTON) {
  175.                 if(wind_find(x,y) == windforms[WIND_CTRL].whandle)
  176.                     if(ev2_loop(&windforms[WIND_CTRL],x,y))
  177.                         event=0;
  178.             }
  179.         }
  180.  
  181.         if(_app)
  182.             quit=fgexit;
  183.         else
  184.             if(fgexit)
  185.                 fgbg=BG;
  186.  
  187.     } while ((replay || fgbg==FG) && !fgexit);
  188. }
  189.  
  190. int ev2_loop(WINDFORM *wind,int mx,int my)
  191. {
  192.     int x,y,kstate,key,clicks,event,state,org_state;
  193.     int obj_id,ev2exit;
  194.     int pipe[8];
  195.     CORDS t;
  196.  
  197.     fgexit = 0;
  198.  
  199.     if((obj_id=objc_find(wind->formtree,CTRL_FIRST,1,mx,my))>=0) {
  200.         if(wind->formtree[obj_id].ob_flags & SELECTABLE) {
  201.             org_state=wind->formtree[obj_id].ob_state & SELECTED;
  202.             toggle_object(wind,obj_id,TOGGLE);
  203.  
  204.             objc_offset(wind->formtree,obj_id,&t.x,&t.y);
  205.             t.w=wind->formtree[obj_id].ob_width;
  206.             t.h=wind->formtree[obj_id].ob_height;
  207.             ev2exit=0;
  208.             do {
  209.                 event = evnt_multi( MU_MESAG | MU_TIMER | MU_BUTTON | MU_M1 | MU_M2,
  210.                                     1, 0x1, 0x0,
  211.                                     0, t.x, t.y, t.w, t.h,
  212.                                     1, t.x, t.y, t.w, t.h,
  213.                                     pipe,
  214.                                     time_slice, 0,
  215.                                     &x, &y, &state, &kstate, &key, &clicks );
  216.  
  217.                 if (event & MU_TIMER)
  218.                     if (replay) {
  219.                         stream_load(0);
  220.                         update_time();
  221.                     }
  222.             
  223.                 if (event & MU_MESAG)
  224.                     fgexit=handle_message(pipe);
  225.  
  226.                 if (event & MU_M1) { /* Enter area */
  227.                     if(org_state==(wind->formtree[obj_id].ob_state & SELECTED))
  228.                         toggle_object(wind,obj_id,TOGGLE);
  229.                 }
  230.                 if (event & MU_M2) { /* Leave area */
  231.                     if(org_state!=(wind->formtree[obj_id].ob_state & SELECTED))
  232.                         toggle_object(wind,obj_id,TOGGLE);
  233.                 }
  234.             
  235.                 if (event & MU_BUTTON) {
  236.                     if(obj_id==objc_find(wind->formtree,
  237.                                                 CTRL_FIRST,1,x,y)) {
  238.                         toggle_object(wind,obj_id,TOGGLE);
  239.  
  240.                         fgexit=do_formstuff(obj_id);
  241.                     } else {
  242.                         objc_change(wind->formtree,obj_id,0,wind->form.x,
  243.                             wind->form.y,wind->form.w,wind->form.h,org_state,0);
  244.                         update_objects(wind,obj_id,1,0);
  245.                     }
  246.                     ev2exit=1;
  247.                 }
  248.  
  249.         
  250.             } while (((replay || fgbg==FG) && !fgexit) && !ev2exit);
  251.             event=0;
  252.             return 1;
  253.         }
  254.     }
  255.     return 0;
  256. }        
  257.  
  258. void toggle_object(WINDFORM *wind,int obj_id,int mode)
  259. {
  260.     if(mode == TOGGLE) {
  261.         if(wind->formtree[obj_id].ob_state & SELECTED)
  262.             mode = SET_NORMAL;
  263.         else
  264.             mode = SET_SELECTED;
  265.     }
  266.  
  267.     /* Take button up */
  268.     if((mode==SET_NORMAL) && 
  269.             (wind->formtree[obj_id].ob_state & SELECTED)) {
  270.         objc_change(wind->formtree,obj_id,0,wind->form.x,
  271.             wind->form.y,wind->form.w,wind->form.h,
  272.             NORMAL,0);
  273.         wind->formtree[wind->formtree[obj_id].ob_head].ob_x--;
  274.         wind->formtree[wind->formtree[obj_id].ob_head].ob_y--;
  275.  
  276.     /* Press button down */
  277.     } else if((mode==SET_SELECTED) &&
  278.                 !(wind->formtree[obj_id].ob_state & SELECTED)) {
  279.         objc_change(wind->formtree,obj_id,0,wind->form.x,
  280.             wind->form.y,wind->form.w,wind->form.h,
  281.             SELECTED,0);
  282.         wind->formtree[wind->formtree[obj_id].ob_head].ob_x++;
  283.         wind->formtree[wind->formtree[obj_id].ob_head].ob_y++;
  284.  
  285.     /* Nothing has changed */
  286.     } else {
  287.         return;
  288.     }
  289.     
  290.     update_objects(wind,obj_id,1,0);
  291. }
  292.  
  293. int handle_message(int pipe[8])
  294. {
  295.     static int first_open=0;
  296.     int wnr;
  297.     static char hookcall[1024];
  298.  
  299. #ifdef DEBUG
  300.     char tmp[128];
  301. #endif
  302.  
  303.     switch (pipe[0]) {
  304.         case AC_OPEN:
  305.             if (pipe[4] == acc_id) {
  306.                 if(first_open) {
  307.                     if(windforms[WIND_CTRL].wind_open)
  308.                         wind_set(windforms[WIND_CTRL].whandle,WF_TOP);
  309.                     else
  310.                         fgbg=FG;
  311.                 } else {
  312.                     window_create(WIND_CTRL);
  313.                     fgbg=FG;
  314.                     first_open=1;
  315.                 }
  316.             }
  317. #ifdef DEBUG
  318.                 form_alert(1,"[1][Got AC_OPEN][Ok]");
  319. #endif
  320.             break;
  321.         case AC_CLOSE:
  322. /*            if (pipe[4] == acc_id) */
  323.  
  324.             {
  325.                 window_close(WIND_CTRL);
  326.                 window_close(WIND_INFO);
  327.                 window_close(WIND_SHOE);
  328.                 
  329.                 stream_save_state();
  330.                 closed_acc=1;
  331.                 return 1;
  332.             }
  333. /*            break; */
  334.             
  335.         case AP_TERM:
  336.             quit=1;
  337.             return 1;
  338. /*            switch(pipe[5]) {
  339.             case AP_RESCHG:
  340.                 printf("Got AP_RESCHG!\n");
  341.                 break;
  342.             case AP_TERM:
  343.                 printf("Got AP_TERM!");
  344.                 break;
  345.             default:
  346.                 printf("Got unknown AP_TERM!");
  347.             }
  348. */
  349. /*            break; */
  350.         case RESCHG_COMPLETED:
  351. /*            printf("Got RESCHG_COMPLETED!"); */
  352.             break;
  353.         
  354.         case WM_REDRAW:
  355.             if((wnr=find_windform(pipe[3]))>=0)
  356.                 update_objects(&windforms[wnr],windforms[wnr].firstobj,
  357.                     windforms[wnr].objdepth,pipe);
  358.             break;
  359.         case WM_MOVED:
  360.             if((wnr=find_windform(pipe[3]))>=0) {
  361.                 window_move(wnr, pipe[4], pipe[5]);
  362.             }
  363.             break;
  364.         case WM_CLOSED:
  365.             if((wnr=find_windform(pipe[3]))>=0) {
  366.                 return window_close(wnr);
  367.             }
  368.             break;
  369.         case WM_TOPPED:
  370.             if((wnr=find_windform(pipe[3]))>=0)
  371.                 wind_set(pipe[3],WF_TOP);
  372.             break;
  373.         case AP_DRAGDROP:
  374.         {
  375.             char *file;
  376.             
  377.             if(find_windform(wind_find(pipe[4],pipe[5])) < 0) {
  378.                 file=do_dragdrop(pipe,DD_OK);
  379.                 if(file != NULL) {
  380.                     strcpy(hookcall, "(mp2-hook-dragumdroppum \"");
  381.                     strcat(hookcall, file);
  382.                     strcat(hookcall, "\")");
  383.                     parse_eval(hookcall);
  384.                 }
  385.             } else {
  386.                 do_dragdrop(pipe,DD_NAK);
  387.             }
  388.         }
  389.             break;
  390.  
  391.         case VA_START:
  392.         {
  393.             char *vamsg; 
  394.             /* int avmsg[8]; */
  395.  
  396.             vamsg=*((char **)&pipe[3]);
  397.  
  398. /* This *should* be sent to the application
  399.     which sent the VA_START msg, but it seems
  400.     to hang Thing doing it. */
  401. /*
  402.             avmsg[0]=AV_STARTED;
  403.             avmsg[1]=app_id;
  404.             avmsg[2]=0;
  405.             avmsg[3]=pipe[3];
  406.             avmsg[4]=pipe[4];
  407.             appl_write(pipe[1],5*2,avmsg);
  408. */
  409.             unquote(vamsg);
  410.             strcpy(hookcall, "(mp2-hook-dragumdroppum \"");
  411.             strcat(hookcall, vamsg);
  412.             strcat(hookcall, "\")");
  413.             parse_eval(hookcall);
  414.         }            
  415.             break;
  416.         default:
  417. #ifdef DEBUG
  418.             sprintf(tmp,"[1][Unimplemented| message: %d][Ok]",pipe[0]);
  419.             form_alert(1,tmp);
  420. #endif
  421.             break;
  422.     }
  423.     return 0;
  424. }
  425.  
  426. char *do_dragdrop(int pipe[8], int mode)
  427. {
  428.     static char misc[1024];
  429.     char dd_name[32],dd_cmsg;
  430.     int i,dd_pipe,headsize,again=1;
  431.     long datasize,err;
  432.     
  433.     strcpy(dd_name,"U:\\PIPE\\DRAGDROP.");
  434.     strcat(dd_name,(char *)&pipe[7]);
  435.     
  436.     if((err=Fopen(dd_name,FO_RW)) >= 0) {
  437.         dd_pipe=(int)err;
  438.  
  439.         dd_cmsg=(char)mode;
  440.         Fwrite(dd_pipe,1,&dd_cmsg);
  441.         if(mode==DD_OK) {
  442.             strcpy(misc,"ARGS");
  443.             for(i=(int)strlen(misc) ; i<32 ; i++)
  444.                 misc[i] = '\0';
  445.             Fwrite(dd_pipe,32,misc);
  446.             
  447.             while(again) {
  448.                 Fread(dd_pipe,2,&headsize);
  449.                 
  450.                 if(headsize > 0) {
  451.                     Fread(dd_pipe,headsize,misc);
  452.                     if(!strncmp(misc,"ARGS",4)) {
  453.                         datasize = *((long *)&misc[4]);
  454.  
  455.                         dd_cmsg=DD_OK;
  456.                         Fwrite(dd_pipe,1,&dd_cmsg);
  457.                         Fread(dd_pipe,datasize,misc);
  458.     
  459.                         misc[datasize] = '\0';
  460.                         unquote(misc);
  461.  
  462.                         return misc;
  463.                     } else {
  464.                         dd_cmsg=DD_EXT;
  465.                         Fwrite(dd_pipe,1,&dd_cmsg);
  466.                         again=1;
  467.                     }
  468.                 } else
  469.                     again=0;
  470.             }
  471.             Fclose(dd_pipe);
  472.             return NULL;
  473.         }
  474.         /* mode==DD_NAK do nothing*/
  475.  
  476.         Fclose(dd_pipe);
  477.         return NULL;
  478.     }
  479.     
  480.     return NULL;
  481. }
  482.  
  483. void update_objects(WINDFORM *wind,int obj_id,int depth, int pipe[8])
  484. {
  485.     CORDS2 r,u,o;
  486.     CORDS t;
  487.  
  488.     if(pipe) {
  489.         o.x1=pipe[4];
  490.         o.y1=pipe[5];
  491.         o.x2=pipe[4]+pipe[6]-1;
  492.         o.y2=pipe[5]+pipe[7]-1;
  493.     }
  494.  
  495.     graf_mouse(M_OFF,0);
  496.     wind_update(BEG_UPDATE);
  497.     wind_get(wind->whandle,WF_FIRSTXYWH,&t.x,&t.y,&t.w,&t.h);
  498.     while(t.w || t.h) {
  499.         if(pipe) {
  500.             r.x1=t.x;                r.y1=t.y;
  501.             r.x2=t.x+t.w-1;        r.y2=t.y+t.h-1;
  502.             u.x1=max(r.x1,o.x1);    u.y1=max(r.y1,o.y1);
  503.             u.x2=min(r.x2,o.x2);    u.y2=min(r.y2,o.y2);
  504.         } else {
  505.             u.x1=t.x;                u.y1=t.y;
  506.             u.x2=t.x+t.w-1;        u.y2=t.y+t.h-1;
  507.         }
  508.         
  509.         if((u.x2>=u.x1) && (u.y2>=u.y1)) {
  510.             if(wind->wind_id == WIND_SHOE) {
  511.                 int xywh[4];
  512.                 xywh[0] = u.x1;
  513.                 xywh[1] = u.y1;
  514.                 xywh[2] = u.x2-u.x1+1;
  515.                 xywh[3] = u.y2-u.y1+1;
  516.                 redraw_console(xywh, -1); /* redraw everything */
  517.             } else
  518.                 objc_draw(wind->formtree,obj_id,depth,
  519.                     u.x1, u.y1, u.x2-u.x1+1, u.y2-u.y1+1);
  520.         }
  521.  
  522.         wind_get(wind->whandle,WF_NEXTXYWH,&t.x,&t.y,&t.w,&t.h);
  523.     }
  524.     wind_update(END_UPDATE);
  525.     graf_mouse(M_ON,0);
  526. }
  527.  
  528. void do_stop()
  529. {
  530.     if(Dsp_Hf1(-1)) {    /* If fast forwarding */
  531.         if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED)
  532.             toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL);
  533.         Dsp_Hf1(0);                
  534.     }
  535.  
  536.     if(replay || replay_pausep()) {
  537.         if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED)
  538.             toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL);
  539.         replay_stop();
  540.         update_time();
  541.     }
  542. }
  543.  
  544. void do_play()
  545. {
  546.     if(replay_pausep() || Dsp_Hf1(-1)) {
  547.         if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED)
  548.             toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL);
  549.         Dsp_Hf1(0);                
  550.  
  551.         if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED)
  552.             toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL);
  553.         replay_continue();
  554.     } else if(!replay && stream_loadedp()) {
  555.         replay_init(mp2info.sample_frequency);
  556.     }
  557. }
  558.  
  559. void do_pause()
  560. {
  561.     if(replay_pausep()) {
  562.         toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL);
  563.         replay_continue();
  564.     } else {
  565.         if(replay) {
  566.             toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_SELECTED);
  567.             replay_pause();
  568.         }
  569.     }
  570. }
  571.  
  572. char *do_selectfile(char *pattern)
  573. {
  574.     int button;
  575.     static char file[1024],tfn[512];
  576.  
  577.     strcpy(tfn,filename);
  578.     strcat(path, pattern);
  579.     fsel_exinput(path, tfn, &button, "Load MPEG");
  580.     strrchr(path, '\\')[1] = '\0';
  581.     if(button == 1 && *tfn) {
  582.         strcpy(file,path);
  583.         strcat(file, tfn);
  584.         return file;
  585.     }
  586.     return NULL;
  587. }
  588.  
  589. void do_loop()
  590. {
  591.     toggle_object(&windforms[WIND_CTRL],CTRL_LOOP,TOGGLE);
  592.     looping=(windforms[WIND_CTRL].formtree[CTRL_LOOP].ob_state & SELECTED);
  593. }
  594.  
  595. void do_info()
  596. {
  597.     /* Open info window */
  598.     if(windforms[WIND_INFO].wind_open)
  599.         wind_set(windforms[WIND_INFO].whandle,WF_TOP);
  600.     else {
  601.         window_create(WIND_INFO);
  602.         window_open(WIND_INFO);
  603.     }
  604. }
  605.  
  606. void do_ff()
  607. {
  608.     if(replay || replay_pausep()) {
  609.         toggle_object(&windforms[WIND_CTRL],CTRL_FF,TOGGLE);
  610.         if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED)
  611.             Dsp_Hf1(1);
  612.         else
  613.             Dsp_Hf1(0);
  614.     }
  615. }
  616.  
  617. void do_shoe()
  618. {
  619.     /* Open Shoe window */
  620.     if(windforms[WIND_SHOE].wind_open)
  621.         wind_set(windforms[WIND_SHOE].whandle,WF_TOP);
  622.     else {
  623.         static int console_online=0;
  624.  
  625.         window_create(WIND_SHOE);
  626.         window_open(WIND_SHOE);
  627.         
  628.         if(!console_online) {
  629.             initialize_console(CONSOLE_W, CONSOLE_H);
  630.             print_line("Online Shoe Macro Console MP2 "VERSION_TEXT".");
  631.             print_line("COPYRIGHT 1999 by NoCrew Laboratories.");
  632.             print_line("Ready.");
  633.             prompt_console(0, 0);
  634.         }                
  635.         console_online = 1;
  636.     }
  637. }
  638.  
  639. int do_formstuff(int obj_id)
  640. {
  641.     switch(obj_id) {
  642.     case CTRL_STOP:
  643.         eval("(mp2-icon-stop)");
  644.         break;
  645.     case CTRL_PLAY:
  646.         eval("(mp2-icon-play)");
  647.         break;
  648.     case CTRL_PAUSE:
  649.         eval("(mp2-icon-pause)");
  650.         break;
  651.     case CTRL_LOAD:
  652.         eval("(mp2-icon-load)");
  653.         break;
  654.     case CTRL_LOOP:
  655.         eval("(mp2-icon-loop)");
  656.         break;
  657.     case CTRL_INFO:
  658.         eval("(mp2-icon-info)");
  659.         break;
  660.     case CTRL_NEXT:
  661.         eval("(mp2-icon-next)");
  662.         break;
  663.     case CTRL_PREV:
  664.         eval("(mp2-icon-previous)");
  665.         break;
  666.     case CTRL_FF:
  667.         eval("(mp2-icon-fast-forward)");
  668.         break;
  669.     case CTRL_SHOE:
  670.         eval("(mp2-icon-console)");
  671.         break;            
  672.             
  673.     default:
  674.         break;
  675.     }
  676.     return 0;
  677. }
  678.  
  679. long calc_time()
  680. {
  681.     return stream_position()/(mp2info.bitrate/8);
  682. }
  683.  
  684. void set_title(char *title)
  685. {
  686.     strcpy(windforms[WIND_CTRL].wind_title, title);
  687.     wind_set(windforms[WIND_CTRL].whandle,WF_NAME,
  688.         windforms[WIND_CTRL].wind_title);
  689. }
  690.  
  691. void update_time()
  692. {
  693.     long time;
  694.     char tmp[64];
  695.  
  696.     if(!display_time)
  697.         return;
  698.     
  699.     if(count_dir)
  700.         time = mp2info.timelength - calc_time();
  701.     else
  702.         time = calc_time();
  703.         
  704.     sprintf(tmp,"%02ld:%02ld",time/60,time%60);
  705.     if(strcmp(tmp,windforms[WIND_CTRL].wind_title)) {
  706.         set_title(tmp);
  707.     }
  708. }
  709.  
  710. void set_subtitle(char *subtitle)
  711. {
  712.     char *text;
  713.     
  714.     text = windforms[WIND_CTRL].formtree[CTRL_FILENAME].ob_spec.tedinfo->te_ptext;
  715.     strncpy(text, subtitle, 16);
  716.     text[16] = '\0';
  717.     update_objects(&windforms[WIND_CTRL],CTRL_FNAME_BOX,0,0);
  718.     update_objects(&windforms[WIND_CTRL],CTRL_FILENAME,0,0);
  719. }
  720.  
  721. /* Convert quoted pathname to unquoted form */
  722. void unquote(char *qname)
  723. {
  724.     char temp[512], *tp;
  725.     int i;
  726.  
  727.     if (qname[0] == '\'') {
  728.         strcpy(temp, qname+1);
  729.         tp = temp;
  730.         for (i = 0; i < 512 ; i++) {
  731.             if (tp[i] == '\'') {
  732.                 if (tp[i+1] == '\'')
  733.                     tp++;
  734.                 else
  735.                     tp[i] = '\0';
  736.             }
  737.  
  738.             qname[i] = tp[i];
  739.  
  740.             if (tp[i] == '\0')
  741.                 break;
  742.         }
  743.     } else {
  744.         if ((tp = strchr(qname, ' ')) != NULL)
  745.             *tp = '\0';
  746.     }
  747. }
  748.  
  749.  
  750.