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.

528 lines
18KB

  1. //***********************************************************************************************
  2. //Impromptu Modular: Modules for VCV Rack by Marc Boulé
  3. //***********************************************************************************************
  4. #include "FoundrySequencer.hpp"
  5. namespace rack_plugin_ImpromptuModular {
  6. void Sequencer::construct(bool* _holdTiedNotesPtr, int* _velocityModePtr) {// don't want regaular constructor mechanism
  7. velocityModePtr = _velocityModePtr;
  8. sek[0].construct(0, nullptr, _holdTiedNotesPtr);
  9. for (int trkn = 1; trkn < NUM_TRACKS; trkn++)
  10. sek[trkn].construct(trkn, &sek[0], _holdTiedNotesPtr);
  11. }
  12. void Sequencer::setVelocityVal(int trkn, int intVel, int multiStepsCount, bool multiTracks) {
  13. sek[trkn].setVelocityVal(seqIndexEdit, stepIndexEdit, intVel, multiStepsCount);
  14. if (multiTracks) {
  15. for (int i = 0; i < NUM_TRACKS; i++) {
  16. if (i == trkn) continue;
  17. sek[i].setVelocityVal(seqIndexEdit, stepIndexEdit, intVel, multiStepsCount);
  18. }
  19. }
  20. }
  21. void Sequencer::setLength(int length, bool multiTracks) {
  22. sek[trackIndexEdit].setLength(seqIndexEdit, length);
  23. if (multiTracks) {
  24. for (int i = 0; i < NUM_TRACKS; i++) {
  25. if (i == trackIndexEdit) continue;
  26. sek[i].setLength(seqIndexEdit, length);
  27. }
  28. }
  29. }
  30. void Sequencer::setBegin(bool multiTracks) {
  31. sek[trackIndexEdit].setBegin(phraseIndexEdit);
  32. if (multiTracks) {
  33. for (int i = 0; i < NUM_TRACKS; i++) {
  34. if (i == trackIndexEdit) continue;
  35. sek[i].setBegin(phraseIndexEdit);
  36. }
  37. }
  38. }
  39. void Sequencer::setEnd(bool multiTracks) {
  40. sek[trackIndexEdit].setEnd(phraseIndexEdit);
  41. if (multiTracks) {
  42. for (int i = 0; i < NUM_TRACKS; i++) {
  43. if (i == trackIndexEdit) continue;
  44. sek[i].setEnd(phraseIndexEdit);
  45. }
  46. }
  47. }
  48. bool Sequencer::setGateType(int keyn, int multiSteps, float sampleRate, bool autostepClick, bool multiTracks) {// Third param is for right-click autostep. Returns success
  49. int newMode = keyIndexToGateTypeEx(keyn);
  50. if (newMode == -1)
  51. return false;
  52. sek[trackIndexEdit].setGateType(seqIndexEdit, stepIndexEdit, newMode, multiSteps);
  53. if (multiTracks) {
  54. for (int i = 0; i < NUM_TRACKS; i++) {
  55. if (i == trackIndexEdit) continue;
  56. sek[i].setGateType(seqIndexEdit, stepIndexEdit, newMode, multiSteps);
  57. }
  58. }
  59. if (autostepClick){ // if right-click then move to next step
  60. moveStepIndexEdit(1, false);
  61. editingGateKeyLight = keyn;
  62. editingType = (unsigned long) (gateTime * sampleRate / displayRefreshStepSkips);
  63. if (windowIsModPressed() && multiSteps < 2)
  64. setGateType(keyn, 1, sampleRate, false, multiTracks);
  65. }
  66. return true;
  67. }
  68. void Sequencer::initSlideVal(int multiStepsCount, bool multiTracks) {
  69. sek[trackIndexEdit].setSlideVal(seqIndexEdit, stepIndexEdit, StepAttributes::INIT_SLIDE, multiStepsCount);
  70. if (multiTracks) {
  71. for (int i = 0; i < NUM_TRACKS; i++) {
  72. if (i == trackIndexEdit) continue;
  73. sek[i].setSlideVal(seqIndexEdit, stepIndexEdit, StepAttributes::INIT_SLIDE, multiStepsCount);
  74. }
  75. }
  76. }
  77. void Sequencer::initGatePVal(int multiStepsCount, bool multiTracks) {
  78. sek[trackIndexEdit].setGatePVal(seqIndexEdit, stepIndexEdit, StepAttributes::INIT_PROB, multiStepsCount);
  79. if (multiTracks) {
  80. for (int i = 0; i < NUM_TRACKS; i++) {
  81. if (i == trackIndexEdit) continue;
  82. sek[i].setGatePVal(seqIndexEdit, stepIndexEdit, StepAttributes::INIT_PROB, multiStepsCount);
  83. }
  84. }
  85. }
  86. void Sequencer::initVelocityVal(int multiStepsCount, bool multiTracks) {
  87. sek[trackIndexEdit].setVelocityVal(seqIndexEdit, stepIndexEdit, StepAttributes::INIT_VELOCITY, multiStepsCount);
  88. if (multiTracks) {
  89. for (int i = 0; i < NUM_TRACKS; i++) {
  90. if (i == trackIndexEdit) continue;
  91. sek[i].setVelocityVal(seqIndexEdit, stepIndexEdit, StepAttributes::INIT_VELOCITY, multiStepsCount);
  92. }
  93. }
  94. }
  95. void Sequencer::initPulsesPerStep(bool multiTracks) {
  96. sek[trackIndexEdit].initPulsesPerStep();
  97. if (multiTracks) {
  98. for (int i = 0; i < NUM_TRACKS; i++) {
  99. if (i == trackIndexEdit) continue;
  100. sek[i].initPulsesPerStep();
  101. }
  102. }
  103. }
  104. void Sequencer::initDelay(bool multiTracks) {
  105. sek[trackIndexEdit].initDelay();
  106. if (multiTracks) {
  107. for (int i = 0; i < NUM_TRACKS; i++) {
  108. if (i == trackIndexEdit) continue;
  109. sek[i].initDelay();
  110. }
  111. }
  112. }
  113. void Sequencer::initRunModeSong(bool multiTracks) {
  114. sek[trackIndexEdit].setRunModeSong(SequencerKernel::MODE_FWD);
  115. if (multiTracks) {
  116. for (int i = 0; i < NUM_TRACKS; i++) {
  117. if (i == trackIndexEdit) continue;
  118. sek[i].setRunModeSong(SequencerKernel::MODE_FWD);
  119. }
  120. }
  121. }
  122. void Sequencer::initRunModeSeq(bool multiTracks) {
  123. sek[trackIndexEdit].setRunModeSeq(seqIndexEdit, SequencerKernel::MODE_FWD);
  124. if (multiTracks) {
  125. for (int i = 0; i < NUM_TRACKS; i++) {
  126. if (i == trackIndexEdit) continue;
  127. sek[i].setRunModeSeq(seqIndexEdit, SequencerKernel::MODE_FWD);
  128. }
  129. }
  130. }
  131. void Sequencer::initLength(bool multiTracks) {
  132. sek[trackIndexEdit].setLength(seqIndexEdit, SequencerKernel::MAX_STEPS);
  133. if (multiTracks) {
  134. for (int i = 0; i < NUM_TRACKS; i++) {
  135. if (i == trackIndexEdit) continue;
  136. sek[i].setLength(seqIndexEdit, SequencerKernel::MAX_STEPS);
  137. }
  138. }
  139. }
  140. void Sequencer::initPhraseReps(bool multiTracks) {
  141. sek[trackIndexEdit].setPhraseReps(phraseIndexEdit, 1);
  142. if (multiTracks) {
  143. for (int i = 0; i < NUM_TRACKS; i++) {
  144. if (i == trackIndexEdit) continue;
  145. sek[i].setPhraseReps(phraseIndexEdit, 1);
  146. }
  147. }
  148. }
  149. void Sequencer::initPhraseSeqNum(bool multiTracks) {
  150. sek[trackIndexEdit].setPhraseSeqNum(phraseIndexEdit, 0);
  151. if (multiTracks) {
  152. for (int i = 0; i < NUM_TRACKS; i++) {
  153. if (i == trackIndexEdit) continue;
  154. sek[i].setPhraseSeqNum(phraseIndexEdit, 0);
  155. }
  156. }
  157. }
  158. void Sequencer::copySequence(int countCP) {
  159. int startCP = stepIndexEdit;
  160. sek[trackIndexEdit].copySequence(&seqCPbuf, seqIndexEdit, startCP, countCP);
  161. }
  162. void Sequencer::pasteSequence(bool multiTracks) {
  163. int startCP = stepIndexEdit;
  164. sek[trackIndexEdit].pasteSequence(&seqCPbuf, seqIndexEdit, startCP);
  165. if (multiTracks) {
  166. for (int i = 0; i < NUM_TRACKS; i++) {
  167. if (i == trackIndexEdit) continue;
  168. sek[i].pasteSequence(&seqCPbuf, seqIndexEdit, startCP);
  169. }
  170. }
  171. }
  172. void Sequencer::copySong(int startCP, int countCP) {
  173. sek[trackIndexEdit].copySong(&songCPbuf, startCP, countCP);
  174. }
  175. void Sequencer::pasteSong(bool multiTracks) {
  176. sek[trackIndexEdit].pasteSong(&songCPbuf, phraseIndexEdit);
  177. if (multiTracks) {
  178. for (int i = 0; i < NUM_TRACKS; i++) {
  179. if (i == trackIndexEdit) continue;
  180. sek[i].pasteSong(&songCPbuf, phraseIndexEdit);
  181. }
  182. }
  183. }
  184. void Sequencer::writeCV(int trkn, float cvVal, int multiStepsCount, float sampleRate, bool multiTracks) {
  185. sek[trkn].writeCV(seqIndexEdit, stepIndexEdit, cvVal, multiStepsCount);
  186. editingGateCV[trkn] = cvVal;
  187. editingGateCV2[trkn] = sek[trkn].getVelocityVal(seqIndexEdit, stepIndexEdit);
  188. editingGate[trkn] = (unsigned long) (gateTime * sampleRate / displayRefreshStepSkips);
  189. if (multiTracks) {
  190. for (int i = 0; i < NUM_TRACKS; i++) {
  191. if (i == trkn) continue;
  192. sek[i].writeCV(seqIndexEdit, stepIndexEdit, cvVal, multiStepsCount);
  193. }
  194. }
  195. }
  196. void Sequencer::autostep(bool autoseq, bool autostepLen) {
  197. moveStepIndexEdit(1, autostepLen);
  198. if (stepIndexEdit == 0 && autoseq)
  199. seqIndexEdit = moveIndex(seqIndexEdit, seqIndexEdit + 1, SequencerKernel::MAX_SEQS);
  200. }
  201. bool Sequencer::applyNewOctave(int octn, int multiSteps, float sampleRate, bool multiTracks) { // returns true if tied
  202. if (sek[trackIndexEdit].getTied(seqIndexEdit, stepIndexEdit))
  203. return true;
  204. editingGateCV[trackIndexEdit] = sek[trackIndexEdit].applyNewOctave(seqIndexEdit, stepIndexEdit, octn, multiSteps);
  205. editingGateCV2[trackIndexEdit] = sek[trackIndexEdit].getVelocityVal(seqIndexEdit, stepIndexEdit);
  206. editingGate[trackIndexEdit] = (unsigned long) (gateTime * sampleRate / displayRefreshStepSkips);
  207. editingGateKeyLight = -1;
  208. if (multiTracks) {
  209. for (int i = 0; i < NUM_TRACKS; i++) {
  210. if (i == trackIndexEdit) continue;
  211. sek[i].applyNewOctave(seqIndexEdit, stepIndexEdit, octn, multiSteps);
  212. }
  213. }
  214. return false;
  215. }
  216. bool Sequencer::applyNewKey(int keyn, int multiSteps, float sampleRate, bool autostepClick, bool multiTracks) { // returns true if tied
  217. bool ret = false;
  218. if (sek[trackIndexEdit].getTied(seqIndexEdit, stepIndexEdit)) {
  219. if (autostepClick)
  220. moveStepIndexEdit(1, false);
  221. else
  222. ret = true;
  223. }
  224. else {
  225. editingGateCV[trackIndexEdit] = sek[trackIndexEdit].applyNewKey(seqIndexEdit, stepIndexEdit, keyn, multiSteps);
  226. editingGateCV2[trackIndexEdit] = sek[trackIndexEdit].getVelocityVal(seqIndexEdit, stepIndexEdit);
  227. editingGate[trackIndexEdit] = (unsigned long) (gateTime * sampleRate / displayRefreshStepSkips);
  228. editingGateKeyLight = -1;
  229. if (multiTracks) {
  230. for (int i = 0; i < NUM_TRACKS; i++) {
  231. if (i == trackIndexEdit) continue;
  232. sek[i].applyNewKey(seqIndexEdit, stepIndexEdit, keyn, multiSteps);
  233. }
  234. }
  235. if (autostepClick) {// if right-click then move to next step
  236. moveStepIndexEdit(1, false);
  237. if (windowIsModPressed() && multiSteps < 2) // if ctrl-right-click and SEL is off
  238. writeCV(trackIndexEdit, editingGateCV[trackIndexEdit], 1, sampleRate, multiTracks);// copy CV only to next step
  239. editingGateKeyLight = keyn;
  240. }
  241. }
  242. return ret;
  243. }
  244. void Sequencer::moveStepIndexEditWithEditingGate(int delta, bool writeTrig, float sampleRate) {
  245. moveStepIndexEdit(delta, false);
  246. for (int trkn = 0; trkn < NUM_TRACKS; trkn++) {
  247. if (!sek[trkn].getTied(seqIndexEdit, stepIndexEdit)) {// play if non-tied step
  248. if (!writeTrig) {// in case autostep when simultaneous writeCV and stepCV (keep what was done in Write Input block above)
  249. editingGate[trkn] = (unsigned long) (gateTime * sampleRate / displayRefreshStepSkips);
  250. editingGateCV[trkn] = sek[trkn].getCV(seqIndexEdit, stepIndexEdit);
  251. editingGateCV2[trkn] = sek[trkn].getVelocityVal(seqIndexEdit, stepIndexEdit);
  252. editingGateKeyLight = -1;
  253. }
  254. }
  255. }
  256. }
  257. void Sequencer::modSlideVal(int deltaVelKnob, int mutliStepsCount, bool multiTracks) {
  258. int sVal = sek[trackIndexEdit].modSlideVal(seqIndexEdit, stepIndexEdit, deltaVelKnob, mutliStepsCount);
  259. if (multiTracks) {
  260. for (int i = 0; i < NUM_TRACKS; i++) {
  261. if (i == trackIndexEdit) continue;
  262. sek[i].setSlideVal(seqIndexEdit, stepIndexEdit, sVal, mutliStepsCount);
  263. }
  264. }
  265. }
  266. void Sequencer::modGatePVal(int deltaVelKnob, int mutliStepsCount, bool multiTracks) {
  267. int gpVal = sek[trackIndexEdit].modGatePVal(seqIndexEdit, stepIndexEdit, deltaVelKnob, mutliStepsCount);
  268. if (multiTracks) {
  269. for (int i = 0; i < NUM_TRACKS; i++) {
  270. if (i == trackIndexEdit) continue;
  271. sek[i].setGatePVal(seqIndexEdit, stepIndexEdit, gpVal, mutliStepsCount);
  272. }
  273. }
  274. }
  275. void Sequencer::modVelocityVal(int deltaVelKnob, int mutliStepsCount, bool multiTracks) {
  276. int upperLimit = ((*velocityModePtr) == 0 ? 200 : 127);
  277. int vVal = sek[trackIndexEdit].modVelocityVal(seqIndexEdit, stepIndexEdit, deltaVelKnob, upperLimit, mutliStepsCount);
  278. if (multiTracks) {
  279. for (int i = 0; i < NUM_TRACKS; i++) {
  280. if (i == trackIndexEdit) continue;
  281. sek[i].setVelocityVal(seqIndexEdit, stepIndexEdit, vVal, mutliStepsCount);
  282. }
  283. }
  284. }
  285. void Sequencer::modRunModeSong(int deltaPhrKnob, bool multiTracks) {
  286. int newRunMode = sek[trackIndexEdit].modRunModeSong(deltaPhrKnob);
  287. if (multiTracks) {
  288. for (int i = 0; i < NUM_TRACKS; i++) {
  289. if (i == trackIndexEdit) continue;
  290. sek[i].setRunModeSong(newRunMode);
  291. }
  292. }
  293. }
  294. void Sequencer::modPulsesPerStep(int deltaSeqKnob, bool multiTracks) {
  295. int newPPS = sek[trackIndexEdit].modPulsesPerStep(deltaSeqKnob);
  296. if (multiTracks) {
  297. for (int i = 0; i < NUM_TRACKS; i++) {
  298. if (i == trackIndexEdit) continue;
  299. sek[i].setPulsesPerStep(newPPS);
  300. }
  301. }
  302. }
  303. void Sequencer::modDelay(int deltaSeqKnob, bool multiTracks) {
  304. int newDelay = sek[trackIndexEdit].modDelay(deltaSeqKnob);
  305. if (multiTracks) {
  306. for (int i = 0; i < NUM_TRACKS; i++) {
  307. if (i == trackIndexEdit) continue;
  308. sek[i].setDelay(newDelay);
  309. }
  310. }
  311. }
  312. void Sequencer::modRunModeSeq(int deltaSeqKnob, bool multiTracks) {
  313. int newRunMode = sek[trackIndexEdit].modRunModeSeq(seqIndexEdit, deltaSeqKnob);
  314. if (multiTracks) {
  315. for (int i = 0; i < NUM_TRACKS; i++) {
  316. if (i == trackIndexEdit) continue;
  317. sek[i].setRunModeSeq(seqIndexEdit, newRunMode);
  318. }
  319. }
  320. }
  321. void Sequencer::modLength(int deltaSeqKnob, bool multiTracks) {
  322. int newLength = sek[trackIndexEdit].modLength(seqIndexEdit, deltaSeqKnob);
  323. if (multiTracks) {
  324. for (int i = 0; i < NUM_TRACKS; i++) {
  325. if (i == trackIndexEdit) continue;
  326. sek[i].setLength(seqIndexEdit, newLength);
  327. }
  328. }
  329. }
  330. void Sequencer::modPhraseReps(int deltaSeqKnob, bool multiTracks) {
  331. int newReps = sek[trackIndexEdit].modPhraseReps(phraseIndexEdit, deltaSeqKnob);
  332. if (multiTracks) {
  333. for (int i = 0; i < NUM_TRACKS; i++) {
  334. if (i == trackIndexEdit) continue;
  335. sek[i].setPhraseReps(phraseIndexEdit, newReps);
  336. }
  337. }
  338. }
  339. void Sequencer::modPhraseSeqNum(int deltaSeqKnob, bool multiTracks) {
  340. int newSeqn = sek[trackIndexEdit].modPhraseSeqNum(phraseIndexEdit, deltaSeqKnob);
  341. if (multiTracks) {
  342. for (int i = 0; i < NUM_TRACKS; i++) {
  343. if (i == trackIndexEdit) continue;
  344. sek[i].setPhraseSeqNum(phraseIndexEdit, newSeqn);
  345. }
  346. }
  347. }
  348. void Sequencer::transposeSeq(int deltaSeqKnob, bool multiTracks) {
  349. sek[trackIndexEdit].transposeSeq(seqIndexEdit, deltaSeqKnob);
  350. if (multiTracks) {
  351. for (int i = 0; i < NUM_TRACKS; i++) {
  352. if (i == trackIndexEdit) continue;
  353. sek[i].transposeSeq(seqIndexEdit, deltaSeqKnob);
  354. }
  355. }
  356. }
  357. void Sequencer::unTransposeSeq(bool multiTracks) {
  358. sek[trackIndexEdit].unTransposeSeq(seqIndexEdit);
  359. if (multiTracks) {
  360. for (int i = 0; i < NUM_TRACKS; i++) {
  361. if (i == trackIndexEdit) continue;
  362. sek[i].unTransposeSeq(seqIndexEdit);
  363. }
  364. }
  365. }
  366. void Sequencer::rotateSeq(int deltaSeqKnob, bool multiTracks) {
  367. sek[trackIndexEdit].rotateSeq(seqIndexEdit, deltaSeqKnob);
  368. if (stepIndexEdit < getLength())
  369. moveStepIndexEdit(deltaSeqKnob, true);
  370. if (multiTracks) {
  371. for (int i = 0; i < NUM_TRACKS; i++) {
  372. if (i == trackIndexEdit) continue;
  373. sek[i].rotateSeq(seqIndexEdit, deltaSeqKnob);
  374. }
  375. }
  376. }
  377. void Sequencer::unRotateSeq(bool multiTracks) {
  378. sek[trackIndexEdit].unRotateSeq(seqIndexEdit);
  379. if (multiTracks) {
  380. for (int i = 0; i < NUM_TRACKS; i++) {
  381. if (i == trackIndexEdit) continue;
  382. sek[i].unRotateSeq(seqIndexEdit);
  383. }
  384. }
  385. }
  386. void Sequencer::toggleGate(int multiSteps, bool multiTracks) {
  387. bool newGate = sek[trackIndexEdit].toggleGate(seqIndexEdit, stepIndexEdit, multiSteps);
  388. if (multiTracks) {
  389. for (int i = 0; i < NUM_TRACKS; i++) {
  390. if (i == trackIndexEdit) continue;
  391. sek[i].setGate(seqIndexEdit, stepIndexEdit, newGate, multiSteps);
  392. }
  393. }
  394. }
  395. bool Sequencer::toggleGateP(int multiSteps, bool multiTracks) { // returns true if tied
  396. if (sek[trackIndexEdit].getTied(seqIndexEdit,stepIndexEdit))
  397. return true;
  398. bool newGateP = sek[trackIndexEdit].toggleGateP(seqIndexEdit, stepIndexEdit, multiSteps);
  399. if (multiTracks) {
  400. for (int i = 0; i < NUM_TRACKS; i++) {
  401. if (i == trackIndexEdit) continue;
  402. sek[i].setGateP(seqIndexEdit, stepIndexEdit, newGateP, multiSteps);
  403. }
  404. }
  405. return false;
  406. }
  407. bool Sequencer::toggleSlide(int multiSteps, bool multiTracks) { // returns true if tied
  408. if (sek[trackIndexEdit].getTied(seqIndexEdit,stepIndexEdit))
  409. return true;
  410. bool newSlide = sek[trackIndexEdit].toggleSlide(seqIndexEdit, stepIndexEdit, multiSteps);
  411. if (multiTracks) {
  412. for (int i = 0; i < NUM_TRACKS; i++) {
  413. if (i == trackIndexEdit) continue;
  414. sek[i].setSlide(seqIndexEdit, stepIndexEdit, newSlide, multiSteps);
  415. }
  416. }
  417. return false;
  418. }
  419. void Sequencer::toggleTied(int multiSteps, bool multiTracks) {
  420. bool newTied = sek[trackIndexEdit].toggleTied(seqIndexEdit, stepIndexEdit, multiSteps);// will clear other attribs if new state is on
  421. if (multiTracks) {
  422. for (int i = 0; i < NUM_TRACKS; i++) {
  423. if (i == trackIndexEdit) continue;
  424. sek[i].setTied(seqIndexEdit, stepIndexEdit, newTied, multiSteps);
  425. }
  426. }
  427. }
  428. void Sequencer::toJson(json_t *rootJ) {
  429. // stepIndexEdit
  430. json_object_set_new(rootJ, "stepIndexEdit", json_integer(stepIndexEdit));
  431. // seqIndexEdit
  432. json_object_set_new(rootJ, "seqIndexEdit", json_integer(seqIndexEdit));
  433. // phraseIndexEdit
  434. json_object_set_new(rootJ, "phraseIndexEdit", json_integer(phraseIndexEdit));
  435. // trackIndexEdit
  436. json_object_set_new(rootJ, "trackIndexEdit", json_integer(trackIndexEdit));
  437. for (int trkn = 0; trkn < NUM_TRACKS; trkn++)
  438. sek[trkn].toJson(rootJ);
  439. }
  440. void Sequencer::fromJson(json_t *rootJ) {
  441. // stepIndexEdit
  442. json_t *stepIndexEditJ = json_object_get(rootJ, "stepIndexEdit");
  443. if (stepIndexEditJ)
  444. stepIndexEdit = json_integer_value(stepIndexEditJ);
  445. // phraseIndexEdit
  446. json_t *phraseIndexEditJ = json_object_get(rootJ, "phraseIndexEdit");
  447. if (phraseIndexEditJ)
  448. phraseIndexEdit = json_integer_value(phraseIndexEditJ);
  449. // seqIndexEdit
  450. json_t *seqIndexEditJ = json_object_get(rootJ, "seqIndexEdit");
  451. if (seqIndexEditJ)
  452. seqIndexEdit = json_integer_value(seqIndexEditJ);
  453. // trackIndexEdit
  454. json_t *trackIndexEditJ = json_object_get(rootJ, "trackIndexEdit");
  455. if (trackIndexEditJ)
  456. trackIndexEdit = json_integer_value(trackIndexEditJ);
  457. for (int trkn = 0; trkn < NUM_TRACKS; trkn++)
  458. sek[trkn].fromJson(rootJ);
  459. }
  460. void Sequencer::reset() {
  461. stepIndexEdit = 0;
  462. phraseIndexEdit = 0;
  463. seqIndexEdit = 0;
  464. trackIndexEdit = 0;
  465. seqCPbuf.reset();
  466. songCPbuf.reset();
  467. for (int trkn = 0; trkn < NUM_TRACKS; trkn++) {
  468. editingGate[trkn] = 0ul;
  469. sek[trkn].reset();
  470. }
  471. editingType = 0ul;
  472. }
  473. void Sequencer::clockStep(int trkn) {
  474. bool phraseChange = sek[trkn].clockStep();
  475. if (trkn == 0 && phraseChange) {
  476. for (int tkbcd = 1; tkbcd < NUM_TRACKS; tkbcd++) {// check for song run mode slaving
  477. if (sek[tkbcd].getRunModeSong() == SequencerKernel::MODE_TKA) {
  478. sek[tkbcd].setPhraseIndexRun(sek[0].getPhraseIndexRun());
  479. // The code below is to make it such that stepIndexRun should re-init upon phraseChange
  480. // example for phrase jump does not reset stepIndexRun in B
  481. //A (FWD): 1 = 1x10, 2 = 1x10
  482. //B (TKA): 1 = 1x20, 2 = 1x20
  483. // next line will not work, it will result in a double move of stepIndexRun since clock will move it also
  484. //sek[tkbcd].moveStepIndexRun(true);
  485. // this next mechanism works, the chain of events will make moveStepIndexRun(true) happen automatically and no double move will occur
  486. sek[tkbcd].setMoveStepIndexRunIgnore();//
  487. }
  488. }
  489. }
  490. }
  491. } // namespace rack_plugin_ImpromptuModular