funcftion state_play(c){
 switch(c){
  case undefined: print("this is state_play"); return;
  case 'stop_pressed': state = state_stopped; return false;
  case 'pause_pressed': state = state_paused; return false;
  default: return state_normal;
 }
}

function state_paused(c){
 switch(c){
  case undefined: print("this is state_paused"); return;
  case 'stop_pressed': state = state_stopped; return false;
  case 'play_pressed': state = state_play; return false;
  default: return state_normal;
 }
}

function state_stopped(c){
 switch(c){
  case undefined: print("this is state_stopped"); return;
  case 'play_pressed': state = state_play; return false;
  default: return state_normal;
 }
}

function state_normal(c){
 switch(c){
  case undefined: print("this is state_normal"); state_stopped();
  case 'ff_pressed': state = state_forward; return false;
  default: return false;
 }
}

function state_forward(c){
 switch(c){
  case undefined: print("this is state_forward"); return;
  case 'ff_released': state = state_play;return false;
  default: return false;
 }
}

function trans(c){
 while(newstate = state(c)){
  state = newstate;
 }
 state();
}

state = state_normal;
trans('play_pressed');
trans('ff_pressed');
trans('ff_released');
trans('stop_pressed');
trans('ff_pressed');
trans('ff_released');