Klang C++ 0.7.15
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Stereo::Synth::Notes

Synthesiser note array (stereo) More...

#include <klang.h>

+ Inheritance diagram for klang::Stereo::Synth::Notes:

Public Types

typedef Array< Note *, 128 > Array
 

Public Member Functions

void add (int count)
 
void add (const Note *&item)
 Add the specified item to the end of the array.
 
Note ** add ()
 Add a blank item to the end of the array, returning a pointer that allows the item to be modified.
 
int assign ()
 
unsigned int size () const
 The current number of items in the array.
 
void clear ()
 Clear the array contents. Only resets the item count, without wiping memory.
 
float max () const
 Find the maximum value in the array.
 
float mean () const
 Find the mean average of values in the array.
 
float rms () const
 Find the root mean squared (RMS) average of values in the array.
 
void normalise (float target=1.f, int mode=Peak)
 Normalises values in the array to the specified target, based on peak, mean, or RMS value;.
 
Note *& operator[] (int index)
 Returns a reference to the array item at the given index.
 
const Note *& operator[] (int index) const
 Returns a read-only reference to the array item at the given index.
 

Static Public Member Functions

static int capacity ()
 The maximum capacity of the array.
 

Public Attributes

Synth * synth
 
unsigned int noteOns
 
unsigned int noteStart [128]
 
unsigned int count
 
Note * items [CAPACITY]
 

Detailed Description

Definition at line 6149 of file klang.h.

Member Typedef Documentation

◆ Array

Array<Note*, 128> klang::Notes< Synth, Note >::Array
inherited

Definition at line 5656 of file klang.h.

Member Function Documentation

◆ add() [1/3]

Note * * klang::Array< Note *, CAPACITY >::add ( )
inlineinherited

Definition at line 324 of file klang.h.

324 {
325 if (count < CAPACITY)
326 return &items[count++];
327 return nullptr;
328 }
Note * items[CAPACITY]
Definition klang.h:309

◆ add() [2/3]

void klang::Array< Note *, CAPACITY >::add ( const Note * & item)
inlineinherited

Definition at line 318 of file klang.h.

318 {
319 if (count < CAPACITY)
320 items[count++] = item;
321 }

◆ add() [3/3]

void klang::Notes< Synth, Note >::add ( int count)
inlineinherited

Definition at line 5667 of file klang.h.

5667 {
5668 for (int n = 0; n < count; n++) {
5669 TYPE* note = new TYPE();
5670 note->attach(synth);
5671 Array::add(note);
5672 }
5673 }
TYPE * add()
Add a blank item to the end of the array, returning a pointer that allows the item to be modified.
Definition klang.h:324

◆ assign()

int klang::Notes< Synth, Note >::assign ( )
inlineinherited

Definition at line 5679 of file klang.h.

5679 {
5680 // favour unused voices
5681 for (unsigned int i = 0; i < count; i++) {
5682 if (items[i]->stage == NOTE::Off) {
5683 noteStart[i] = noteOns++;
5684 return i;
5685 }
5686 }
5687
5688 // no free notes => steal oldest released note?
5689 int oldest = -1;
5690 unsigned int oldest_start = 0;
5691 for (unsigned int i = 0; i < count; i++) {
5692 if (items[i]->stage == NOTE::Release) {
5693 if (oldest == -1 || noteStart[i] < oldest_start) {
5694 oldest = i;
5695 oldest_start = noteStart[i];
5696 }
5697 }
5698 }
5699 if (oldest != -1) {
5700 noteStart[oldest] = noteOns++;
5701 return oldest;
5702 }
5703
5704 // no available released notes => steal oldest playing note
5705 oldest = -1;
5706 oldest_start = 0;
5707 for (unsigned int i = 0; i < count; i++) {
5708 if (oldest == -1 || noteStart[i] < oldest_start) {
5709 oldest = i;
5710 oldest_start = noteStart[i];
5711 }
5712 }
5713 noteStart[oldest] = noteOns++;
5714 return oldest;
5715 }
unsigned int noteStart[128]
Definition klang.h:5677

◆ capacity()

static int klang::Array< Note *, CAPACITY >::capacity ( )
inlinestaticinherited

Definition at line 312 of file klang.h.

312{ return CAPACITY; }

◆ clear()

void klang::Array< Note *, CAPACITY >::clear ( )
inlineinherited

Definition at line 331 of file klang.h.

331{ count = 0; }

◆ max()

float klang::Array< Note *, CAPACITY >::max ( ) const
inlineinherited

Definition at line 334 of file klang.h.

334 {
335 float max = 0.f;
336 for (unsigned int i = 0; i < count; i++)
337 if (abs(items[i]) > max)
338 max = items[i];
339 return max;
340 }

◆ mean()

float klang::Array< Note *, CAPACITY >::mean ( ) const
inlineinherited

Definition at line 343 of file klang.h.

343 {
344 float sum = 0.f;
345 for (unsigned int i = 0; i < count; i++)
346 sum += abs(items[i]);
347 return sum / count;
348 }

◆ normalise()

void klang::Array< Note *, CAPACITY >::normalise ( float target = 1.f,
int mode = Peak )
inlineinherited

Definition at line 359 of file klang.h.

359 {
360 if (!count) return;
361
362 const float current = (mode == Peak) ? max() : (mode == Mean) ? mean() : rms();
363 const float scale = current == 0.f ? 0.f : target / current;
364 for (int i = 0; i < count; i++)
365 items[i] *= scale;
366 }
@ Peak
Definition klang.h:149
@ Mean
Definition klang.h:149

◆ operator[]() [1/2]

Note * & klang::Array< Note *, CAPACITY >::operator[] ( int index)
inlineinherited

Definition at line 369 of file klang.h.

369{ return items[index]; }

◆ operator[]() [2/2]

const Note * & klang::Array< Note *, CAPACITY >::operator[] ( int index) const
inlineinherited

Definition at line 372 of file klang.h.

372{ return items[index]; }

◆ rms()

float klang::Array< Note *, CAPACITY >::rms ( ) const
inlineinherited

Definition at line 351 of file klang.h.

351 {
352 float sum = 0.f;
353 for (unsigned int i = 0; i < count; i++)
354 sum += items[i] * items[i];
355 return sqrt(sum / count);
356 }

◆ size()

unsigned int klang::Array< Note *, CAPACITY >::size ( ) const
inlineinherited

Definition at line 315 of file klang.h.

315{ return count; }

Member Data Documentation

◆ count

unsigned int klang::Array< Note *, CAPACITY >::count
inherited

Definition at line 308 of file klang.h.

◆ items

Note * klang::Array< Note *, CAPACITY >::items[CAPACITY]
inherited

Definition at line 309 of file klang.h.

◆ noteOns

unsigned int klang::Notes< Synth, Note >::noteOns
inherited

Definition at line 5676 of file klang.h.

◆ noteStart

unsigned int klang::Notes< Synth, Note >::noteStart[128]
inherited

Definition at line 5677 of file klang.h.

5677{ 0 }; // track age of notes (for note stealing)

◆ synth

Synth* klang::Notes< Synth, Note >::synth
inherited

Definition at line 5655 of file klang.h.