tracker_engine_defs.h 3.0 KB

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