#include <stdio.h>
#include <conio.h>
#include <allegro.h>
#include "libamp.h"
#include "mmlib.h"

extern FILE *fp;

long double evaluate_ex();
int evaluate_strexpr(char* string);

int PLAYMP3_Handler()
  {
    char *string = (char*)malloc(1024);

    evaluate_strexpr(string);

    install_sound(DIGI_AUTODETECT,MIDI_NONE,NULL);
    install_amp();

    load_amp(string,evaluate_ex());

    free(string);
    return 0;
  }
/** END PLAYMP3_HANDLER **/


int RUNMP3_Handler()
  {
     return run_amp();
  }
/** END RUNMP3_HANDLER **/


int FREEMP3_Handler()
  {
     unload_amp();
     return 0;
  }
/** END FREEMP3_HANDLER **/

int REPLAYMP3_Handler()
  {
     replay_amp();
     return 0;
  }

int BITRATEMP3_Handler()
  {
     return amp_bitrate;
  }

int SAMPRATEMP3_Handler()
  {
     return amp_samprat;
  }

int POLLSIZEMP3_Handler()
  {
     return amp_pollsize;
  }

int POLLMP3_Handler()
  {
     return poll_amp();
  }

int STEREOMP3_Handler()
  {
     return amp_stereo;
  }

void MM_Library() {
// CLS, LOCATE, etc.

  switch (fgetc(fp))
  {
      case IK_PLAYMP3:
         //printf("CLS\n");
         PLAYMP3_Handler();
         break;
      case IK_RUNMP3:
         //printf("CLS\n");
         RUNMP3_Handler();
         break;
      case IK_FREEMP3:
         FREEMP3_Handler();
         break;
      case IK_POLLMP3:
         POLLMP3_Handler();
         break;
      case IK_REPLAYMP3:
         REPLAYMP3_Handler();
         break;
  }

} /** Endof MM_Library **/

