Yet Another Synthesizer Engine
 
Loading...
Searching...
No Matches
module.hh
1//
2// YASE Module Header
3//
4// Copyright (C) 2022 Eric Klavins
5// This file is part of YASE
6//
7// YASE is free software: you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the Free Software
9// Foundation, either version 3 of the License, or (at your option) any later
10// version.
11//
12// YASE is distributed in the hope that it will be useful, but WITHOUT ANY
13// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15// details.
16//
17// You should have received a copy of the GNU General Public License along
18// with YASE. If not, see <https://www.gnu.org/licenses/>.
19//
20
21#ifndef YASE_MODULE_H
22#define YASE_MODULE_H
23
24#include <string>
25#include <map>
26#include <vector>
27
28#include "event.hh"
29
30namespace yase {
31
32 using std::string;
33 using std::map;
34 using std::vector;
35
37
39 class Module {
40
41 friend class Synthesizer;
42 friend class EventManager;
43
44 public:
45
46 Module();
47 virtual ~Module() = default;
48
53 virtual void init() = 0;
54
58 virtual void update() = 0;
59
60 int add_input(string name);
61 int add_output(string name); // adds a new output
62 int get_input_index(string name) const;
63 string get_input_name(int index) const;
64 string get_output_name(int index) const;
65 int get_output_index(string name) const; // get the output index corresponding to the name
66 void set_input(string name, double value);
67 void set_input(int index, double value);
68 double get_input(int index) const;
69 double get_input(string name) const;
70 double get_output(string name) const; // simular to inputs
71 double get_output(int index) const;
72 void set_output(int index, double value);
73 void copy_inputs(const Module &source);
74 void copy_outputs(Module &destination) const;
75
76 void configure(std::vector<std::tuple<string,double>> assignments); // do a bunch of set_inputs
77
78 inline int num_inputs() const { return input_map.size(); }
79 inline int num_outputs() const { return output_map.size(); }
80
81 void emit(Event e);
82
83 inline void set_ts(double s) { ts = s; }
84 inline double get_ts() { return ts; }
85
86 protected:
87
88 map<string,int> input_map, // relates input names to their indices
89 output_map; // relates output names to their indices
90
91 vector<double> inputs, // values of the inputs
92 outputs; // values of the outputs
93
94 vector<Event> events;
95
96 double ts;
97
98 };
99
100}
101
102#endif
A class that keeps track of event listeners.
Definition event_manager.hh:42
An abstract base class for modules.
Definition module.hh:39
void emit(Event e)
Definition module.cc:204
string get_input_name(int index) const
Definition module.cc:176
string get_output_name(int index) const
Definition module.cc:190
virtual void init()=0
int add_output(string name)
Definition module.cc:44
void copy_inputs(const Module &source)
Definition module.cc:151
int get_output_index(string name) const
Definition module.cc:74
int add_input(string name)
Definition module.cc:33
virtual void update()=0
double get_output(string name) const
Definition module.cc:114
int get_input_index(string name) const
Definition module.cc:55
double get_input(int index) const
Definition module.cc:134
void copy_outputs(Module &destination) const
Definition module.cc:168
void set_output(int index, double value)
Definition module.cc:160
void set_input(string name, double value)
Definition module.cc:86
Definition additive_saw.cc:24