songinfo.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "songinfo.h"
  2. #include <gui/modules/text_input.h>
  3. void edit_songinfo_param(FlizzerTrackerApp *tracker, uint8_t selected_param, int8_t delta)
  4. {
  5. if (!(tracker->current_digit))
  6. {
  7. delta *= 16;
  8. }
  9. switch (selected_param)
  10. {
  11. case SI_PATTERNPOS:
  12. {
  13. if ((int16_t)tracker->song.pattern_length + (int16_t)delta > 1 && (int16_t)tracker->song.pattern_length + (int16_t)delta <= 0xff)
  14. {
  15. tracker->song.pattern_length += delta;
  16. }
  17. break;
  18. }
  19. case SI_SEQUENCEPOS:
  20. {
  21. if ((int16_t)tracker->song.num_sequence_steps + (int16_t)delta > 1 && (int16_t)tracker->song.num_sequence_steps + (int16_t)delta <= 0xff)
  22. {
  23. tracker->song.num_sequence_steps += delta;
  24. }
  25. break;
  26. }
  27. case SI_SONGSPEED:
  28. {
  29. if ((int16_t)tracker->song.speed + (int16_t)delta > 1 && (int16_t)tracker->song.speed + (int16_t)delta <= 0xff)
  30. {
  31. tracker->song.speed += delta;
  32. }
  33. break;
  34. }
  35. case SI_SONGRATE:
  36. {
  37. if ((int16_t)tracker->song.rate + (int16_t)delta > 1 && (int16_t)tracker->song.rate + (int16_t)delta <= 0xff)
  38. {
  39. tracker->song.rate += delta;
  40. }
  41. break;
  42. }
  43. case SI_MASTERVOL:
  44. {
  45. if ((int16_t)tracker->tracker_engine.master_volume + (int16_t)delta > 0 && (int16_t)tracker->tracker_engine.master_volume + (int16_t)delta <= 0xff)
  46. {
  47. tracker->tracker_engine.master_volume += delta;
  48. }
  49. break;
  50. }
  51. case SI_SONGNAME:
  52. {
  53. break;
  54. }
  55. default:
  56. break;
  57. }
  58. }
  59. void songinfo_edit_event(FlizzerTrackerApp *tracker, FlizzerTrackerEvent *event)
  60. {
  61. if (event->input.key == InputKeyOk && event->input.type == InputTypeShort && !tracker->tracker_engine.playing)
  62. {
  63. tracker->editing = !tracker->editing;
  64. }
  65. if (event->input.key == InputKeyRight && event->input.type == InputTypeShort && tracker->editing)
  66. {
  67. tracker->current_digit++;
  68. if (tracker->current_digit > 1)
  69. {
  70. tracker->selected_param++;
  71. tracker->current_digit = 0;
  72. if (tracker->selected_param > SI_PARAMS - 1)
  73. {
  74. tracker->selected_param = 0;
  75. }
  76. }
  77. }
  78. if (event->input.key == InputKeyLeft && event->input.type == InputTypeShort && tracker->editing)
  79. {
  80. tracker->current_digit--;
  81. if (tracker->current_digit > 1) // unsigned int overflow
  82. {
  83. tracker->selected_param--;
  84. tracker->current_digit = 1;
  85. if (tracker->selected_param > SI_PARAMS - 1) // unsigned int overflow
  86. {
  87. tracker->selected_param = SI_PARAMS - 1;
  88. }
  89. }
  90. }
  91. if (event->input.key == InputKeyDown && event->input.type == InputTypeShort)
  92. {
  93. if (tracker->editing)
  94. {
  95. edit_songinfo_param(tracker, tracker->selected_param, -1);
  96. }
  97. }
  98. if (event->input.key == InputKeyUp && event->input.type == InputTypeShort)
  99. {
  100. if (tracker->editing)
  101. {
  102. edit_songinfo_param(tracker, tracker->selected_param, 1);
  103. }
  104. }
  105. }