1
// ------------------------------------------------------------------------
2
// eca-preset-map: Dynamic register for storing effect presets
3
// Copyright (C) 2000-2003 Kai Vehmanen
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// ------------------------------------------------------------------------
31
#include "eca-object.h"
32
#include "eca-resources.h"
33
#include "eca-preset-map.h"
34
#include "global-preset.h"
42
ECA_PRESET_MAP::ECA_PRESET_MAP(void)
44
#ifndef ECA_DISABLE_EFFECTS
48
ecarc.resource("user-resource-directory") + "/" + ecarc.resource("resource-file-effect-presets");
50
string global_filename =
51
ecarc.resource("resource-directory") + "/" + ecarc.resource("resource-file-effect-presets");
53
load_preset_file(global_filename);
54
load_preset_file(filename);
58
ECA_PRESET_MAP::~ECA_PRESET_MAP(void)
62
void ECA_PRESET_MAP::load_preset_file(const string& fname)
64
RESOURCE_FILE preset_file;
65
preset_file.resource_file(fname);
67
const vector<string>& pmap = preset_file.keywords();
68
vector<string>::const_iterator p = pmap.begin();
69
while(p != pmap.end()) {
70
if (*p != "") preset_keywords_rep.push_back(*p);
75
void ECA_PRESET_MAP::register_object(const string& keyword, const string& matchstr, ECA_OBJECT* object)
77
if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), keyword) == preset_keywords_rep.end())
78
preset_keywords_rep.push_back(keyword);
80
ECA_OBJECT_MAP::register_object(keyword, matchstr, object);
83
void ECA_PRESET_MAP::unregister_object(const string& keyword)
85
preset_keywords_rep.remove(keyword);
86
ECA_OBJECT_MAP::unregister_object(keyword);
89
const list<string>& ECA_PRESET_MAP::registered_objects(void) const
91
return(preset_keywords_rep);
94
bool ECA_PRESET_MAP::has_keyword(const std::string& keyword) const
96
if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), keyword) == preset_keywords_rep.end())
102
const ECA_OBJECT* ECA_PRESET_MAP::object_expr(const string& expr) const
104
if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), expr) != preset_keywords_rep.end()) {
105
return(object(expr));
110
const ECA_OBJECT* ECA_PRESET_MAP::object(const string& keyword) const
112
const PRESET* retobj = 0;
114
#ifndef ECA_DISABLE_EFFECTS
115
if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), keyword) != preset_keywords_rep.end()) {
116
const list<string>& objlist = ECA_OBJECT_MAP::registered_objects();
118
if (find(objlist.begin(), objlist.end(), keyword) == objlist.end()) {
120
PRESET* obj = dynamic_cast<PRESET*>(new GLOBAL_PRESET(keyword));
122
const_cast<ECA_PRESET_MAP*>(this)->register_object(keyword, "^" + keyword + "$", obj);
124
// std::cerr << "(eca-preset-map) registering obj; " << keyword << ".\n";
126
// else std::cerr << "(eca-preset-map) fail (3); " << keyword << ".\n";
129
catch(...) { retobj = 0; }
131
DBC_CHECK(find(objlist.begin(), objlist.end(), keyword) != objlist.end() || retobj == 0);
134
retobj = dynamic_cast<const PRESET*>(ECA_OBJECT_MAP::object(keyword));
135
// if (retobj == 0) std::cerr << "(eca-preset-map) fail (2); " << keyword << ".\n";
138
// else std::cerr << "(eca-preset-map) fail (1); " << keyword << ".\n";