/*
  main.h - main Riscos entry

  created  12/2021
*/

#ifndef main_h
#define main_h


// windows
enum { WIN_INFO,
       WIN_EDT,
       WIN_ED_WAVE1,
       WIN_ED_WAVE2,
       WIN_ED_FILTER,
       WIN_ED_NOISE,
       WIN_ED_GENERAL,
       WIN_SYN_CONTROL,
       WIN_SAVE,
       WIN_CREATE,
       WIN_WAVEFORMS,
       NUM_WINDOWS };

// menus
enum { MENU_ICONBAR,
       MENU_EDITOR,
       MENU_CONTROL,
       MENU_RATE,
       MENU_WAVEFORM,
       NUM_MENUS };

// slider control types
enum {
  // envelopes, wave1, wave2, filter, and noise panes
  SLDR_ENV_DY,
  SLDR_ENV_AR,
  SLDR_ENV_AT,
  SLDR_ENV_AH,
  SLDR_ENV_DR,
  SLDR_ENV_DT,
  SLDR_ENV_SR,
  SLDR_ENV_RR,
  // wave 1 and wave2 panes, additional sliders
  SLDR_GLIDE,
  // filter pane, additional sliders
  SLDR_RESONANCE,
  // noise pane, no additional sliders
  // general controls pane
  SLDR_FM,
  SLDR_DETUNE,
  SLDR_MOD_RATE,
  SLDR_MOD_DEPTH,
  SLDR_GEN_RETRIG,
  SLDR_GEN_GAIN,
  // synth control
  SLDR_VOLUME,
  SLDR_BALANCE,
  SLDR_FINE,
  // waveform amplitude
  SLDR_WED_AMP,
  // activity bar
  SLDR_ACTIVE,

  NUM_SLIDERS };

// Waveform edit icons
#define ICON_WED_AMP_BACK   3 // ) 32 of these pairs
#define ICON_WED_AMP_SLDR   4 // )
#define ICON_WED_NAME      67
#define ICON_WED_WAV_VAL   68
#define ICON_WED_WAV_DEC   69
#define ICON_WED_WAV_INC   70
#define ICON_WED_HARM_VAL  71
#define ICON_WED_HARM_DEC  72
#define ICON_WED_HARM_INC  73
#define ICON_WED_MAG_VAL   74
#define ICON_WED_MAG_DEC   75
#define ICON_WED_MAG_INC   76
#define ICON_WED_PHASE_VAL 77
#define ICON_WED_PHASE_DEC 78
#define ICON_WED_PHASE_INC 79
#define ICON_WED_GAIN_DEC  80
#define ICON_WED_GAIN_INC  81
#define ICON_WED_SHF_LEFT  82
#define ICON_WED_SHF_RIGHT 83
#define ICON_WED_WAVEFORM  84
#define ICON_WED_RELOAD    85
#define ICON_WED_CLEAR     86
#define ICON_WED_SAVE      87
#define ICON_WED_SAVE_NEW  88
#define ICON_WED_INVERT    89
#define ICON_WED_REVERSE   90


// Control window icons
#define ICON_CTRL_STEREO    0
#define ICON_CTRL_SWAP      1
#define ICON_CTRL_GM_VAR    2
#define ICON_ALL_KITS       3
#define ICON_BANK_SEL_DRUM  4
#define ICON_PRG_UPD_BANK   5
#define ICON_CSV_NO_NUMBER  6
#define ICON_PATCH_NO_KITS  7
#define ICON_PATCH_BY_BANK  8
#define ICON_CTRL_BANKS    10
#define ICON_CTRL_KITS     12
#define ICON_CTRL_GLIDE    14
#define ICON_CTRL_POLY     16
#define ICON_CTRL_SLEEP    18
#define ICON_DEF_DRUM_CHAN 21
#define ICON_CUR_DRUM_CHAN 23
#define ICON_SAMPLE_RATE   25
#define ICON_RATE_MENU     26
#define ICON_VOLUME_BACK   28
#define ICON_VOLUME_SLDR   29
#define ICON_BALANCE_BACK  30
#define ICON_BALANCE_SLDR  31
#define ICON_FIN_TUNE_BACK 32
#define ICON_FIN_TUNE_SLDR 33
#define ICON_COR_TUNE_VAL  35
#define ICON_COR_TUNE_DEC  36
#define ICON_COR_TUNE_INC  37
#define ICON_CTRL_RESET    38
#define ICON_RESET_TUNING  39
#define ICON_SAVE_CHOICES  40
#define ICON_ACTIVE_BACK   42
#define ICON_ACTIVE_VAL    43


// Save sound set icons
#define ICON_FILE_SPRITE    0
#define ICON_FILE_NAME      1
#define ICON_FILE_OK        2
#define ICON_SS_DATA        3
#define ICON_BANK_MAP       4
#define ICON_PATCH_LIST     5
#define ICON_INSTR_LIST     6
#define ICON_C_SOURCE       7

// Create Instrument icons
#define ICON_CA_MELODIC     0
#define ICON_CA_PERCUSSION  1
#define ICON_CA_PROG        2
#define ICON_CA_PROG_VAL    3
#define ICON_CA_PROG_DEC    4
#define ICON_CA_PROG_INC    5
#define ICON_CA_BANK        6
#define ICON_CA_BANK_VAL    7
#define ICON_CA_BANK_DEC    8
#define ICON_CA_BANK_INC    9
#define ICON_CA_CREATE     10
#define ICON_CA_COPY       11
#define ICON_CA_MOVE       12

// Editor icons
#define ICON_ED_WAVE1       4
#define ICON_ED_WAVE2       5
#define ICON_ED_FILTER      6
#define ICON_ED_NOISE       7
#define ICON_ED_GENERAL     8
#define ICON_ED_SOUND_SET   9
#define ICON_ED_SSET_DATE  10
#define ICON_ED_INST_NAME  11
#define ICON_ED_BANK_NAME  12
#define ICON_ED_PATCH      14
#define ICON_ED_PATCH_DEC  15
#define ICON_ED_PATCH_INC  16
#define ICON_ED_INST_NUM   18
#define ICON_ED_INST_DEC   19
#define ICON_ED_INST_INC   20
#define ICON_ED_PRG_NAME   21
#define ICON_ED_PRG_VAL    22
#define ICON_ED_BHI_NAME   23
#define ICON_ED_BHI_VAL    24
#define ICON_ED_BLO_NAME   25
#define ICON_ED_BLO_VAL    26
#define ICON_ED_RELOAD     27
#define ICON_ED_CLEAR      28
#define ICON_ED_SAVE       29
#define ICON_ED_SAVE_NEW   30

// Envelope icons (Wave 1/2, Filter, and Noise Panes)
#define ICON_ENV_DY_BACK    3 // Delay
#define ICON_ENV_DY_SLDR    4
#define ICON_ENV_DY_VAL     5
#define ICON_ENV_AR_BACK    7 // Attack Rate
#define ICON_ENV_AR_SLDR    8
#define ICON_ENV_AR_VAL     9
#define ICON_ENV_AT_BACK   11 // Attack Target
#define ICON_ENV_AT_SLDR   12
#define ICON_ENV_AT_VAL    13
#define ICON_ENV_AH_BACK   15 // Attack Hold
#define ICON_ENV_AH_SLDR   16
#define ICON_ENV_AH_VAL    17
#define ICON_ENV_DR_BACK   19 // Decay Rate
#define ICON_ENV_DR_SLDR   20
#define ICON_ENV_DR_VAL    21
#define ICON_ENV_DT_BACK   23 // Decay Target
#define ICON_ENV_DT_SLDR   24
#define ICON_ENV_DT_VAL    25
#define ICON_ENV_SR_BACK   27 // Sustain Rate
#define ICON_ENV_SR_SLDR   28
#define ICON_ENV_SR_VAL    29
#define ICON_ENV_RR_BACK   31 // Release Rate
#define ICON_ENV_RR_SLDR   32
#define ICON_ENV_RR_VAL    33

// Wave 1/2 Pane icons
#define ICON_WAV_NUM_NAME  34 // Wave number and name
#define ICON_WAV_NUM_DEC   35
#define ICON_WAV_NUM_VAL   36
#define ICON_WAV_NUM_INC   37
#define ICON_WAV_IPO_DEC   39 // Initial Pitch Offset
#define ICON_WAV_IPO_VAL   40
#define ICON_WAV_IPO_INC   41
#define ICON_WAV_FPO_DEC   43 // Final Pitch Offset
#define ICON_WAV_FPO_VAL   44
#define ICON_WAV_FPO_INC   45
#define ICON_WAV_GT_BACK   47 // Glide Time
#define ICON_WAV_GT_SLDR   48
#define ICON_WAV_GT_VAL    49
#define ICON_WAV_PM        50 // Pitch Mod
#define ICON_WAV_AUM       51 // Amp Unsigned Mod
#define ICON_WAV_ASM       52 // Amp Signed Mod
#define ICON_WAV_COPY      54 // Copy to other Wave
#define ICON_SWAP_WAVES    55 // Swap Waves
#define ICON_WAV_MASTER    56 // Master envelope

// Filter Pane Icons
#define ICON_FLT_CF_DEC    35 // Cuttoff Frequency
#define ICON_FLT_CF_VAL    36
#define ICON_FLT_CF_INC    37
#define ICON_FLT_LOW_PASS  38 // Low Pass
#define ICON_FLT_BAND_PASS 39 // Band Pass
#define ICON_FLT_HIGH_PASS 40 // High Pass
#define ICON_FLT_RETRIG    41 // Retrigger
#define ICON_FLT_INVERT    42 // Invert Envelope
#define ICON_FLT_RES_BACK  44 // Resonance
#define ICON_FLT_RES_SLDR  45
#define ICON_FLT_RES_VAL   46
#define ICON_FLT_PM        47 // Pitch Mod
#define ICON_FLT_WF        48 // Wave Filter
#define ICON_FLT_PT        49 // Pitch Track
#define ICON_FLT_ET        50 // Envelope Track
#define ICON_FLT_MASTER    51 // Master envelope

// Noise Generator Pane icons
#define ICON_NOISE_AM      34 // Amplitude Modulation
#define ICON_NOISE_RETRIG  35 // Retrigger
#define ICON_NOISE_ET      36 // Envelope Track
#define ICON_NOISE_MASTER  37 // Master envelope

// General Controls Pane icons
#define ICON_COM_PT         2 // Common Wave, Pitch Track
#define ICON_COM_ET         3 // Common Wave, Envelope Track
#define ICON_COM_RETRIG     4 // Common WAve, Retrigger
#define ICON_COM_W1_OUT     5 // Wave 1 Out
#define ICON_COM_W2_OUT     6 // Wave 2 Out
#define ICON_COM_WRM        7 // Wave Ring Mod
#define ICON_COM_FM_BACK    9 // FM Mod Depth
#define ICON_COM_FM_SLDR   10
#define ICON_COM_FM_VAL    11
#define ICON_COM_DT_BACK   13 // Wave 1/2 Detune
#define ICON_COM_DT_SLDR   14
#define ICON_COM_DT_VAL    15
#define ICON_MOD_NUM_NAME  18 // Modulator Wave number and name
#define ICON_MOD_NUM_DEC   19
#define ICON_MOD_NUM_VAL   20
#define ICON_MOD_NUM_INC   21
#define ICON_MOD_RATE_BACK 23 // Modulation rate
#define ICON_MOD_RATE_SLDR 24
#define ICON_MOD_RATE_VAL  25
#define ICON_MOD_DPTH_BACK 27 // Modulation Depth
#define ICON_MOD_DPTH_SLDR 28
#define ICON_MOD_DPTH_VAL  29
#define ICON_GEN_DLE       32 // Defined Length Envelopes
#define ICON_GEN_MONO      33 // Mono Instrument
#define ICON_GEN_ERT_BACK  35 // Envelope Retrigger Time
#define ICON_GEN_ERT_SLDR  36
#define ICON_GEN_ERT_VAL   37
#define ICON_GEN_GAIN_BACK 39 // Instrument Overall Gain
#define ICON_GEN_GAIN_SLDR 40
#define ICON_GEN_GAIN_VAL  41

// slider definitions
struct slider_dfn_s
{
  int window; // currently selected slider window
  int icon;   // currently selected slider icon
  slider_t type[NUM_SLIDERS]; // slider type
};

extern menu_t control_menu;
extern menu_t editor_menu;
#define MAX_SYS_RATES 20 // maximum number of system sample rates supported
extern menu_t rate_menu;
extern menu_t waveform_menu;
extern menu_t test_menu;

// ro.flags bits
#define QUIT          0
#define MESSAGES_OPEN 1
#define TEMPLATES_OK  2
#define DRAG_ACTIVE   3
#define CENTRALISE    4

// global variables
typedef struct ro_glbs_s
{
  int task_handle;
  int handle[NUM_WINDOWS];
  int cur_menu;
  int cur_pane;
  int save_type;
  int rate_start;
  int flags;
  int save_patch; // bits: 23-16 prg, 15-8 lo, 7-0 hi
  int cur_wav;
  char *wave_plot;

  // data returned by MIDISynth_Edit
  ins_t *user;
  int patch_valid; // TRUE or FALSE
  int cur_ins; // patch number
//  wave_table_t *wav;
  int num_wavs;
  harm_t *harm;
  int num_patches;
  int patch; // bits: 23-16 prg, 15-8 lo, 7-0 hi
  char *bank_name;
  char *soundset_name;
  unsigned int soundset_date;
  int inst_num;
  int num_instruments;
  int master_volume;
  int master_balance;
  int master_coarse;
  int master_fine;

  struct caret_s
  {
    int window;
    int icon;
  } caret;

  struct vdu_s
  {
    int width;
    int height;
  } vdu;

  struct slider_dfn_s slider;
} ro_glbs_t;

extern ro_glbs_t ro;


void update_control_window(void);
int trb_to_param(int slider, int n); // display.c

#endif
