summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/synti/zynaddsubfx/Params/Presets.C
blob: e5f6e10c24ef58ddbf01fe8605265c13d5dd5748 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
  ZynAddSubFX - a software synthesizer
 
  Presets.C - Presets and Clipboard management
  Copyright (C) 2002-2005 Nasca Octavian Paul
  Author: Nasca Octavian Paul

  This program is free software; you can redistribute it and/or modify
  it under the terms of version 2 of the GNU General Public License 
  as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License (version 2) for more details.

  You should have received a copy of the GNU General Public License (version 2)
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

*/

#include "Presets.h"
#include <string.h>


Presets::Presets(){
    type[0]=0;
    nelement=-1;
};

Presets::~Presets(){
};

void Presets::setpresettype(char *type){
    strcpy(this->type,type);
};

void Presets::copy(const char *name){
    XMLwrapper *xml=new XMLwrapper();
    
    //used only for the clipboard
    if (name==NULL) xml->minimal=false;
    
    char type[MAX_PRESETTYPE_SIZE];
    strcpy(type,this->type);
    if (nelement!=-1) strcat(type,"n");
    if (name==NULL) {
	if (strstr(type,"Plfo")!=NULL) strcpy(type,"Plfo");
    };

    xml->beginbranch(type);
    if (nelement==-1) add2XML(xml);
	else add2XMLsection(xml,nelement);
    xml->endbranch();

    if (name==NULL) presetsstore.copyclipboard(xml,type);
	else presetsstore.copypreset(xml,type,name);
    
    delete(xml);
    nelement=-1;
};

void Presets::paste(int npreset){
    char type[MAX_PRESETTYPE_SIZE];
    strcpy(type,this->type);
    if (nelement!=-1) strcat(type,"n");
    if (npreset==0){
	if (strstr(type,"Plfo")!=NULL) strcpy(type,"Plfo");
    };

    XMLwrapper *xml=new XMLwrapper();
    if (npreset==0){
	if (!checkclipboardtype()) {
	    nelement=-1;
	    delete(xml);
	    return;
	};
	if (!presetsstore.pasteclipboard(xml)) {
	    delete(xml);
	    nelement=-1;
	    return;
	};
    } else {
	if (!presetsstore.pastepreset(xml,npreset)) {
	    delete(xml);
	    nelement=-1;
	    return;
	};
    };
    
    if (xml->enterbranch(type)==0) {
	nelement=-1;
	return;
    };
	if (nelement==-1) {
	    defaults();
	    getfromXML(xml);
	} else {
	    defaults(nelement);
	    getfromXMLsection(xml,nelement);
	};
    xml->exitbranch();
    
    delete(xml);
    nelement=-1;
};

bool Presets::checkclipboardtype(){
    char type[MAX_PRESETTYPE_SIZE];
    strcpy(type,this->type);
    if (nelement!=-1) strcat(type,"n");

    return(presetsstore.checkclipboardtype(type));
};

void Presets::setelement(int n){
    nelement=n;
};

void Presets::rescanforpresets(){
    presetsstore.rescanforpresets(type);
};


void Presets::deletepreset(int npreset){
    presetsstore.deletepreset(npreset);
};