File: eca-preset-map.cpp

package info (click to toggle)
ecasound 2.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 6,292 kB
  • sloc: cpp: 39,475; sh: 4,335; lisp: 1,918; ansic: 1,883; makefile: 888; python: 617; ruby: 202
file content (142 lines) | stat: -rw-r--r-- 4,318 bytes parent folder | download | duplicates (9)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
// ------------------------------------------------------------------------
// eca-preset-map: Dynamic register for storing effect presets
// Copyright (C) 2000-2003 Kai Vehmanen
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// 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 for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
// ------------------------------------------------------------------------

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <algorithm>
#include <list>
#include <vector>
#include <string>

#include <kvu_dbc.h>

#include "eca-object.h"
#include "eca-resources.h"
#include "eca-preset-map.h"
#include "global-preset.h"

using std::find;
using std::list;
using std::map;
using std::string;
using std::vector;

ECA_PRESET_MAP::ECA_PRESET_MAP(void)
{
#ifndef ECA_DISABLE_EFFECTS
  ECA_RESOURCES ecarc;

  string filename =
    ecarc.resource("user-resource-directory") + "/" + ecarc.resource("resource-file-effect-presets");

  string global_filename =
    ecarc.resource("resource-directory") + "/" + ecarc.resource("resource-file-effect-presets");

  load_preset_file(global_filename);
  load_preset_file(filename);
#endif
}

ECA_PRESET_MAP::~ECA_PRESET_MAP(void)
{
}

void ECA_PRESET_MAP::load_preset_file(const string& fname)
{
  RESOURCE_FILE preset_file;
  preset_file.resource_file(fname);
  preset_file.load();
  const vector<string>& pmap = preset_file.keywords();
  vector<string>::const_iterator p = pmap.begin();
  while(p != pmap.end()) {
    if (*p != "") preset_keywords_rep.push_back(*p);
    ++p;
  }
}

void ECA_PRESET_MAP::register_object(const string& keyword, const string& matchstr, ECA_OBJECT* object)
{
  if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), keyword) == preset_keywords_rep.end())
    preset_keywords_rep.push_back(keyword);

  ECA_OBJECT_MAP::register_object(keyword, matchstr, object);
}

void ECA_PRESET_MAP::unregister_object(const string& keyword)
{
  preset_keywords_rep.remove(keyword);
  ECA_OBJECT_MAP::unregister_object(keyword);
}

const list<string>& ECA_PRESET_MAP::registered_objects(void) const
{
  return(preset_keywords_rep);
}

bool ECA_PRESET_MAP::has_keyword(const std::string& keyword) const
{
  if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), keyword) == preset_keywords_rep.end())
    return(false);

  return (true);
}

const ECA_OBJECT* ECA_PRESET_MAP::object_expr(const string& expr) const
{
  if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), expr) != preset_keywords_rep.end()) {
    return(object(expr));
  }
  return(0);
}

const ECA_OBJECT* ECA_PRESET_MAP::object(const string& keyword) const
{
  const PRESET* retobj = 0;

#ifndef ECA_DISABLE_EFFECTS
  if (find(preset_keywords_rep.begin(), preset_keywords_rep.end(), keyword) != preset_keywords_rep.end()) {
    const list<string>& objlist = ECA_OBJECT_MAP::registered_objects();

    if (find(objlist.begin(), objlist.end(), keyword) == objlist.end()) {
      try {
	PRESET* obj = dynamic_cast<PRESET*>(new GLOBAL_PRESET(keyword));
	if (obj != 0) {
	  const_cast<ECA_PRESET_MAP*>(this)->register_object(keyword, "^" + keyword + "$", obj);
	  retobj = obj;
	  //  std::cerr << "(eca-preset-map) registering obj; " << keyword << ".\n";
	}
	//  else std::cerr << "(eca-preset-map) fail (3); " << keyword << ".\n";

      }
      catch(...) { retobj = 0; }

      DBC_CHECK(find(objlist.begin(), objlist.end(), keyword) != objlist.end() || retobj == 0);
    }
    else {
      retobj = dynamic_cast<const PRESET*>(ECA_OBJECT_MAP::object(keyword));
      //  if (retobj == 0) std::cerr << "(eca-preset-map) fail (2); " << keyword << ".\n";
    }
  }
  //  else std::cerr << "(eca-preset-map) fail (1); " << keyword << ".\n";
#endif

  return(retobj);
}