Yet Another Synthesizer Engine
 
Loading...
Searching...
No Matches
container.hh
1//
2// YASE Container 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_CONTAINER_H
22#define YASE_CONTAINER_H
23
24#include <string>
25#include <map>
26#include <vector>
27#include <tuple>
28#include <typeinfo>
29#include <algorithm>
30#include <thread>
31#include <list>
32
33#include "module.hh"
34#include "event.hh"
35#include "fader.hh"
36#include "buttons.hh"
37#include "auto_load.hh"
38
39namespace yase {
40
41 using std::string;
42 using std::vector;
43 using std::tuple;
44 using std::function;
45 using std::map;
46
47 typedef tuple<Module &, int, Module &, int> Wire;
48 typedef tuple<int, Module &, int> Equate;
49
51
63 class Container : public Module, public EventManager {
64
65 public:
66
67 Container();
68 void init();
69 void update();
70 Container &add(Module &module);
71 Container &add_if_new(Module &module);
73 void run(int num_steps);
74 void run_again(int num_steps);
75 void stop();
76
77 // Connectivity
78 Container &connect(Module &source, string output, Module &dest, string input);
79 Container &connect(Module &source, string output, Module &dest, int input);
80 Container &connect(AutoLoad& loader, string category, Module& module);
81
82 Container &connect(Module &source, Module &dest); // assumes signal name is "signal"
83 Container &path(Module &a, Module &b, Module &c);
84 Container &path(Module &a, Module &b, Module &c, Module &d);
85 Container &path(Module &a, Module &b, Module &c, Module &d, Module &e);
86
87 Container &disconnect(Module &source, string output, Module &dest, string input);
88
89 bool connected(Module * module, string input_name); // test whether the in put to module is connected to another module
90
91 // I/O Identifications
92 Container &equate_input(string input, Module &sub_module, string sub_input);
93 Container &attach_inputs(std::vector<std::tuple<string,Module&,string>> attachments);
94 Container &equate_output(string output, Module &sub_module, string sub_output);
95 Container &attach_outputs(std::vector<std::tuple<string,Module&,string>> attachments);
96
97 // Multithreading interface
99 Container &add(Module &module, int n);
100 void run_threaded(int num_steps);
101 void update_threaded();
102 void thread_loop(int i);
103
104 private:
105
106 vector<Module *> modules;
107 vector<Wire> wires;
108 vector<Equate> input_equates, output_equates;
109
110 // Thread groups
111 vector<std::thread> threads;
112 vector<vector<Module *> > groups;
113 vector<bool> working_flags;
114 std::mutex mtx;
115
116 };
117}
118
119#endif
A parameter auto-loader that continually reloads a *.json file.
Definition auto_load.hh:36
A module and event manager that can contain other modules.
Definition container.hh:63
Container & propagate_to(EventManager &em)
Definition container.cc:95
Container & equate_input(string input, Module &sub_module, string sub_input)
Definition container.cc:236
Container & path(Module &a, Module &b, Module &c)
Definition container.cc:195
Container & connect(Module &source, string output, Module &dest, string input)
Definition container.cc:111
bool connected(Module *module, string input_name)
Definition container.cc:335
void thread_loop(int i)
EXPERIMENTAL.
Definition container.cc:432
void init()
Definition container.cc:323
void run_again(int num_steps)
Definition container.cc:391
Container & add_if_new(Module &module)
Definition container.cc:70
void run_threaded(int num_steps)
EXPERIMENTAL.
Definition container.cc:454
void run(int num_steps)
Definition container.cc:374
void update_threaded()
EXPERIMENTAL.
Definition container.cc:481
Container & equate_output(string output, Module &sub_module, string sub_output)
Definition container.cc:284
Container & attach_inputs(std::vector< std::tuple< string, Module &, string > > attachments)
Definition container.cc:254
Container & set_thread_number(int n)
EXPERIMENTAL.
Definition container.cc:406
Container & add(Module &module)
Definition container.cc:62
Container & attach_outputs(std::vector< std::tuple< string, Module &, string > > attachments)
Definition container.cc:268
Container & disconnect(Module &source, string output, Module &dest, string input)
Definition container.cc:303
void update()
Definition container.cc:344
A class that keeps track of event listeners.
Definition event_manager.hh:42
An abstract base class for modules.
Definition module.hh:39
Definition additive_saw.cc:24