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.

PresetsArray.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. PresetsArray.cpp - PresetsArray and Clipboard management
  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 "PresetsArray.h"
  18. #include <string.h>
  19. PresetsArray::PresetsArray()
  20. {
  21. type[0] = 0;
  22. nelement = -1;
  23. }
  24. PresetsArray::~PresetsArray()
  25. {}
  26. void PresetsArray::setpresettype(const char *type)
  27. {
  28. strcpy(this->type, type);
  29. }
  30. void PresetsArray::copy(const char *name)
  31. {
  32. XMLwrapper *xml = new XMLwrapper();
  33. //used only for the clipboard
  34. if(name == NULL)
  35. xml->minimal = false;
  36. char type[MAX_PRESETTYPE_SIZE];
  37. strcpy(type, this->type);
  38. if(nelement != -1)
  39. strcat(type, "n");
  40. if(name == NULL)
  41. if(strstr(type, "Plfo") != NULL)
  42. strcpy(type, "Plfo");
  43. ;
  44. xml->beginbranch(type);
  45. if(nelement == -1)
  46. add2XML(xml);
  47. else
  48. add2XMLsection(xml, nelement);
  49. xml->endbranch();
  50. if(name == NULL)
  51. presetsstore.copyclipboard(xml, type);
  52. else
  53. presetsstore.copypreset(xml, type, name);
  54. delete (xml);
  55. nelement = -1;
  56. }
  57. void PresetsArray::paste(int npreset)
  58. {
  59. char type[MAX_PRESETTYPE_SIZE];
  60. strcpy(type, this->type);
  61. if(nelement != -1)
  62. strcat(type, "n");
  63. if(npreset == 0)
  64. if(strstr(type, "Plfo") != NULL)
  65. strcpy(type, "Plfo");
  66. ;
  67. XMLwrapper *xml = new XMLwrapper();
  68. if(npreset == 0) {
  69. if(!checkclipboardtype()) {
  70. nelement = -1;
  71. delete (xml);
  72. return;
  73. }
  74. if(!presetsstore.pasteclipboard(xml)) {
  75. delete (xml);
  76. nelement = -1;
  77. return;
  78. }
  79. }
  80. else
  81. if(!presetsstore.pastepreset(xml, npreset)) {
  82. delete (xml);
  83. nelement = -1;
  84. return;
  85. }
  86. if(xml->enterbranch(type) == 0) {
  87. nelement = -1;
  88. return;
  89. }
  90. if(nelement == -1) {
  91. defaults();
  92. getfromXML(xml);
  93. }
  94. else {
  95. defaults(nelement);
  96. getfromXMLsection(xml, nelement);
  97. }
  98. xml->exitbranch();
  99. delete (xml);
  100. nelement = -1;
  101. }
  102. bool PresetsArray::checkclipboardtype()
  103. {
  104. char type[MAX_PRESETTYPE_SIZE];
  105. strcpy(type, this->type);
  106. if(nelement != -1)
  107. strcat(type, "n");
  108. return presetsstore.checkclipboardtype(type);
  109. }
  110. void PresetsArray::rescanforpresets()
  111. {
  112. char type[MAX_PRESETTYPE_SIZE];
  113. strcpy(type, this->type);
  114. if(nelement != -1)
  115. strcat(type, "n");
  116. presetsstore.rescanforpresets(type);
  117. }
  118. void PresetsArray::setelement(int n)
  119. {
  120. nelement = n;
  121. }