LMMS
Loading...
Searching...
No Matches
NotePool.h
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 NotePool.h - Pool of Synthesizer Engines And Note Instances
5 Copyright (C) 2016 Mark McCurry
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11*/
12#pragma once
13#include <stdint.h>
14#include <functional>
15#include "../globals.h"
16
17//Expected upper bound of synths given that max polyphony is hit
18#define EXPECTED_USAGE 3
19
20namespace zyncarla {
21
22struct LegatoParams;
24{
25 public:
26 typedef uint8_t note_t;
27 //Currently this wastes a ton of bits due ot the legatoMirror flag
29 //acceptable overlap after 2 minutes
30 //run time at 48kHz 8 samples per buffer
31 //19 bit minimum
35 //max of 16 kit elms and 3 kit items per
40
41 //status checks
42 bool playing(void) const;
43 bool off(void) const;
44 bool sustained(void) const;
45 bool released(void) const;
46
47 //status transitions
48 void setStatus(uint8_t s);
49 void doSustain(void);
50
51 bool canSustain(void) const;
52 void makeUnsustainable(void);
53 };
54
55 //To be pedantic this wastes 2 or 6 bytes per descriptor
56 //depending on 32bit/64bit alignment rules
62
63
64 //Pool of notes
68
69
70 //Iterators
77
80 {
81 int off=0;
82 for(int i=0; i<POLYPHONY; ++i, ++off)
83 if(np.ndesc[i].status == 0)
84 break;
85 _end = np.ndesc+off;
86 }
87 NoteDescriptor *begin() {return np.ndesc;};
88 NoteDescriptor *end() { return _end; };
91 };
92
95 {
96 int off=0;
97 for(int i=0; i<POLYPHONY; ++i, ++off)
98 if(np.ndesc[i].status == 0)
99 break;
100 _end = np.ndesc+off;
101 }
102 const NoteDescriptor *begin() const {return np.ndesc;};
103 const NoteDescriptor *end() const { return _end; };
105 const NotePool &np;
106 };
107
109
112
113 //Counts of descriptors used for tests
114 int usedNoteDesc(void) const;
115 int usedSynthDesc(void) const;
116
117 NotePool(void);
118
119 //Operations
120 void insertNote(uint8_t note, uint8_t sendto, SynthDescriptor desc, bool legato=false);
121 void insertLegatoNote(uint8_t note, uint8_t sendto, SynthDescriptor desc);
122
123 void upgradeToLegato(void);
124 void applyLegato(LegatoParams &par);
125
126 void makeUnsustainable(uint8_t note);
127
128 bool full(void) const;
129 bool synthFull(int sdesc_count) const;
130
131 //Note that isn't KEY_PLAYING or KEY_RELASED_AND_SUSTAINING
132 bool existsRunningNote(void) const;
133 int getRunningNotes(void) const;
134 void enforceKeyLimit(int limit);
135
136 void releasePlayingNotes(void);
137 void releaseNote(note_t note);
138 void release(NoteDescriptor &d);
139
140 void killAllNotes(void);
141 void killNote(note_t note);
142 void kill(NoteDescriptor &d);
143 void kill(SynthDescriptor &s);
144 void entomb(NoteDescriptor &d);
145
146 void cleanup(void);
147
148 void dump(void);
149};
150
151}
#define POLYPHONY
Definition globals.h:114
#define EXPECTED_USAGE
Definition NotePool.h:18
void releaseNote(note_t note)
int usedSynthDesc(void) const
Definition NotePool.cpp:143
void insertLegatoNote(uint8_t note, uint8_t sendto, SynthDescriptor desc)
Definition NotePool.cpp:184
void enforceKeyLimit(int limit)
Definition NotePool.cpp:259
void applyLegato(LegatoParams &par)
Definition NotePool.cpp:196
SynthDescriptor sdesc[POLYPHONY *EXPECTED_USAGE]
Definition NotePool.h:66
void killNote(note_t note)
Definition NotePool.cpp:316
bool existsRunningNote(void) const
Definition NotePool.cpp:238
bool full(void) const
Definition NotePool.cpp:220
void insertNote(uint8_t note, uint8_t sendto, SynthDescriptor desc, bool legato=false)
Definition NotePool.cpp:154
int getRunningNotes(void) const
Definition NotePool.cpp:244
void entomb(NoteDescriptor &d)
Definition NotePool.cpp:338
NotePool(void)
Definition NotePool.cpp:32
NoteDescriptor ndesc[POLYPHONY]
Definition NotePool.h:65
void dump(void)
Definition NotePool.cpp:416
int usedNoteDesc(void) const
Definition NotePool.cpp:132
void kill(NoteDescriptor &d)
Definition NotePool.cpp:324
activeNotesIter activeNotes(NoteDescriptor &n)
Definition NotePool.cpp:80
uint8_t note_t
Definition NotePool.h:26
void cleanup(void)
Definition NotePool.cpp:357
bool synthFull(int sdesc_count) const
Definition NotePool.cpp:228
bool needs_cleaning
Definition NotePool.h:67
void upgradeToLegato(void)
Definition NotePool.cpp:176
void releasePlayingNotes(void)
Definition NotePool.cpp:292
void killAllNotes(void)
Definition NotePool.cpp:310
void release(NoteDescriptor &d)
Definition NotePool.cpp:303
activeDescIter activeDesc(void)
Definition NotePool.cpp:120
void makeUnsustainable(uint8_t note)
Definition NotePool.cpp:209
Definition SynthNote.h:44
unsigned d
Definition inflate.c:940
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
unsigned int uint32_t
Definition mid.cpp:100
unsigned char uint8_t
Definition mid.cpp:98
Definition zynaddsubfx-src.cpp:569
T limit(T val, T min, T max)
Definition Util.h:85
Definition SynthNote.h:35
Definition NotePool.h:28
bool off(void) const
Definition NotePool.cpp:54
uint32_t age
Definition NotePool.h:32
bool operator==(NoteDescriptor)
Definition NotePool.cpp:90
bool released(void) const
Definition NotePool.cpp:49
uint8_t size
Definition NotePool.h:36
bool legatoMirror
Definition NotePool.h:38
void doSustain(void)
Definition NotePool.cpp:65
bool playing(void) const
Definition NotePool.cpp:39
bool canSustain(void) const
Definition NotePool.cpp:70
uint8_t status
Definition NotePool.h:37
void setStatus(uint8_t s)
Definition NotePool.cpp:59
void makeUnsustainable(void)
Definition NotePool.cpp:75
bool sustained(void) const
Definition NotePool.cpp:44
uint8_t note
Definition NotePool.h:33
uint8_t sendto
Definition NotePool.h:34
Definition NotePool.h:57
uint8_t kit
Definition NotePool.h:60
SynthNote * note
Definition NotePool.h:58
uint8_t type
Definition NotePool.h:59
Definition NotePool.h:78
NoteDescriptor * end()
Definition NotePool.h:88
NoteDescriptor * _end
Definition NotePool.h:89
NoteDescriptor * begin()
Definition NotePool.h:87
activeDescIter(NotePool &_np)
Definition NotePool.h:79
NotePool & np
Definition NotePool.h:90
Definition NotePool.h:71
SynthDescriptor * _b
Definition NotePool.h:74
SynthDescriptor * _e
Definition NotePool.h:75
SynthDescriptor * end()
Definition NotePool.h:73
SynthDescriptor * begin()
Definition NotePool.h:72
const NoteDescriptor * begin() const
Definition NotePool.h:102
const NoteDescriptor * _end
Definition NotePool.h:104
constActiveDescIter(const NotePool &_np)
Definition NotePool.h:94
const NotePool & np
Definition NotePool.h:105
const NoteDescriptor * end() const
Definition NotePool.h:103
int n
Definition crypt.c:458