Audio plugin host https://kx.studio/carla
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.

1343 lines
47KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Part.cpp - Part implementation
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include "Part.h"
  18. #include "Microtonal.h"
  19. #include "Util.h"
  20. #include "XMLwrapper.h"
  21. #include "../Effects/EffectMgr.h"
  22. #include "../Params/ADnoteParameters.h"
  23. #include "../Params/SUBnoteParameters.h"
  24. #include "../Params/PADnoteParameters.h"
  25. #include "../Synth/ADnote.h"
  26. #include "../Synth/SUBnote.h"
  27. #include "../Synth/PADnote.h"
  28. #include "../DSP/FFTwrapper.h"
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32. Part::Part(Microtonal *microtonal_, FFTwrapper *fft_, pthread_mutex_t *mutex_)
  33. {
  34. microtonal = microtonal_;
  35. fft = fft_;
  36. mutex = mutex_;
  37. pthread_mutex_init(&load_mutex, NULL);
  38. partoutl = new float [synth->buffersize];
  39. partoutr = new float [synth->buffersize];
  40. for(int n = 0; n < NUM_KIT_ITEMS; ++n) {
  41. kit[n].Pname = new unsigned char [PART_MAX_NAME_LEN];
  42. kit[n].adpars = NULL;
  43. kit[n].subpars = NULL;
  44. kit[n].padpars = NULL;
  45. }
  46. kit[0].adpars = new ADnoteParameters(fft);
  47. kit[0].subpars = new SUBnoteParameters();
  48. kit[0].padpars = new PADnoteParameters(fft, mutex);
  49. //Part's Insertion Effects init
  50. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) {
  51. partefx[nefx] = new EffectMgr(1, mutex);
  52. Pefxbypass[nefx] = false;
  53. }
  54. for(int n = 0; n < NUM_PART_EFX + 1; ++n) {
  55. partfxinputl[n] = new float [synth->buffersize];
  56. partfxinputr[n] = new float [synth->buffersize];
  57. }
  58. killallnotes = 0;
  59. oldfreq = -1.0f;
  60. for(int i = 0; i < POLIPHONY; ++i) {
  61. partnote[i].status = KEY_OFF;
  62. partnote[i].note = -1;
  63. partnote[i].itemsplaying = 0;
  64. for(int j = 0; j < NUM_KIT_ITEMS; ++j) {
  65. partnote[i].kititem[j].adnote = NULL;
  66. partnote[i].kititem[j].subnote = NULL;
  67. partnote[i].kititem[j].padnote = NULL;
  68. }
  69. partnote[i].time = 0;
  70. }
  71. cleanup();
  72. Pname = new unsigned char [PART_MAX_NAME_LEN];
  73. oldvolumel = oldvolumer = 0.5f;
  74. lastnote = -1;
  75. lastpos = 0; // lastpos will store previously used NoteOn(...)'s pos.
  76. lastlegatomodevalid = false; // To store previous legatomodevalid value.
  77. defaults();
  78. }
  79. void Part::defaults()
  80. {
  81. Penabled = 0;
  82. Pminkey = 0;
  83. Pmaxkey = 127;
  84. Pnoteon = 1;
  85. Ppolymode = 1;
  86. Plegatomode = 0;
  87. setPvolume(96);
  88. Pkeyshift = 64;
  89. Prcvchn = 0;
  90. setPpanning(64);
  91. Pvelsns = 64;
  92. Pveloffs = 64;
  93. Pkeylimit = 15;
  94. defaultsinstrument();
  95. ctl.defaults();
  96. }
  97. void Part::defaultsinstrument()
  98. {
  99. ZERO(Pname, PART_MAX_NAME_LEN);
  100. info.Ptype = 0;
  101. ZERO(info.Pauthor, MAX_INFO_TEXT_SIZE + 1);
  102. ZERO(info.Pcomments, MAX_INFO_TEXT_SIZE + 1);
  103. Pkitmode = 0;
  104. Pdrummode = 0;
  105. for(int n = 0; n < NUM_KIT_ITEMS; ++n) {
  106. kit[n].Penabled = 0;
  107. kit[n].Pmuted = 0;
  108. kit[n].Pminkey = 0;
  109. kit[n].Pmaxkey = 127;
  110. kit[n].Padenabled = 0;
  111. kit[n].Psubenabled = 0;
  112. kit[n].Ppadenabled = 0;
  113. ZERO(kit[n].Pname, PART_MAX_NAME_LEN);
  114. kit[n].Psendtoparteffect = 0;
  115. if(n != 0)
  116. setkititemstatus(n, 0);
  117. }
  118. kit[0].Penabled = 1;
  119. kit[0].Padenabled = 1;
  120. kit[0].adpars->defaults();
  121. kit[0].subpars->defaults();
  122. kit[0].padpars->defaults();
  123. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) {
  124. partefx[nefx]->defaults();
  125. Pefxroute[nefx] = 0; //route to next effect
  126. }
  127. }
  128. /*
  129. * Cleanup the part
  130. */
  131. void Part::cleanup(bool final)
  132. {
  133. for(int k = 0; k < POLIPHONY; ++k)
  134. KillNotePos(k);
  135. for(int i = 0; i < synth->buffersize; ++i) {
  136. partoutl[i] = final ? 0.0f : denormalkillbuf[i];
  137. partoutr[i] = final ? 0.0f : denormalkillbuf[i];
  138. }
  139. ctl.resetall();
  140. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx)
  141. partefx[nefx]->cleanup();
  142. for(int n = 0; n < NUM_PART_EFX + 1; ++n)
  143. for(int i = 0; i < synth->buffersize; ++i) {
  144. partfxinputl[n][i] = final ? 0.0f : denormalkillbuf[i];
  145. partfxinputr[n][i] = final ? 0.0f : denormalkillbuf[i];
  146. }
  147. }
  148. Part::~Part()
  149. {
  150. cleanup(true);
  151. for(int n = 0; n < NUM_KIT_ITEMS; ++n) {
  152. if(kit[n].adpars != NULL)
  153. delete (kit[n].adpars);
  154. if(kit[n].subpars != NULL)
  155. delete (kit[n].subpars);
  156. if(kit[n].padpars != NULL)
  157. delete (kit[n].padpars);
  158. kit[n].adpars = NULL;
  159. kit[n].subpars = NULL;
  160. kit[n].padpars = NULL;
  161. delete [] kit[n].Pname;
  162. }
  163. delete [] Pname;
  164. delete [] partoutl;
  165. delete [] partoutr;
  166. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx)
  167. delete (partefx[nefx]);
  168. for(int n = 0; n < NUM_PART_EFX + 1; ++n) {
  169. delete [] partfxinputl[n];
  170. delete [] partfxinputr[n];
  171. }
  172. }
  173. /*
  174. * Note On Messages
  175. */
  176. void Part::NoteOn(unsigned char note,
  177. unsigned char velocity,
  178. int masterkeyshift)
  179. {
  180. int i, pos;
  181. // Legato and MonoMem used vars:
  182. int posb = POLIPHONY - 1; // Just a dummy initial value.
  183. bool legatomodevalid = false; //true when legato mode is determined applicable.
  184. bool doinglegato = false; // true when we determined we do a legato note.
  185. bool ismonofirstnote = false; /*(In Mono/Legato) true when we determined
  186. no other notes are held down or sustained.*/
  187. int lastnotecopy = lastnote; //Useful after lastnote has been changed.
  188. if(Pnoteon == 0)
  189. return;
  190. if((note < Pminkey) || (note > Pmaxkey))
  191. return;
  192. // MonoMem stuff:
  193. if(Ppolymode == 0) { // If Poly is off
  194. monomemnotes.push_back(note); // Add note to the list.
  195. monomem[note].velocity = velocity; // Store this note's velocity.
  196. monomem[note].mkeyshift = masterkeyshift; /* Store masterkeyshift too,
  197. I'm not sure why though... */
  198. if((partnote[lastpos].status != KEY_PLAYING)
  199. && (partnote[lastpos].status != KEY_RELASED_AND_SUSTAINED))
  200. ismonofirstnote = true; // No other keys are held or sustained.
  201. }
  202. else
  203. // Poly mode is On so just make sure the list is empty.
  204. if(not monomemnotes.empty())
  205. monomemnotes.clear();
  206. lastnote = note;
  207. pos = -1;
  208. for(i = 0; i < POLIPHONY; ++i)
  209. if(partnote[i].status == KEY_OFF) {
  210. pos = i;
  211. break;
  212. }
  213. if((Plegatomode != 0) && (Pdrummode == 0)) {
  214. if(Ppolymode != 0) {
  215. fprintf(
  216. stderr,
  217. "ZynAddSubFX WARNING: Poly and Legato modes are both On, that should not happen ! ... Disabling Legato mode ! - (Part.cpp::NoteOn(..))\n");
  218. Plegatomode = 0;
  219. }
  220. else {
  221. // Legato mode is on and applicable.
  222. legatomodevalid = true;
  223. if((not ismonofirstnote) && (lastlegatomodevalid)) {
  224. // At least one other key is held or sustained, and the
  225. // previous note was played while in valid legato mode.
  226. doinglegato = true; // So we'll do a legato note.
  227. pos = lastpos; // A legato note uses same pos as previous..
  228. posb = lastposb; // .. same goes for posb.
  229. }
  230. else {
  231. // Legato mode is valid, but this is only a first note.
  232. for(i = 0; i < POLIPHONY; ++i)
  233. if((partnote[i].status == KEY_PLAYING)
  234. || (partnote[i].status == KEY_RELASED_AND_SUSTAINED))
  235. RelaseNotePos(i);
  236. // Set posb
  237. posb = (pos + 1) % POLIPHONY; //We really want it (if the following fails)
  238. for(i = 0; i < POLIPHONY; ++i)
  239. if((partnote[i].status == KEY_OFF) && (pos != i)) {
  240. posb = i;
  241. break;
  242. }
  243. }
  244. lastposb = posb; // Keep a trace of used posb
  245. }
  246. }
  247. else // Legato mode is either off or non-applicable.
  248. if(Ppolymode == 0) { //if the mode is 'mono' turn off all other notes
  249. for(i = 0; i < POLIPHONY; ++i)
  250. if(partnote[i].status == KEY_PLAYING)
  251. RelaseNotePos(i);
  252. RelaseSustainedKeys();
  253. }
  254. lastlegatomodevalid = legatomodevalid;
  255. if(pos == -1)
  256. //test
  257. fprintf(stderr,
  258. "%s",
  259. "NOTES TOO MANY (> POLIPHONY) - (Part.cpp::NoteOn(..))\n");
  260. else {
  261. //start the note
  262. partnote[pos].status = KEY_PLAYING;
  263. partnote[pos].note = note;
  264. if(legatomodevalid) {
  265. partnote[posb].status = KEY_PLAYING;
  266. partnote[posb].note = note;
  267. }
  268. //this computes the velocity sensing of the part
  269. float vel = VelF(velocity / 127.0f, Pvelsns);
  270. //compute the velocity offset
  271. vel += (Pveloffs - 64.0f) / 64.0f;
  272. if(vel < 0.0f)
  273. vel = 0.0f;
  274. else
  275. if(vel > 1.0f)
  276. vel = 1.0f;
  277. //compute the keyshift
  278. int partkeyshift = (int)Pkeyshift - 64;
  279. int keyshift = masterkeyshift + partkeyshift;
  280. //initialise note frequency
  281. float notebasefreq;
  282. if(Pdrummode == 0) {
  283. notebasefreq = microtonal->getnotefreq(note, keyshift);
  284. if(notebasefreq < 0.0f)
  285. return; //the key is no mapped
  286. }
  287. else
  288. notebasefreq = 440.0f * powf(2.0f, (note - 69.0f) / 12.0f);
  289. ;
  290. //Portamento
  291. if(oldfreq < 1.0f)
  292. oldfreq = notebasefreq; //this is only the first note is played
  293. // For Mono/Legato: Force Portamento Off on first
  294. // notes. That means it is required that the previous note is
  295. // still held down or sustained for the Portamento to activate
  296. // (that's like Legato).
  297. int portamento = 0;
  298. if((Ppolymode != 0) || (not ismonofirstnote))
  299. // I added a third argument to the
  300. // ctl.initportamento(...) function to be able
  301. // to tell it if we're doing a legato note.
  302. portamento = ctl.initportamento(oldfreq, notebasefreq, doinglegato);
  303. if(portamento != 0)
  304. ctl.portamento.noteusing = pos;
  305. oldfreq = notebasefreq;
  306. lastpos = pos; // Keep a trace of used pos.
  307. if(doinglegato) {
  308. // Do Legato note
  309. if(Pkitmode == 0) { // "normal mode" legato note
  310. if((kit[0].Padenabled != 0)
  311. && (partnote[pos].kititem[0].adnote != NULL)
  312. && (partnote[posb].kititem[0].adnote != NULL)) {
  313. partnote[pos].kititem[0].adnote->legatonote(notebasefreq,
  314. vel,
  315. portamento,
  316. note,
  317. true); //'true' is to tell it it's being called from here.
  318. partnote[posb].kititem[0].adnote->legatonote(notebasefreq,
  319. vel,
  320. portamento,
  321. note,
  322. true);
  323. }
  324. if((kit[0].Psubenabled != 0)
  325. && (partnote[pos].kititem[0].subnote != NULL)
  326. && (partnote[posb].kititem[0].subnote != NULL)) {
  327. partnote[pos].kititem[0].subnote->legatonote(
  328. notebasefreq, vel, portamento, note, true);
  329. partnote[posb].kititem[0].subnote->legatonote(
  330. notebasefreq, vel, portamento, note, true);
  331. }
  332. if((kit[0].Ppadenabled != 0)
  333. && (partnote[pos].kititem[0].padnote != NULL)
  334. && (partnote[posb].kititem[0].padnote != NULL)) {
  335. partnote[pos].kititem[0].padnote->legatonote(
  336. notebasefreq, vel, portamento, note, true);
  337. partnote[posb].kititem[0].padnote->legatonote(
  338. notebasefreq, vel, portamento, note, true);
  339. }
  340. }
  341. else { // "kit mode" legato note
  342. int ci = 0;
  343. for(int item = 0; item < NUM_KIT_ITEMS; ++item) {
  344. if(kit[item].Pmuted != 0)
  345. continue;
  346. if((note < kit[item].Pminkey) || (note > kit[item].Pmaxkey))
  347. continue;
  348. if((lastnotecopy < kit[item].Pminkey)
  349. || (lastnotecopy > kit[item].Pmaxkey))
  350. continue; // We will not perform legato across 2 key regions.
  351. partnote[pos].kititem[ci].sendtoparteffect =
  352. (kit[item].Psendtoparteffect <
  353. NUM_PART_EFX ? kit[item].Psendtoparteffect :
  354. NUM_PART_EFX); //if this parameter is 127 for "unprocessed"
  355. partnote[posb].kititem[ci].sendtoparteffect =
  356. (kit[item].Psendtoparteffect <
  357. NUM_PART_EFX ? kit[item].Psendtoparteffect :
  358. NUM_PART_EFX);
  359. if((kit[item].Padenabled != 0) && (kit[item].adpars != NULL)
  360. && (partnote[pos].kititem[ci].adnote != NULL)
  361. && (partnote[posb].kititem[ci].adnote != NULL)) {
  362. partnote[pos].kititem[ci].adnote->legatonote(
  363. notebasefreq, vel, portamento, note, true);
  364. partnote[posb].kititem[ci].adnote->legatonote(
  365. notebasefreq, vel, portamento, note, true);
  366. }
  367. if((kit[item].Psubenabled != 0)
  368. && (kit[item].subpars != NULL)
  369. && (partnote[pos].kititem[ci].subnote != NULL)
  370. && (partnote[posb].kititem[ci].subnote != NULL)) {
  371. partnote[pos].kititem[ci].subnote->legatonote(
  372. notebasefreq, vel, portamento, note, true);
  373. partnote[posb].kititem[ci].subnote->legatonote(
  374. notebasefreq, vel, portamento, note, true);
  375. }
  376. if((kit[item].Ppadenabled != 0)
  377. && (kit[item].padpars != NULL)
  378. && (partnote[pos].kititem[ci].padnote != NULL)
  379. && (partnote[posb].kititem[ci].padnote != NULL)) {
  380. partnote[pos].kititem[ci].padnote->legatonote(
  381. notebasefreq, vel, portamento, note, true);
  382. partnote[posb].kititem[ci].padnote->legatonote(
  383. notebasefreq, vel, portamento, note, true);
  384. }
  385. if((kit[item].adpars != NULL)
  386. || (kit[item].subpars != NULL)
  387. || (kit[item].padpars != NULL)) {
  388. ci++;
  389. if(((kit[item].Padenabled != 0)
  390. || (kit[item].Psubenabled != 0)
  391. || (kit[item].Ppadenabled != 0)) && (Pkitmode == 2))
  392. break;
  393. }
  394. }
  395. if(ci == 0) {
  396. // No legato were performed at all, so pretend nothing happened:
  397. monomemnotes.pop_back(); // Remove last note from the list.
  398. lastnote = lastnotecopy; // Set lastnote back to previous value.
  399. }
  400. }
  401. return; // Ok, Legato note done, return.
  402. }
  403. partnote[pos].itemsplaying = 0;
  404. if(legatomodevalid)
  405. partnote[posb].itemsplaying = 0;
  406. if(Pkitmode == 0) { //init the notes for the "normal mode"
  407. partnote[pos].kititem[0].sendtoparteffect = 0;
  408. if(kit[0].Padenabled != 0)
  409. partnote[pos].kititem[0].adnote = new ADnote(kit[0].adpars,
  410. &ctl,
  411. notebasefreq,
  412. vel,
  413. portamento,
  414. note,
  415. false);
  416. if(kit[0].Psubenabled != 0)
  417. partnote[pos].kititem[0].subnote = new SUBnote(kit[0].subpars,
  418. &ctl,
  419. notebasefreq,
  420. vel,
  421. portamento,
  422. note,
  423. false);
  424. if(kit[0].Ppadenabled != 0)
  425. partnote[pos].kititem[0].padnote = new PADnote(kit[0].padpars,
  426. &ctl,
  427. notebasefreq,
  428. vel,
  429. portamento,
  430. note,
  431. false);
  432. if((kit[0].Padenabled != 0) || (kit[0].Psubenabled != 0)
  433. || (kit[0].Ppadenabled != 0))
  434. partnote[pos].itemsplaying++;
  435. // Spawn another note (but silent) if legatomodevalid==true
  436. if(legatomodevalid) {
  437. partnote[posb].kititem[0].sendtoparteffect = 0;
  438. if(kit[0].Padenabled != 0)
  439. partnote[posb].kititem[0].adnote = new ADnote(kit[0].adpars,
  440. &ctl,
  441. notebasefreq,
  442. vel,
  443. portamento,
  444. note,
  445. true); //true for silent.
  446. if(kit[0].Psubenabled != 0)
  447. partnote[posb].kititem[0].subnote = new SUBnote(
  448. kit[0].subpars,
  449. &ctl,
  450. notebasefreq,
  451. vel,
  452. portamento,
  453. note,
  454. true);
  455. if(kit[0].Ppadenabled != 0)
  456. partnote[posb].kititem[0].padnote = new PADnote(
  457. kit[0].padpars,
  458. &ctl,
  459. notebasefreq,
  460. vel,
  461. portamento,
  462. note,
  463. true);
  464. if((kit[0].Padenabled != 0) || (kit[0].Psubenabled != 0)
  465. || (kit[0].Ppadenabled != 0))
  466. partnote[posb].itemsplaying++;
  467. }
  468. }
  469. else //init the notes for the "kit mode"
  470. for(int item = 0; item < NUM_KIT_ITEMS; ++item) {
  471. if(kit[item].Pmuted != 0)
  472. continue;
  473. if((note < kit[item].Pminkey) || (note > kit[item].Pmaxkey))
  474. continue;
  475. int ci = partnote[pos].itemsplaying; //ci=current item
  476. //if this parameter is 127 for "unprocessed"
  477. partnote[pos].kititem[ci].sendtoparteffect =
  478. (kit[item].Psendtoparteffect < NUM_PART_EFX ?
  479. kit[item].Psendtoparteffect : NUM_PART_EFX);
  480. if((kit[item].adpars != NULL) && ((kit[item].Padenabled) != 0))
  481. partnote[pos].kititem[ci].adnote = new ADnote(
  482. kit[item].adpars,
  483. &ctl,
  484. notebasefreq,
  485. vel,
  486. portamento,
  487. note,
  488. false);
  489. if((kit[item].subpars != NULL) && ((kit[item].Psubenabled) != 0))
  490. partnote[pos].kititem[ci].subnote = new SUBnote(
  491. kit[item].subpars,
  492. &ctl,
  493. notebasefreq,
  494. vel,
  495. portamento,
  496. note,
  497. false);
  498. if((kit[item].padpars != NULL) && ((kit[item].Ppadenabled) != 0))
  499. partnote[pos].kititem[ci].padnote = new PADnote(
  500. kit[item].padpars,
  501. &ctl,
  502. notebasefreq,
  503. vel,
  504. portamento,
  505. note,
  506. false);
  507. // Spawn another note (but silent) if legatomodevalid==true
  508. if(legatomodevalid) {
  509. partnote[posb].kititem[ci].sendtoparteffect =
  510. (kit[item].Psendtoparteffect <
  511. NUM_PART_EFX ? kit[item].Psendtoparteffect :
  512. NUM_PART_EFX); //if this parameter is 127 for "unprocessed"
  513. if((kit[item].adpars != NULL)
  514. && ((kit[item].Padenabled) != 0))
  515. partnote[posb].kititem[ci].adnote = new ADnote(
  516. kit[item].adpars,
  517. &ctl,
  518. notebasefreq,
  519. vel,
  520. portamento,
  521. note,
  522. true); //true for silent.
  523. if((kit[item].subpars != NULL)
  524. && ((kit[item].Psubenabled) != 0))
  525. partnote[posb].kititem[ci].subnote =
  526. new SUBnote(kit[item].subpars,
  527. &ctl,
  528. notebasefreq,
  529. vel,
  530. portamento,
  531. note,
  532. true);
  533. if((kit[item].padpars != NULL)
  534. && ((kit[item].Ppadenabled) != 0))
  535. partnote[posb].kititem[ci].padnote =
  536. new PADnote(kit[item].padpars,
  537. &ctl,
  538. notebasefreq,
  539. vel,
  540. portamento,
  541. note,
  542. true);
  543. if((kit[item].adpars != NULL) || (kit[item].subpars != NULL))
  544. partnote[posb].itemsplaying++;
  545. }
  546. if((kit[item].adpars != NULL) || (kit[item].subpars != NULL)) {
  547. partnote[pos].itemsplaying++;
  548. if(((kit[item].Padenabled != 0)
  549. || (kit[item].Psubenabled != 0)
  550. || (kit[item].Ppadenabled != 0))
  551. && (Pkitmode == 2))
  552. break;
  553. }
  554. }
  555. }
  556. //this only relase the keys if there is maximum number of keys allowed
  557. setkeylimit(Pkeylimit);
  558. }
  559. /*
  560. * Note Off Messages
  561. */
  562. void Part::NoteOff(unsigned char note) //relase the key
  563. {
  564. int i;
  565. // This note is released, so we remove it from the list.
  566. if(not monomemnotes.empty())
  567. monomemnotes.remove(note);
  568. for(i = POLIPHONY - 1; i >= 0; i--) //first note in, is first out if there are same note multiple times
  569. if((partnote[i].status == KEY_PLAYING) && (partnote[i].note == note)) {
  570. if(ctl.sustain.sustain == 0) { //the sustain pedal is not pushed
  571. if((Ppolymode == 0) && (not monomemnotes.empty()))
  572. MonoMemRenote(); // To play most recent still held note.
  573. else
  574. RelaseNotePos(i);
  575. /// break;
  576. }
  577. else //the sustain pedal is pushed
  578. partnote[i].status = KEY_RELASED_AND_SUSTAINED;
  579. }
  580. }
  581. void Part::PolyphonicAftertouch(unsigned char note,
  582. unsigned char velocity,
  583. int masterkeyshift)
  584. {
  585. (void) masterkeyshift;
  586. if(!Pnoteon || (note < Pminkey) || (note > Pmaxkey))
  587. return;
  588. if(Pdrummode)
  589. return;
  590. // MonoMem stuff:
  591. if(!Ppolymode) // if Poly is off
  592. monomem[note].velocity = velocity; // Store this note's velocity.
  593. for(int i = 0; i < POLIPHONY; ++i)
  594. if((partnote[i].note == note) && (partnote[i].status == KEY_PLAYING)) {
  595. /* update velocity */
  596. // compute the velocity offset
  597. float vel =
  598. VelF(velocity / 127.0f, Pvelsns) + (Pveloffs - 64.0f) / 64.0f;
  599. vel = (vel < 0.0f) ? 0.0f : vel;
  600. vel = (vel > 1.0f) ? 1.0f : vel;
  601. if(!Pkitmode) { // "normal mode"
  602. if(kit[0].Padenabled)
  603. partnote[i].kititem[0].adnote->setVelocity(vel);
  604. if(kit[0].Psubenabled)
  605. partnote[i].kititem[0].subnote->setVelocity(vel);
  606. if(kit[0].Ppadenabled)
  607. partnote[i].kititem[0].padnote->setVelocity(vel);
  608. }
  609. else // "kit mode"
  610. for(int item = 0; item < NUM_KIT_ITEMS; ++item) {
  611. if(kit[item].Pmuted)
  612. continue;
  613. if((note < kit[item].Pminkey)
  614. || (note > kit[item].Pmaxkey))
  615. continue;
  616. if(kit[item].Padenabled)
  617. partnote[i].kititem[item].adnote->setVelocity(vel);
  618. if(kit[item].Psubenabled)
  619. partnote[i].kititem[item].subnote->setVelocity(vel);
  620. if(kit[item].Ppadenabled)
  621. partnote[i].kititem[item].padnote->setVelocity(vel);
  622. }
  623. }
  624. }
  625. /*
  626. * Controllers
  627. */
  628. void Part::SetController(unsigned int type, int par)
  629. {
  630. switch(type) {
  631. case C_pitchwheel:
  632. ctl.setpitchwheel(par);
  633. break;
  634. case C_expression:
  635. ctl.setexpression(par);
  636. setPvolume(Pvolume); //update the volume
  637. break;
  638. case C_portamento:
  639. ctl.setportamento(par);
  640. break;
  641. case C_panning:
  642. ctl.setpanning(par);
  643. setPpanning(Ppanning); //update the panning
  644. break;
  645. case C_filtercutoff:
  646. ctl.setfiltercutoff(par);
  647. break;
  648. case C_filterq:
  649. ctl.setfilterq(par);
  650. break;
  651. case C_bandwidth:
  652. ctl.setbandwidth(par);
  653. break;
  654. case C_modwheel:
  655. ctl.setmodwheel(par);
  656. break;
  657. case C_fmamp:
  658. ctl.setfmamp(par);
  659. break;
  660. case C_volume:
  661. ctl.setvolume(par);
  662. if(ctl.volume.receive != 0)
  663. volume = ctl.volume.volume;
  664. else
  665. setPvolume(Pvolume);
  666. break;
  667. case C_sustain:
  668. ctl.setsustain(par);
  669. if(ctl.sustain.sustain == 0)
  670. RelaseSustainedKeys();
  671. break;
  672. case C_allsoundsoff:
  673. AllNotesOff(); //Panic
  674. break;
  675. case C_resetallcontrollers:
  676. ctl.resetall();
  677. RelaseSustainedKeys();
  678. if(ctl.volume.receive != 0)
  679. volume = ctl.volume.volume;
  680. else
  681. setPvolume(Pvolume);
  682. setPvolume(Pvolume); //update the volume
  683. setPpanning(Ppanning); //update the panning
  684. for(int item = 0; item < NUM_KIT_ITEMS; ++item) {
  685. if(kit[item].adpars == NULL)
  686. continue;
  687. kit[item].adpars->GlobalPar.Reson->
  688. sendcontroller(C_resonance_center, 1.0f);
  689. kit[item].adpars->GlobalPar.Reson->
  690. sendcontroller(C_resonance_bandwidth, 1.0f);
  691. }
  692. //more update to add here if I add controllers
  693. break;
  694. case C_allnotesoff:
  695. RelaseAllKeys();
  696. break;
  697. case C_resonance_center:
  698. ctl.setresonancecenter(par);
  699. for(int item = 0; item < NUM_KIT_ITEMS; ++item) {
  700. if(kit[item].adpars == NULL)
  701. continue;
  702. kit[item].adpars->GlobalPar.Reson->
  703. sendcontroller(C_resonance_center,
  704. ctl.resonancecenter.relcenter);
  705. }
  706. break;
  707. case C_resonance_bandwidth:
  708. ctl.setresonancebw(par);
  709. kit[0].adpars->GlobalPar.Reson->
  710. sendcontroller(C_resonance_bandwidth, ctl.resonancebandwidth.relbw);
  711. break;
  712. }
  713. }
  714. /*
  715. * Relase the sustained keys
  716. */
  717. void Part::RelaseSustainedKeys()
  718. {
  719. // Let's call MonoMemRenote() on some conditions:
  720. if((Ppolymode == 0) && (not monomemnotes.empty()))
  721. if(monomemnotes.back() != lastnote) // Sustain controller manipulation would cause repeated same note respawn without this check.
  722. MonoMemRenote(); // To play most recent still held note.
  723. for(int i = 0; i < POLIPHONY; ++i)
  724. if(partnote[i].status == KEY_RELASED_AND_SUSTAINED)
  725. RelaseNotePos(i);
  726. }
  727. /*
  728. * Relase all keys
  729. */
  730. void Part::RelaseAllKeys()
  731. {
  732. for(int i = 0; i < POLIPHONY; ++i)
  733. if((partnote[i].status != KEY_RELASED)
  734. && (partnote[i].status != KEY_OFF)) //thanks to Frank Neumann
  735. RelaseNotePos(i);
  736. }
  737. // Call NoteOn(...) with the most recent still held key as new note
  738. // (Made for Mono/Legato).
  739. void Part::MonoMemRenote()
  740. {
  741. unsigned char mmrtempnote = monomemnotes.back(); // Last list element.
  742. monomemnotes.pop_back(); // We remove it, will be added again in NoteOn(...).
  743. if(Pnoteon == 0)
  744. RelaseNotePos(lastpos);
  745. else
  746. NoteOn(mmrtempnote, monomem[mmrtempnote].velocity,
  747. monomem[mmrtempnote].mkeyshift);
  748. }
  749. /*
  750. * Release note at position
  751. */
  752. void Part::RelaseNotePos(int pos)
  753. {
  754. for(int j = 0; j < NUM_KIT_ITEMS; ++j) {
  755. if(partnote[pos].kititem[j].adnote != NULL)
  756. if(partnote[pos].kititem[j].adnote)
  757. partnote[pos].kititem[j].adnote->relasekey();
  758. if(partnote[pos].kititem[j].subnote != NULL)
  759. if(partnote[pos].kititem[j].subnote != NULL)
  760. partnote[pos].kititem[j].subnote->relasekey();
  761. if(partnote[pos].kititem[j].padnote != NULL)
  762. if(partnote[pos].kititem[j].padnote)
  763. partnote[pos].kititem[j].padnote->relasekey();
  764. }
  765. partnote[pos].status = KEY_RELASED;
  766. }
  767. /*
  768. * Kill note at position
  769. */
  770. void Part::KillNotePos(int pos)
  771. {
  772. partnote[pos].status = KEY_OFF;
  773. partnote[pos].note = -1;
  774. partnote[pos].time = 0;
  775. partnote[pos].itemsplaying = 0;
  776. for(int j = 0; j < NUM_KIT_ITEMS; ++j) {
  777. if(partnote[pos].kititem[j].adnote != NULL) {
  778. delete (partnote[pos].kititem[j].adnote);
  779. partnote[pos].kititem[j].adnote = NULL;
  780. }
  781. if(partnote[pos].kititem[j].subnote != NULL) {
  782. delete (partnote[pos].kititem[j].subnote);
  783. partnote[pos].kititem[j].subnote = NULL;
  784. }
  785. if(partnote[pos].kititem[j].padnote != NULL) {
  786. delete (partnote[pos].kititem[j].padnote);
  787. partnote[pos].kititem[j].padnote = NULL;
  788. }
  789. }
  790. if(pos == ctl.portamento.noteusing) {
  791. ctl.portamento.noteusing = -1;
  792. ctl.portamento.used = 0;
  793. }
  794. }
  795. /*
  796. * Set Part's key limit
  797. */
  798. void Part::setkeylimit(unsigned char Pkeylimit)
  799. {
  800. this->Pkeylimit = Pkeylimit;
  801. int keylimit = Pkeylimit;
  802. if(keylimit == 0)
  803. keylimit = POLIPHONY - 5;
  804. //release old keys if the number of notes>keylimit
  805. if(Ppolymode != 0) {
  806. int notecount = 0;
  807. for(int i = 0; i < POLIPHONY; ++i)
  808. if((partnote[i].status == KEY_PLAYING)
  809. || (partnote[i].status == KEY_RELASED_AND_SUSTAINED))
  810. notecount++;
  811. int oldestnotepos = -1;
  812. if(notecount > keylimit) //find out the oldest note
  813. for(int i = 0; i < POLIPHONY; ++i) {
  814. int maxtime = 0;
  815. if(((partnote[i].status == KEY_PLAYING)
  816. || (partnote[i].status == KEY_RELASED_AND_SUSTAINED))
  817. && (partnote[i].time > maxtime)) {
  818. maxtime = partnote[i].time;
  819. oldestnotepos = i;
  820. }
  821. }
  822. if(oldestnotepos != -1)
  823. RelaseNotePos(oldestnotepos);
  824. }
  825. }
  826. /*
  827. * Prepare all notes to be turned off
  828. */
  829. void Part::AllNotesOff()
  830. {
  831. killallnotes = 1;
  832. }
  833. void Part::RunNote(unsigned int k)
  834. {
  835. unsigned noteplay = 0;
  836. for(int item = 0; item < partnote[k].itemsplaying; ++item) {
  837. int sendcurrenttofx = partnote[k].kititem[item].sendtoparteffect;
  838. for(unsigned type = 0; type < 3; ++type) {
  839. //Select a note
  840. SynthNote **note;
  841. if(type == 0)
  842. note = &partnote[k].kititem[item].adnote;
  843. else
  844. if(type == 1)
  845. note = &partnote[k].kititem[item].subnote;
  846. else
  847. if(type == 2)
  848. note = &partnote[k].kititem[item].padnote;
  849. //Process if it exists
  850. if(!(*note))
  851. continue;
  852. noteplay++;
  853. float *tmpoutr = getTmpBuffer();
  854. float *tmpoutl = getTmpBuffer();
  855. (*note)->noteout(&tmpoutl[0], &tmpoutr[0]);
  856. if((*note)->finished()) {
  857. delete (*note);
  858. (*note) = NULL;
  859. }
  860. for(int i = 0; i < synth->buffersize; ++i) { //add the note to part(mix)
  861. partfxinputl[sendcurrenttofx][i] += tmpoutl[i];
  862. partfxinputr[sendcurrenttofx][i] += tmpoutr[i];
  863. }
  864. returnTmpBuffer(tmpoutr);
  865. returnTmpBuffer(tmpoutl);
  866. }
  867. }
  868. //Kill note if there is no synth on that note
  869. if(noteplay == 0)
  870. KillNotePos(k);
  871. }
  872. /*
  873. * Compute Part samples and store them in the partoutl[] and partoutr[]
  874. */
  875. void Part::ComputePartSmps()
  876. {
  877. for(unsigned nefx = 0; nefx < NUM_PART_EFX + 1; ++nefx)
  878. for(int i = 0; i < synth->buffersize; ++i) {
  879. partfxinputl[nefx][i] = 0.0f;
  880. partfxinputr[nefx][i] = 0.0f;
  881. }
  882. for(unsigned k = 0; k < POLIPHONY; ++k) {
  883. if(partnote[k].status == KEY_OFF)
  884. continue;
  885. partnote[k].time++;
  886. //get the sampledata of the note and kill it if it's finished
  887. RunNote(k);
  888. }
  889. //Apply part's effects and mix them
  890. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) {
  891. if(!Pefxbypass[nefx]) {
  892. partefx[nefx]->out(partfxinputl[nefx], partfxinputr[nefx]);
  893. if(Pefxroute[nefx] == 2)
  894. for(int i = 0; i < synth->buffersize; ++i) {
  895. partfxinputl[nefx + 1][i] += partefx[nefx]->efxoutl[i];
  896. partfxinputr[nefx + 1][i] += partefx[nefx]->efxoutr[i];
  897. }
  898. }
  899. int routeto = ((Pefxroute[nefx] == 0) ? nefx + 1 : NUM_PART_EFX);
  900. for(int i = 0; i < synth->buffersize; ++i) {
  901. partfxinputl[routeto][i] += partfxinputl[nefx][i];
  902. partfxinputr[routeto][i] += partfxinputr[nefx][i];
  903. }
  904. }
  905. for(int i = 0; i < synth->buffersize; ++i) {
  906. partoutl[i] = partfxinputl[NUM_PART_EFX][i];
  907. partoutr[i] = partfxinputr[NUM_PART_EFX][i];
  908. }
  909. //Kill All Notes if killallnotes!=0
  910. if(killallnotes != 0) {
  911. for(int i = 0; i < synth->buffersize; ++i) {
  912. float tmp = (synth->buffersize_f - i) / synth->buffersize_f;
  913. partoutl[i] *= tmp;
  914. partoutr[i] *= tmp;
  915. }
  916. for(int k = 0; k < POLIPHONY; ++k)
  917. KillNotePos(k);
  918. killallnotes = 0;
  919. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx)
  920. partefx[nefx]->cleanup();
  921. }
  922. ctl.updateportamento();
  923. }
  924. /*
  925. * Parameter control
  926. */
  927. void Part::setPvolume(char Pvolume_)
  928. {
  929. Pvolume = Pvolume_;
  930. volume =
  931. dB2rap((Pvolume - 96.0f) / 96.0f * 40.0f) * ctl.expression.relvolume;
  932. }
  933. void Part::setPpanning(char Ppanning_)
  934. {
  935. Ppanning = Ppanning_;
  936. panning = Ppanning / 127.0f + ctl.panning.pan;
  937. if(panning < 0.0f)
  938. panning = 0.0f;
  939. else
  940. if(panning > 1.0f)
  941. panning = 1.0f;
  942. }
  943. /*
  944. * Enable or disable a kit item
  945. */
  946. void Part::setkititemstatus(int kititem, int Penabled_)
  947. {
  948. if((kititem == 0) || (kititem >= NUM_KIT_ITEMS))
  949. return; //nonexistent kit item and the first kit item is always enabled
  950. kit[kititem].Penabled = Penabled_;
  951. bool resetallnotes = false;
  952. if(Penabled_ == 0) {
  953. if(kit[kititem].adpars != NULL)
  954. delete (kit[kititem].adpars);
  955. if(kit[kititem].subpars != NULL)
  956. delete (kit[kititem].subpars);
  957. if(kit[kititem].padpars != NULL) {
  958. delete (kit[kititem].padpars);
  959. resetallnotes = true;
  960. }
  961. kit[kititem].adpars = NULL;
  962. kit[kititem].subpars = NULL;
  963. kit[kititem].padpars = NULL;
  964. kit[kititem].Pname[0] = '\0';
  965. }
  966. else {
  967. if(kit[kititem].adpars == NULL)
  968. kit[kititem].adpars = new ADnoteParameters(fft);
  969. if(kit[kititem].subpars == NULL)
  970. kit[kititem].subpars = new SUBnoteParameters();
  971. if(kit[kititem].padpars == NULL)
  972. kit[kititem].padpars = new PADnoteParameters(fft, mutex);
  973. }
  974. if(resetallnotes)
  975. for(int k = 0; k < POLIPHONY; ++k)
  976. KillNotePos(k);
  977. }
  978. void Part::add2XMLinstrument(XMLwrapper *xml)
  979. {
  980. xml->beginbranch("INFO");
  981. xml->addparstr("name", (char *)Pname);
  982. xml->addparstr("author", (char *)info.Pauthor);
  983. xml->addparstr("comments", (char *)info.Pcomments);
  984. xml->addpar("type", info.Ptype);
  985. xml->endbranch();
  986. xml->beginbranch("INSTRUMENT_KIT");
  987. xml->addpar("kit_mode", Pkitmode);
  988. xml->addparbool("drum_mode", Pdrummode);
  989. for(int i = 0; i < NUM_KIT_ITEMS; ++i) {
  990. xml->beginbranch("INSTRUMENT_KIT_ITEM", i);
  991. xml->addparbool("enabled", kit[i].Penabled);
  992. if(kit[i].Penabled != 0) {
  993. xml->addparstr("name", (char *)kit[i].Pname);
  994. xml->addparbool("muted", kit[i].Pmuted);
  995. xml->addpar("min_key", kit[i].Pminkey);
  996. xml->addpar("max_key", kit[i].Pmaxkey);
  997. xml->addpar("send_to_instrument_effect", kit[i].Psendtoparteffect);
  998. xml->addparbool("add_enabled", kit[i].Padenabled);
  999. if((kit[i].Padenabled != 0) && (kit[i].adpars != NULL)) {
  1000. xml->beginbranch("ADD_SYNTH_PARAMETERS");
  1001. kit[i].adpars->add2XML(xml);
  1002. xml->endbranch();
  1003. }
  1004. xml->addparbool("sub_enabled", kit[i].Psubenabled);
  1005. if((kit[i].Psubenabled != 0) && (kit[i].subpars != NULL)) {
  1006. xml->beginbranch("SUB_SYNTH_PARAMETERS");
  1007. kit[i].subpars->add2XML(xml);
  1008. xml->endbranch();
  1009. }
  1010. xml->addparbool("pad_enabled", kit[i].Ppadenabled);
  1011. if((kit[i].Ppadenabled != 0) && (kit[i].padpars != NULL)) {
  1012. xml->beginbranch("PAD_SYNTH_PARAMETERS");
  1013. kit[i].padpars->add2XML(xml);
  1014. xml->endbranch();
  1015. }
  1016. }
  1017. xml->endbranch();
  1018. }
  1019. xml->endbranch();
  1020. xml->beginbranch("INSTRUMENT_EFFECTS");
  1021. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) {
  1022. xml->beginbranch("INSTRUMENT_EFFECT", nefx);
  1023. xml->beginbranch("EFFECT");
  1024. partefx[nefx]->add2XML(xml);
  1025. xml->endbranch();
  1026. xml->addpar("route", Pefxroute[nefx]);
  1027. partefx[nefx]->setdryonly(Pefxroute[nefx] == 2);
  1028. xml->addparbool("bypass", Pefxbypass[nefx]);
  1029. xml->endbranch();
  1030. }
  1031. xml->endbranch();
  1032. }
  1033. void Part::add2XML(XMLwrapper *xml)
  1034. {
  1035. //parameters
  1036. xml->addparbool("enabled", Penabled);
  1037. if((Penabled == 0) && (xml->minimal))
  1038. return;
  1039. xml->addpar("volume", Pvolume);
  1040. xml->addpar("panning", Ppanning);
  1041. xml->addpar("min_key", Pminkey);
  1042. xml->addpar("max_key", Pmaxkey);
  1043. xml->addpar("key_shift", Pkeyshift);
  1044. xml->addpar("rcv_chn", Prcvchn);
  1045. xml->addpar("velocity_sensing", Pvelsns);
  1046. xml->addpar("velocity_offset", Pveloffs);
  1047. xml->addparbool("note_on", Pnoteon);
  1048. xml->addparbool("poly_mode", Ppolymode);
  1049. xml->addpar("legato_mode", Plegatomode);
  1050. xml->addpar("key_limit", Pkeylimit);
  1051. xml->beginbranch("INSTRUMENT");
  1052. add2XMLinstrument(xml);
  1053. xml->endbranch();
  1054. xml->beginbranch("CONTROLLER");
  1055. ctl.add2XML(xml);
  1056. xml->endbranch();
  1057. }
  1058. int Part::saveXML(const char *filename)
  1059. {
  1060. XMLwrapper *xml;
  1061. xml = new XMLwrapper();
  1062. xml->beginbranch("INSTRUMENT");
  1063. add2XMLinstrument(xml);
  1064. xml->endbranch();
  1065. int result = xml->saveXMLfile(filename);
  1066. delete (xml);
  1067. return result;
  1068. }
  1069. int Part::loadXMLinstrument(const char *filename) /*{*/
  1070. {
  1071. XMLwrapper *xml = new XMLwrapper();
  1072. if(xml->loadXMLfile(filename) < 0) {
  1073. delete (xml);
  1074. return -1;
  1075. }
  1076. if(xml->enterbranch("INSTRUMENT") == 0)
  1077. return -10;
  1078. getfromXMLinstrument(xml);
  1079. xml->exitbranch();
  1080. delete (xml);
  1081. return 0;
  1082. } /*}*/
  1083. void Part::applyparameters(bool lockmutex) /*{*/
  1084. {
  1085. for(int n = 0; n < NUM_KIT_ITEMS; ++n)
  1086. if((kit[n].padpars != NULL) && (kit[n].Ppadenabled != 0))
  1087. kit[n].padpars->applyparameters(lockmutex);
  1088. } /*}*/
  1089. void Part::getfromXMLinstrument(XMLwrapper *xml)
  1090. {
  1091. if(xml->enterbranch("INFO")) {
  1092. xml->getparstr("name", (char *)Pname, PART_MAX_NAME_LEN);
  1093. xml->getparstr("author", (char *)info.Pauthor, MAX_INFO_TEXT_SIZE);
  1094. xml->getparstr("comments", (char *)info.Pcomments, MAX_INFO_TEXT_SIZE);
  1095. info.Ptype = xml->getpar("type", info.Ptype, 0, 16);
  1096. xml->exitbranch();
  1097. }
  1098. if(xml->enterbranch("INSTRUMENT_KIT")) {
  1099. Pkitmode = xml->getpar127("kit_mode", Pkitmode);
  1100. Pdrummode = xml->getparbool("drum_mode", Pdrummode);
  1101. setkititemstatus(0, 0);
  1102. for(int i = 0; i < NUM_KIT_ITEMS; ++i) {
  1103. if(xml->enterbranch("INSTRUMENT_KIT_ITEM", i) == 0)
  1104. continue;
  1105. setkititemstatus(i, xml->getparbool("enabled", kit[i].Penabled));
  1106. if(kit[i].Penabled == 0) {
  1107. xml->exitbranch();
  1108. continue;
  1109. }
  1110. xml->getparstr("name", (char *)kit[i].Pname, PART_MAX_NAME_LEN);
  1111. kit[i].Pmuted = xml->getparbool("muted", kit[i].Pmuted);
  1112. kit[i].Pminkey = xml->getpar127("min_key", kit[i].Pminkey);
  1113. kit[i].Pmaxkey = xml->getpar127("max_key", kit[i].Pmaxkey);
  1114. kit[i].Psendtoparteffect = xml->getpar127(
  1115. "send_to_instrument_effect",
  1116. kit[i].Psendtoparteffect);
  1117. kit[i].Padenabled = xml->getparbool("add_enabled",
  1118. kit[i].Padenabled);
  1119. if(xml->enterbranch("ADD_SYNTH_PARAMETERS")) {
  1120. kit[i].adpars->getfromXML(xml);
  1121. xml->exitbranch();
  1122. }
  1123. kit[i].Psubenabled = xml->getparbool("sub_enabled",
  1124. kit[i].Psubenabled);
  1125. if(xml->enterbranch("SUB_SYNTH_PARAMETERS")) {
  1126. kit[i].subpars->getfromXML(xml);
  1127. xml->exitbranch();
  1128. }
  1129. kit[i].Ppadenabled = xml->getparbool("pad_enabled",
  1130. kit[i].Ppadenabled);
  1131. if(xml->enterbranch("PAD_SYNTH_PARAMETERS")) {
  1132. kit[i].padpars->getfromXML(xml);
  1133. xml->exitbranch();
  1134. }
  1135. xml->exitbranch();
  1136. }
  1137. xml->exitbranch();
  1138. }
  1139. if(xml->enterbranch("INSTRUMENT_EFFECTS")) {
  1140. for(int nefx = 0; nefx < NUM_PART_EFX; ++nefx) {
  1141. if(xml->enterbranch("INSTRUMENT_EFFECT", nefx) == 0)
  1142. continue;
  1143. if(xml->enterbranch("EFFECT")) {
  1144. partefx[nefx]->getfromXML(xml);
  1145. xml->exitbranch();
  1146. }
  1147. Pefxroute[nefx] = xml->getpar("route",
  1148. Pefxroute[nefx],
  1149. 0,
  1150. NUM_PART_EFX);
  1151. partefx[nefx]->setdryonly(Pefxroute[nefx] == 2);
  1152. Pefxbypass[nefx] = xml->getparbool("bypass", Pefxbypass[nefx]);
  1153. xml->exitbranch();
  1154. }
  1155. xml->exitbranch();
  1156. }
  1157. }
  1158. void Part::getfromXML(XMLwrapper *xml)
  1159. {
  1160. Penabled = xml->getparbool("enabled", Penabled);
  1161. setPvolume(xml->getpar127("volume", Pvolume));
  1162. setPpanning(xml->getpar127("panning", Ppanning));
  1163. Pminkey = xml->getpar127("min_key", Pminkey);
  1164. Pmaxkey = xml->getpar127("max_key", Pmaxkey);
  1165. Pkeyshift = xml->getpar127("key_shift", Pkeyshift);
  1166. Prcvchn = xml->getpar127("rcv_chn", Prcvchn);
  1167. Pvelsns = xml->getpar127("velocity_sensing", Pvelsns);
  1168. Pveloffs = xml->getpar127("velocity_offset", Pveloffs);
  1169. Pnoteon = xml->getparbool("note_on", Pnoteon);
  1170. Ppolymode = xml->getparbool("poly_mode", Ppolymode);
  1171. Plegatomode = xml->getparbool("legato_mode", Plegatomode); //older versions
  1172. if(!Plegatomode)
  1173. Plegatomode = xml->getpar127("legato_mode", Plegatomode);
  1174. Pkeylimit = xml->getpar127("key_limit", Pkeylimit);
  1175. if(xml->enterbranch("INSTRUMENT")) {
  1176. getfromXMLinstrument(xml);
  1177. xml->exitbranch();
  1178. }
  1179. if(xml->enterbranch("CONTROLLER")) {
  1180. ctl.getfromXML(xml);
  1181. xml->exitbranch();
  1182. }
  1183. }