/*
 * mpeg.c:
 *
 * Copyright (c) 2000 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] = "$Id: wave.c,v 1.1 2000/11/23 23:45:36 root Exp $";

/*
 * $Log: wave.c,v $
 * Revision 1.1  2000/11/23 23:45:36  root
 * #
 *
 * Revision 1.5  2000/09/24 01:37:11  root
 * #
 *
 * Revision 1.4  2000/09/24 01:12:47  root
 * #
 *
 * Revision 1.3  2000/09/19 06:09:00  root
 * #
 *
 * Revision 1.2  2000/09/19 05:39:42  root
 * #
 *
 * Revision 1.1  2000/09/19 05:08:18  root
 * #
 *
 */

#include "project.h"


extern void *player;
extern void *msglib;


void
wave_cmdst_message (Byte dunit, Word cmd, Byte * data, Word len)
{

  if ((dunit != waveunit) && (dunit != HIFI_UNIT_ALL))
    return;


  switch (cmd)
    {
    case HIFI_CMD_VOL:
      {
        float voll = 0.01 * (float) data[0];
        float volr = 0.01 * (float) data[1];
        printf ("Vol %d %d\n", data[0], data[1]);
        wavep_setvol (player, voll, volr);
      }
      break;
    case HIFI_CMD_WAVE_RESCAN:
      printf ("Rescan\n");
      rotary_scan ();
      break;
    case HIFI_CMD_WAVE_PLAY:
      printf ("Play\n");
      rotary_play (player, data[0]);
      break;
    case HIFI_CMD_RECORD:
      rotary_record (player);
      break;
    case HIFI_CMD_WAVE_SEEK:
      {
        Word where;
        hifipkt_dword (data, &where);
        wavep_seek (player, (int) where);
      }
      printf ("Seek\n");
      break;
    case HIFI_CMD_STOP:
      printf ("Stop\n");
      wavep_stop (player);
      rotary_scan ();
      break;
    case HIFI_CMD_WAVE_SOURCE:
      mixer_set_source (data[0]);
      break;
    }


}


void
wave_status (void)
{
  Byte *buf = hifi_getbuf ();
  Byte *ptr = buf, *cptr;

  struct wavep_status s;


  s = wavep_status (player);


  ptr = hifipkt_new_brd (ptr, HIFI_CLASS_WAVE, waveunit);


  ptr = hifipkt_est (cptr = ptr, HIFI_ST_WAVE_STATE);



  switch (s.state)
    {
    case WAVE_STOPPED:
      ptr = hifipkt_ebyte (ptr, HIFI_WAVE_State_Stopped);
      break;
    case WAVE_PAUSED:
      ptr = hifipkt_ebyte (ptr, HIFI_WAVE_State_Paused);
      break;
    case WAVE_RECORDING:
      ptr = hifipkt_ebyte (ptr, HIFI_WAVE_State_Recording);
      break;
    case WAVE_PLAYING:
      ptr = hifipkt_ebyte (ptr, HIFI_WAVE_State_Playing);
      break;
    case WAVE_ERROR:
      ptr = hifipkt_ebyte (ptr, HIFI_WAVE_State_Error);
      break;
    default:
      ptr = hifipkt_ebyte (ptr, HIFI_WAVE_State_Unknown);
    }

  ptr = hifipkt_ebyte (ptr, s.position.bmins);
  ptr = hifipkt_ebyte (ptr, s.position.bsecs);

  ptr = hifipkt_eword (ptr, s.length.secs);
  ptr = hifipkt_ebyte (ptr, rotary_derefence (s.filename));

  hifipkt_elen (cptr, HIFI_PTR_DIFF (ptr, cptr));

  {
    int l, r;

    l = (int) (s.voll * 100.0);
    r = (int) (s.volr * 100.0);

    ptr = hifipkt_est (cptr = ptr, HIFI_ST_VOL);
    ptr = hifipkt_ebyte (ptr, l);
    ptr = hifipkt_ebyte (ptr, r);
    hifipkt_elen (cptr, HIFI_PTR_DIFF (ptr, cptr));


    ptr = hifipkt_est (cptr = ptr, HIFI_ST_WAVE_SOURCE);
    mixer_get_source (&l);
    ptr = hifipkt_ebyte (ptr, l);
    hifipkt_elen (cptr, HIFI_PTR_DIFF (ptr, cptr));


  }

  ptr = hifipkt_eeof (ptr);

  hifi_send (msglib, buf, HIFI_PTR_DIFF (ptr, buf));
  hifi_freebuf (buf);

}
