#include "interpreter.hpp"
#include "sound.hpp"
#include "playlist.hpp"

#include "xm.h"
#include "xm/milkypack01.xm.h"
#include "xm/CottageFantasy2.xm.h"
#include "xm/CloudsAhead6.xm.h"

namespace playlist {

  struct state state = {
    .playlist_ix = -1
  };

  const static playlist_item playlist[] = {
    {
      "Shiroiii",
      (int)&_binary_xm_CottageFantasy2_xm_start,
    },
    {
      "Shiroiii",
      (int)&_binary_xm_CloudsAhead6_xm_start,
    },
    {
      "leon du star",
      (int)&_binary_xm_milkypack01_xm_start,
    },
  };

  const int playlist_length = (sizeof (playlist)) / (sizeof (playlist[0]));

  void next()
  {
    state.playlist_ix += 1;
    if (state.playlist_ix >= playlist_length)
      state.playlist_ix = 0;

    printf("next deferred_load playlist_ix %d\n", state.playlist_ix);
    interpreter::deferred_load(playlist[state.playlist_ix].start);
  }

  void prev()
  {
    state.playlist_ix -= 1;
    if (state.playlist_ix < 0)
      state.playlist_ix = playlist_length - 1;

    printf("prev deferred_load playlist_ix %d\n", state.playlist_ix);
    interpreter::deferred_load(playlist[state.playlist_ix].start);
  }
}
