songinfo.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #include "songinfo.h"
  2. #include "../diskop.h"
  3. void return_from_keyboard_callback(void *ctx)
  4. {
  5. FlizzerTrackerApp *tracker = (FlizzerTrackerApp *)ctx;
  6. if(!tracker->is_loading && !tracker->is_saving)
  7. {
  8. uint8_t string_length = 0;
  9. char *string = NULL;
  10. if (tracker->focus == EDIT_SONGINFO && tracker->mode == PATTERN_VIEW)
  11. {
  12. switch (tracker->selected_param)
  13. {
  14. case SI_SONGNAME:
  15. {
  16. string_length = MUS_SONG_NAME_LEN;
  17. string = (char *)&tracker->song.song_name;
  18. break;
  19. }
  20. case SI_INSTRUMENTNAME:
  21. {
  22. string_length = MUS_INST_NAME_LEN;
  23. string = (char *)&tracker->song.instrument[tracker->current_instrument]->name;
  24. break;
  25. }
  26. }
  27. }
  28. if (tracker->focus == EDIT_INSTRUMENT && tracker->mode == INST_EDITOR_VIEW)
  29. {
  30. switch (tracker->selected_param)
  31. {
  32. case INST_INSTRUMENTNAME:
  33. {
  34. string_length = MUS_INST_NAME_LEN;
  35. string = (char *)&tracker->song.instrument[tracker->current_instrument]->name;
  36. break;
  37. }
  38. }
  39. }
  40. if (string == NULL || string_length == 0)
  41. return;
  42. for (uint8_t i = 0; i < string_length; i++) // I tinyfied the font by deleting lowercase chars, and I don't like the lowercase chars of any 3x5 pixels font
  43. {
  44. string[i] = toupper(string[i]);
  45. }
  46. }
  47. view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_TRACKER);
  48. if(tracker->is_saving)
  49. {
  50. //storage_file_exists(storage, NFC_TEST_DICT_PATH);
  51. tracker->filepath = furi_string_alloc();
  52. furi_string_cat_printf(tracker->filepath, "%s/%s%s", FLIZZER_TRACKER_FOLDER, tracker->filename, SONG_FILE_EXT);
  53. if(storage_file_exists(tracker->storage, furi_string_get_cstr(tracker->filepath)))
  54. {
  55. view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_FILE_OVERWRITE);
  56. return;
  57. }
  58. else
  59. {
  60. FlizzerTrackerEvent event = {.type = EventTypeSaveSong, .input = {0}, .period = 0};
  61. furi_message_queue_put(tracker->event_queue, &event, FuriWaitForever);
  62. //bool song_saved = save_song(tracker, tracker->filepath);
  63. //UNUSED(song_saved);
  64. }
  65. }
  66. }
  67. void edit_songinfo_param(FlizzerTrackerApp *tracker, uint8_t selected_param, int8_t delta)
  68. {
  69. if (!(tracker->current_digit))
  70. {
  71. delta *= 16;
  72. }
  73. switch (selected_param)
  74. {
  75. case SI_PATTERNPOS:
  76. {
  77. uint16_t new_length = tracker->song.pattern_length;
  78. if ((int16_t)new_length + (int16_t)delta > 0 && (int16_t)new_length + (int16_t)delta <= 0x100)
  79. {
  80. new_length += delta;
  81. change_pattern_length(&tracker->song, new_length);
  82. }
  83. break;
  84. }
  85. case SI_SEQUENCEPOS:
  86. {
  87. if ((int16_t)tracker->song.num_sequence_steps + (int16_t)delta > 0 && (int16_t)tracker->song.num_sequence_steps + (int16_t)delta <= 0x100)
  88. {
  89. tracker->song.num_sequence_steps += delta;
  90. }
  91. break;
  92. }
  93. case SI_SONGSPEED:
  94. {
  95. if ((int16_t)tracker->song.speed + (int16_t)delta > 1 && (int16_t)tracker->song.speed + (int16_t)delta <= 0xff)
  96. {
  97. tracker->song.speed += delta;
  98. }
  99. break;
  100. }
  101. case SI_SONGRATE:
  102. {
  103. if ((int16_t)tracker->song.rate + (int16_t)delta > 1 && (int16_t)tracker->song.rate + (int16_t)delta <= 0xff)
  104. {
  105. tracker->song.rate += delta;
  106. }
  107. break;
  108. }
  109. case SI_MASTERVOL:
  110. {
  111. if ((int16_t)tracker->tracker_engine.master_volume + (int16_t)delta > 0 && (int16_t)tracker->tracker_engine.master_volume + (int16_t)delta <= 0xff)
  112. {
  113. tracker->tracker_engine.master_volume += delta;
  114. }
  115. break;
  116. }
  117. case SI_SONGNAME:
  118. {
  119. text_input_set_header_text(tracker->text_input, "Song name:");
  120. text_input_set_result_callback(tracker->text_input, return_from_keyboard_callback, tracker, (char *)&tracker->song.song_name, MUS_SONG_NAME_LEN + 1, false);
  121. view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_KEYBOARD);
  122. break;
  123. }
  124. case SI_CURRENTINSTRUMENT:
  125. {
  126. int16_t inst = tracker->current_instrument;
  127. int8_t inst_delta = delta > 0 ? 1 : -1;
  128. inst += inst_delta;
  129. clamp(inst, 0, 0, tracker->song.num_instruments - 1);
  130. tracker->current_instrument = inst;
  131. break;
  132. }
  133. case SI_INSTRUMENTNAME:
  134. {
  135. text_input_set_header_text(tracker->text_input, "Instrument name:");
  136. text_input_set_result_callback(tracker->text_input, return_from_keyboard_callback, tracker, (char *)&tracker->song.instrument[tracker->current_instrument]->name, MUS_INST_NAME_LEN + 1, false);
  137. view_dispatcher_switch_to_view(tracker->view_dispatcher, VIEW_KEYBOARD);
  138. break;
  139. }
  140. default:
  141. break;
  142. }
  143. }
  144. void songinfo_edit_event(FlizzerTrackerApp *tracker, FlizzerTrackerEvent *event)
  145. {
  146. if (event->input.key == InputKeyOk && event->input.type == InputTypeShort && !tracker->tracker_engine.playing)
  147. {
  148. tracker->editing = !tracker->editing;
  149. }
  150. if (event->input.key == InputKeyRight && event->input.type == InputTypeShort && tracker->editing)
  151. {
  152. switch (tracker->selected_param)
  153. {
  154. default:
  155. {
  156. tracker->current_digit++;
  157. if (tracker->current_digit > 1)
  158. {
  159. tracker->selected_param++;
  160. tracker->current_digit = 0;
  161. if (tracker->selected_param > SI_PARAMS - 1)
  162. {
  163. tracker->selected_param = 0;
  164. }
  165. }
  166. break;
  167. }
  168. case SI_CURRENTINSTRUMENT:
  169. case SI_SONGNAME:
  170. case SI_INSTRUMENTNAME:
  171. {
  172. tracker->selected_param++;
  173. tracker->current_digit = 0;
  174. if (tracker->selected_param > SI_PARAMS - 1)
  175. {
  176. tracker->selected_param = 0;
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. if (event->input.key == InputKeyLeft && event->input.type == InputTypeShort && tracker->editing)
  183. {
  184. switch (tracker->selected_param)
  185. {
  186. default:
  187. {
  188. tracker->current_digit--;
  189. if (tracker->current_digit > 1) // unsigned int overflow
  190. {
  191. tracker->selected_param--;
  192. tracker->current_digit = 1;
  193. if (tracker->selected_param > SI_PARAMS - 1) // unsigned int overflow
  194. {
  195. tracker->selected_param = SI_PARAMS - 1;
  196. }
  197. }
  198. break;
  199. }
  200. case SI_CURRENTINSTRUMENT:
  201. case SI_SONGNAME:
  202. case SI_INSTRUMENTNAME:
  203. {
  204. tracker->selected_param--;
  205. tracker->current_digit = 0;
  206. if (tracker->selected_param > SI_PARAMS - 1) // unsigned int overflow
  207. {
  208. tracker->selected_param = SI_PARAMS - 1;
  209. }
  210. break;
  211. }
  212. }
  213. }
  214. if (event->input.key == InputKeyDown && event->input.type == InputTypeShort)
  215. {
  216. if (tracker->editing)
  217. {
  218. edit_songinfo_param(tracker, tracker->selected_param, -1);
  219. }
  220. }
  221. if (event->input.key == InputKeyUp && event->input.type == InputTypeShort)
  222. {
  223. if (tracker->editing)
  224. {
  225. edit_songinfo_param(tracker, tracker->selected_param, 1);
  226. }
  227. }
  228. }