#ifndef _Channel_H
#define _Channel_H

#include "TimTypes.h"
#include "Controller.h"

#define ch_flags_mute         0x001 // Channel is silenced
#define ch_flags_portamento   0x002 // Portamento effect in row, note in row is target
#define ch_flags_glissando    0x004 // Glissando is active
#define ch_flags_newnote      0x008 // Set in Channel_PreProcess
#define ch_flags_triggernote  0x010 // Set in Channel_TriggerNote (new note or retrig)
#define ch_flags_retrig_curr  0x020 // Set in Ctrl, retrig effect in current row
#define ch_flags_retrig_prev  0x040 // Set in Ctrl, retrig effect in previous row
#define ch_flags_retrig_go    0x080 // Set in Ctrl, retrig count reached
#define ch_flags_zero_volume  0x100 // Set in Effects, tremor silences note
#define ch_flags_reset        0x165 // Values to keep on row change

struct Channel
{
	const Instrument* pinstrument;     // pointer to current instrument or NULL
	const Sample*     psample;         // pointer to current sample or NULL
	Note*       pnote;           // pointer to current note or NULL
	uint32_t    GVolume;         // current volume
	uint32_t    GPanning;        // current panning
	uint32_t    NVolume;         // current note volume
	uint8_t     inst_id;         // id of current instrument
	uint8_t     inst_note;       // id of current instrument note
	uint8_t     smp_id;          // id of current sample
	uint8_t     smp_note;        // id of current sample note
	uint8_t     id;              // id of channel (cf virtual channels Dup. Note Check
	uint8_t     new_inst_id;     // id of next instrument/sample
	uint8_t     new_note_id;     // id of next note
	uint8_t     last_arpeggio;   // last value of arpeggio
	uint32_t    flags;
	uint32_t    frame_count;     // frame count within frame adapted with note delay
	Controller  channel_volume;  // column volume controller (note independant)
	Controller  panning;         // panning controller (note independant?)
	Controller  note_pitch;      // pitch controller
	Controller  note_volume;     // volume controller
	const uint8_t*    peffects;        // pointer to active effects
	const uint8_t*    p_new_effects;   // pointer to decoded effects (cf. note delay)
	uint32_t    delay;           // note delay duration (in frames)
	uint32_t    last_set_offset; // last value of set offset
	uint8_t     last_retrig;     // last value of retrig
	uint8_t     last_retrig_eff; // last value of retrig volume effect
	uint8_t     tremor_ontime;   // last value of tremor ontime
	uint8_t     tremor_offtime;  // last value of tremor offtime
	uint8_t     tremor_pos;      // bit 0-6 pos, bit 7 on/off time
	uint8_t     retrig_pos;      // counter for retrigger effect
	uint8_t     retrig_pos_XM;   // counter for retrigger XM effect
	uint8_t     retrig_pos_S3M;  // counter for retrigger S3M effect
	uint8_t     pitch_mem3;      // XM
	uint8_t     pitch_mem4;      // XM
	uint8_t     pitch_mem5;      // XM
	uint8_t     pitch_mem6;      // XM
	uint8_t     gapper_ontime;   // last value of gapper ontime
	uint8_t     gapper_offtime;  // last value of gapper offtime
	uint8_t     gapper_pos;      // bit 0-6 pos, bit 7 on/off time
	uint8_t     dummy;
	uint32_t    upcall_param;    // DSym/DskT upcall param
};

#endif
