-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.cpp
More file actions
99 lines (81 loc) · 1.77 KB
/
model.cpp
File metadata and controls
99 lines (81 loc) · 1.77 KB
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
/*
* model.cpp
*
* Created on: 25 dec. 2017
* Author: MisterCavespider
*/
#include "model.h"
static uint8_t moduleCount = 0;
static uint8_t connectionCount = 0;
static uint8_t mSize = 0;
static Module **modules;
static AudioStream **streams;
static AudioConnection **connections;
void allocateForModules(uint8_t size)
{
modules = new Module*[size];
streams = new AudioStream*[size];
connections = new AudioConnection*[2*size]; // Average of 2 unique connections per module
mSize = size;
}
void addModule(Module *module)
{
modules[moduleCount] = module;
moduleCount++;
}
Module *putModule(Module *module)
{
modules[module->id()] = module;
return module;
}
Module *getModule(int index)
{
if(index > mSize) return NULL;
return modules[index];
}
/*
* It cannot be assumed that all the modules
* are in order, because of the putModule function.
*
* Just run the tree.
*/
void bakeModules()
{
// Clean the array
for(int i = 0; i < mSize; i++)
{
streams[i] = NULL; // Set all pointers to null
}
Module *starter = getModule(0); // TODO: Risky
starter->createAudio(streams[starter->id()]);
}
void bakeModule(Module *m)
{
// Create audio
m->createAudio(streams[m->id()]);
// Connect
for(int i = 0; i < m->outputCount() * m->paralsCount(); i++)
{
Module *t = getModule(m->outputs()[i]);
if(t->inputCount() > 0 && containsInput(t, m->id()) && connectionCount < mSize*2) // Mutually recognised
{
if(streams[t->id()]) // Init?
{
bakeModule(t);
}
connections[connectionCount] = new AudioConnection(*streams[m->id()], 0, *streams[t->id()], 0);
}
}
}
bool containsInput(Module *m, uint8_t input)
{
for(int i = 0; i < m->inputCount(); i++)
{
if(m->inputs()[i] == input) return true;
}
return false;
}
uint8_t getSize()
{
return mSize;
}