You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

369 lines
7.6KB

  1. // Copyright 2012 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // Settings
  28. #include "braids/settings.h"
  29. #include <cstring>
  30. #include "stmlib/system/storage.h"
  31. #include "stmlib/utils/murmurhash3.h"
  32. namespace braids {
  33. using namespace stmlib;
  34. const SettingsData kInitSettings = {
  35. MACRO_OSC_SHAPE_CSAW,
  36. RESOLUTION_16_BIT,
  37. SAMPLE_RATE_96K,
  38. 0, // AD->timbre
  39. false, // Trig source
  40. 1, // Trig delay
  41. false, // Meta modulation
  42. PITCH_RANGE_EXTERNAL,
  43. 2,
  44. 0, // Quantizer is off
  45. false,
  46. false,
  47. false,
  48. 2, // Brightness
  49. 0, // AD attack
  50. 5, // AD decay
  51. 0, // AD->FM
  52. 0, // AD->COLOR
  53. 0, // AD->VCA
  54. 0, // Quantizer root
  55. 50,
  56. 15401,
  57. 2048,
  58. { 0, 0 },
  59. { 32768, 32768 },
  60. "GREETINGS FROM MUTABLE INSTRUMENTS *EDIT ME*",
  61. };
  62. Storage<0x8020000, 4> storage;
  63. void Settings::Init() {
  64. if (!storage.ParsimoniousLoad(&data_, &version_token_)) {
  65. Reset();
  66. }
  67. bool settings_within_range = true;
  68. for (int32_t i = 0; i <= SETTING_LAST_EDITABLE_SETTING; ++i) {
  69. const Setting setting = static_cast<Setting>(i);
  70. const SettingMetadata& setting_metadata = metadata(setting);
  71. uint8_t value = GetValue(setting);
  72. settings_within_range = settings_within_range && \
  73. value >= setting_metadata.min_value && \
  74. value <= setting_metadata.max_value;
  75. }
  76. settings_within_range = settings_within_range && data_.magic_byte == 'M';
  77. for (int i = 0; i < 2; ++i) {
  78. settings_within_range = settings_within_range && \
  79. data_.parameter_cv_scale[i] > 16384;
  80. settings_within_range = settings_within_range && \
  81. data_.parameter_cv_offset[i] < 8000;
  82. settings_within_range = settings_within_range && \
  83. data_.parameter_cv_offset[i] > -8000;
  84. }
  85. if (!settings_within_range) {
  86. Reset();
  87. }
  88. CheckPaques();
  89. }
  90. void Settings::Reset() {
  91. memcpy(&data_, &kInitSettings, sizeof(SettingsData));
  92. data_.magic_byte = 'M';
  93. }
  94. void Settings::Save() {
  95. data_.magic_byte = 'M';
  96. storage.ParsimoniousSave(data_, &version_token_);
  97. CheckPaques();
  98. }
  99. void Settings::CheckPaques() {
  100. paques_ = !strcmp(data_.marquee_text, "49");
  101. }
  102. const char* const boolean_values[] = { "OFF ", "ON " };
  103. const char* const intensity_values[] = {
  104. "OFF ",
  105. " 1",
  106. " 2",
  107. " 3",
  108. "FULL" };
  109. const char* const zero_to_fifteen_values[] = {
  110. " 0",
  111. " 1",
  112. " 2",
  113. " 3",
  114. " 4",
  115. " 5",
  116. " 6",
  117. " 7",
  118. " 8",
  119. " 9",
  120. " 10",
  121. " 11",
  122. " 12",
  123. " 13",
  124. " 14",
  125. " 15"};
  126. const char* const algo_values[] = {
  127. "CSAW",
  128. "^\x88\x8D_",
  129. "\x88\x8A\x8C\x8D",
  130. "FOLD",
  131. "\x8E\x8E\x8E\x8E",
  132. "SUB\x8C",
  133. "SUB\x88",
  134. "SYN\x8C",
  135. "SYN\x88",
  136. "\x88\x88x3",
  137. "\x8C_x3",
  138. "/\\x3",
  139. "SIx3",
  140. "RING",
  141. "\x88\x89\x88\x89",
  142. "\x88\x88\x8E\x8E",
  143. "TOY*",
  144. "ZLPF",
  145. "ZPKF",
  146. "ZBPF",
  147. "ZHPF",
  148. "VOSM",
  149. "VOWL",
  150. "VFOF",
  151. "HARM",
  152. "FM ",
  153. "FBFM",
  154. "WTFM",
  155. "PLUK",
  156. "BOWD",
  157. "BLOW",
  158. "FLUT",
  159. "BELL",
  160. "DRUM",
  161. "KICK",
  162. "CYMB",
  163. "SNAR",
  164. "WTBL",
  165. "WMAP",
  166. "WLIN",
  167. "WTx4",
  168. "NOIS",
  169. "TWNQ",
  170. "CLKN",
  171. "CLOU",
  172. "PRTC",
  173. "QPSK",
  174. // "NAME" // For your algorithm
  175. };
  176. const char* const bits_values[] = {
  177. "2BIT",
  178. "3BIT",
  179. "4BIT",
  180. "6BIT",
  181. "8BIT",
  182. "12B",
  183. "16B " };
  184. const char* const rates_values[] = {
  185. "4KHZ",
  186. "8KHZ",
  187. "16K ",
  188. "24K ",
  189. "32K ",
  190. "48K ",
  191. "96K " };
  192. const char* const quantization_values[] = {
  193. "OFF ",
  194. "SEMI",
  195. "IONI",
  196. "DORI",
  197. "PHRY",
  198. "LYDI",
  199. "MIXO",
  200. "AEOL",
  201. "LOCR",
  202. "BLU+",
  203. "BLU-",
  204. "PEN+",
  205. "PEN-",
  206. "FOLK",
  207. "JAPA",
  208. "GAME",
  209. "GYPS",
  210. "ARAB",
  211. "FLAM",
  212. "WHOL",
  213. "PYTH",
  214. "EB/4",
  215. "E /4",
  216. "EA/4",
  217. "BHAI",
  218. "GUNA",
  219. "MARW",
  220. "SHRI",
  221. "PURV",
  222. "BILA",
  223. "YAMA",
  224. "KAFI",
  225. "BHIM",
  226. "DARB",
  227. "RAGE",
  228. "KHAM",
  229. "MIMA",
  230. "PARA",
  231. "RANG",
  232. "GANG",
  233. "KAME",
  234. "PAKA",
  235. "NATB",
  236. "KAUN",
  237. "BAIR",
  238. "BTOD",
  239. "CHAN",
  240. "KTOD",
  241. "JOGE" };
  242. const char* const trig_source_values[] = { "EXT.", "AUTO" };
  243. const char* const pitch_range_values[] = {
  244. "EXT.",
  245. "FREE",
  246. "XTND",
  247. "440 ",
  248. "LFO "
  249. };
  250. const char* const octave_values[] = { "-2", "-1", "0", "1", "2" };
  251. const char* const trig_delay_values[] = {
  252. "NONE",
  253. "125u",
  254. "250u",
  255. "500u",
  256. "1ms ",
  257. "2ms ",
  258. "4ms "
  259. };
  260. const char* const brightness_values[] = {
  261. "\xff ",
  262. "\xff\xff ",
  263. "\xff\xff\xff\xff",
  264. };
  265. const char* const note_values[] = {
  266. "C",
  267. "Db",
  268. "D",
  269. "Eb",
  270. "E",
  271. "F",
  272. "Gb",
  273. "G",
  274. "Ab",
  275. "A",
  276. "Bb",
  277. "B",
  278. };
  279. /* static */
  280. const SettingMetadata Settings::metadata_[] = {
  281. { 0, MACRO_OSC_SHAPE_LAST - 2, "WAVE", algo_values },
  282. { 0, RESOLUTION_LAST - 1, "BITS", bits_values },
  283. { 0, SAMPLE_RATE_LAST - 1, "RATE", rates_values },
  284. { 0, 15, "\x8F""TIM", zero_to_fifteen_values },
  285. { 0, 1, "TSRC", trig_source_values },
  286. { 0, 6, "TDLY", trig_delay_values },
  287. { 0, 1, "META", boolean_values },
  288. { 0, 3, "RANG", pitch_range_values },
  289. { 0, 4, "OCTV", octave_values },
  290. { 0, 48, "QNTZ", quantization_values },
  291. { 0, 1, "FLAT", boolean_values },
  292. { 0, 4, "DRFT", intensity_values },
  293. { 0, 4, "SIGN", intensity_values },
  294. { 0, 2, "BRIG", brightness_values },
  295. { 0, 15, "\x8F""ATT", zero_to_fifteen_values },
  296. { 0, 15, "\x8F""DEC", zero_to_fifteen_values },
  297. { 0, 15, "\x8F""FM ", zero_to_fifteen_values },
  298. { 0, 15, "\x8F""COL", zero_to_fifteen_values },
  299. { 0, 1, "\x8F""VCA", boolean_values },
  300. { 0, 11, "ROOT", note_values },
  301. { 0, 0, "CAL.", NULL },
  302. { 0, 0, " ", NULL }, // Placeholder for CV tester
  303. { 0, 0, " ", NULL }, // Placeholder for marquee
  304. { 0, 0, "v1.9", NULL }, // Placeholder for version string
  305. };
  306. /* static */
  307. const Setting Settings::settings_order_[] = {
  308. SETTING_OSCILLATOR_SHAPE,
  309. SETTING_META_MODULATION,
  310. SETTING_RESOLUTION,
  311. SETTING_SAMPLE_RATE,
  312. SETTING_TRIG_SOURCE,
  313. SETTING_TRIG_DELAY,
  314. SETTING_AD_ATTACK,
  315. SETTING_AD_DECAY,
  316. SETTING_AD_FM,
  317. SETTING_AD_TIMBRE,
  318. SETTING_AD_COLOR,
  319. SETTING_AD_VCA,
  320. SETTING_PITCH_RANGE,
  321. SETTING_PITCH_OCTAVE,
  322. SETTING_QUANTIZER_SCALE,
  323. SETTING_QUANTIZER_ROOT,
  324. SETTING_VCO_FLATTEN,
  325. SETTING_VCO_DRIFT,
  326. SETTING_SIGNATURE,
  327. SETTING_BRIGHTNESS,
  328. SETTING_CALIBRATION,
  329. SETTING_CV_TESTER,
  330. SETTING_MARQUEE,
  331. SETTING_VERSION,
  332. };
  333. /* extern */
  334. Settings settings;
  335. } // namespace braids