tracker_engine_defs.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4. #include "../sound_engine/sound_engine_defs.h"
  5. #define INST_PROG_LEN 16
  6. #define MUS_SONG_NAME_LEN 17
  7. #define MUS_INST_NAME_LEN (MUS_SONG_NAME_LEN - 3)
  8. #define SONG_MAX_CHANNELS NUM_CHANNELS
  9. #define MAX_INSTRUMENTS 31
  10. #define MAX_PATTERN_LENGTH 256
  11. #define MAX_PATTERNS 64
  12. #define MAX_SEQUENCE_LENGTH 256
  13. #define MUS_NOTE_NONE 127
  14. #define MUS_NOTE_RELEASE 126
  15. #define MUS_NOTE_CUT 125
  16. #define MUS_NOTE_INSTRUMENT_NONE 31
  17. #define MUS_NOTE_VOLUME_NONE 31
  18. #define SONG_FILE_SIG "FZT!SONG"
  19. #define TRACKER_ENGINE_VERSION 1
  20. typedef enum
  21. {
  22. TE_ENABLE_VIBRATO = 1,
  23. TE_ENABLE_PWM = 2,
  24. TE_PROG_NO_RESTART = 4,
  25. TE_SET_CUTOFF = 8,
  26. TE_SET_PW = 16,
  27. TE_KEY_SYNC = 32, //sync oscillators on keydown
  28. TE_RETRIGGER_ON_SLIDE = 64, //call trigger instrument function even if slide command is there
  29. } TrackerEngineFlags;
  30. typedef enum
  31. {
  32. TEC_PLAYING = 1,
  33. TEC_PROGRAM_RUNNING = 2,
  34. TEC_DISABLED = 4,
  35. } TrackerEngineChannelFlags;
  36. typedef struct
  37. {
  38. uint8_t a, d, s, r, volume;
  39. } InstrumentAdsr;
  40. typedef struct
  41. {
  42. char name[MUS_INST_NAME_LEN];
  43. uint8_t waveform;
  44. uint16_t flags;
  45. uint16_t sound_engine_flags;
  46. uint8_t slide_speed;
  47. InstrumentAdsr adsr;
  48. uint8_t ring_mod, hard_sync; //0xff = self
  49. uint8_t pw; //store only one byte since we don't have the luxury of virtually unlimited memory!
  50. uint16_t program[INST_PROG_LEN]; //MSB is unite bit (indicates this and next command must be executed at once)
  51. uint8_t program_period;
  52. uint8_t vibrato_speed, vibrato_depth, vibrato_delay;
  53. uint8_t pwm_speed, pwm_depth, pwm_delay;
  54. uint8_t filter_cutoff, filter_resonance, filter_type;
  55. int8_t finetune;
  56. } Instrument;
  57. typedef struct
  58. {
  59. Instrument* instrument;
  60. uint16_t flags;
  61. uint8_t channel_flags;
  62. uint16_t note, target_note, last_note, fixed_note;
  63. int16_t arpeggio_note;
  64. uint8_t volume;
  65. uint8_t program_counter, program_tick, program_loop, program_period;
  66. uint16_t filter_cutoff;
  67. uint8_t filter_resonance, filter_type;
  68. uint8_t vibrato_speed, vibrato_depth, vibrato_delay;
  69. uint8_t pwm_speed, pwm_depth, pwm_delay;
  70. uint16_t vibrato_position, pwm_position;
  71. uint8_t extarp1, extarp2;
  72. uint16_t pw;
  73. uint8_t slide_speed;
  74. } TrackerEngineChannel;
  75. typedef struct
  76. {
  77. uint8_t note; //MSB is used for instrument number MSB
  78. uint8_t inst_vol; //high nibble + MSB from note = instrument, low nibble = 4 volume LSBs
  79. uint16_t command; //MSB used as volume MSB
  80. } TrackerSongPatternStep;
  81. typedef struct
  82. {
  83. TrackerSongPatternStep* step;
  84. } TrackerSongPattern;
  85. typedef struct
  86. {
  87. uint8_t pattern_indices[SONG_MAX_CHANNELS];
  88. } TrackerSongSequenceStep;
  89. typedef struct
  90. {
  91. TrackerSongSequenceStep sequence_step[MAX_SEQUENCE_LENGTH];
  92. } TrackerSongSequence;
  93. typedef struct
  94. {
  95. Instrument* instrument[MAX_INSTRUMENTS];
  96. TrackerSongPattern pattern[MAX_PATTERNS];
  97. TrackerSongSequence sequence;
  98. uint8_t num_patterns, num_sequence_steps, num_instruments;
  99. uint8_t pattern_length;
  100. char song_name[MUS_SONG_NAME_LEN];
  101. uint8_t speed, rate;
  102. uint8_t loop_start, loop_end;
  103. } TrackerSong;
  104. typedef struct
  105. {
  106. TrackerEngineChannel channel[SONG_MAX_CHANNELS];
  107. TrackerSong* song;
  108. SoundEngine* sound_engine;
  109. uint8_t pattern_position, sequence_position, current_tick;
  110. uint16_t absolute_position; //sequence_position * pattern_length + pattern_position
  111. uint8_t pattern_length;
  112. uint8_t speed, rate;
  113. bool playing; //if we reach the end of the song and song does not loop we just stop there
  114. } TrackerEngine;