tentative bw_note_queue + beginning of bw_voice(_alloc)
This commit is contained in:
parent
c3dff38987
commit
ee4fa3c9f2
129
include/bw_note_queue.h
Normal file
129
include/bw_note_queue.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Brickworks
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Orastron Srl unipersonale
|
||||||
|
*
|
||||||
|
* Brickworks is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* Brickworks is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* File author: Stefano D'Angelo
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* module_type {{{ utility }}}
|
||||||
|
* version {{{ 0.5.0 }}}
|
||||||
|
* requires {{{ }}}
|
||||||
|
* description {{{
|
||||||
|
* Note queue.
|
||||||
|
*
|
||||||
|
* ...
|
||||||
|
* }}}
|
||||||
|
* changelog {{{
|
||||||
|
* <ul>
|
||||||
|
* <li>Version <strong>0.5.0</strong>:
|
||||||
|
* <ul>
|
||||||
|
* <li>First release.</li>
|
||||||
|
* </ul>
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
* }}}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BW_NOTE_QUEUE_H
|
||||||
|
#define _BW_NOTE_QUEUE_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! api {{{
|
||||||
|
* #### bw_note_queue_status
|
||||||
|
* ```>>> */
|
||||||
|
struct _bw_note_queue_status {
|
||||||
|
char pressed;
|
||||||
|
float velocity;
|
||||||
|
};
|
||||||
|
typedef struct _bw_note_queue_status bw_note_queue_status;
|
||||||
|
/*! <<<```
|
||||||
|
* #### bw_note_queue_event
|
||||||
|
* ```>>> */
|
||||||
|
struct _bw_note_queue_event {
|
||||||
|
unsigned char note;
|
||||||
|
bw_note_queue_status status;
|
||||||
|
char went_off;
|
||||||
|
};
|
||||||
|
typedef struct _bw_note_queue_event bw_note_queue_event;
|
||||||
|
/*! <<<```
|
||||||
|
* #### bw_note_queue
|
||||||
|
* ```>>> */
|
||||||
|
struct _bw_note_queue {
|
||||||
|
bw_note_queue_event events[128];
|
||||||
|
unsigned char n_events;
|
||||||
|
bw_note_queue_status status[128];
|
||||||
|
unsigned char n_pressed;
|
||||||
|
};
|
||||||
|
typedef struct _bw_note_queue bw_note_queue;
|
||||||
|
/*! <<<```
|
||||||
|
* #### bw_note_queue_reset()
|
||||||
|
* ```>>> */
|
||||||
|
static inline void bw_note_queue_reset(bw_note_queue *queue);
|
||||||
|
/*! <<<```
|
||||||
|
* #### bw_note_queue_clear()
|
||||||
|
* ```>>> */
|
||||||
|
static inline void bw_note_queue_clear(bw_note_queue *queue);
|
||||||
|
/*! <<<```
|
||||||
|
* #### bw_note_queue_add()
|
||||||
|
* ```>>> */
|
||||||
|
static inline void bw_note_queue_add(bw_note_queue *queue, unsigned char note, char pressed, float velocity, char force_went_off);
|
||||||
|
|
||||||
|
/*** Implementation ***/
|
||||||
|
|
||||||
|
/* WARNING: This part of the file is not part of the public API. Its content may
|
||||||
|
* change at any time in future versions. Please, do not use it directly. */
|
||||||
|
|
||||||
|
static inline void bw_note_queue_reset(bw_note_queue *queue) {
|
||||||
|
for (char i = 0; i < 128; i++)
|
||||||
|
queue->status[i] = { 0, 0.f };
|
||||||
|
queue->n_pressed = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bw_note_queue_clear(bw_note_queue *queue) {
|
||||||
|
queue->n_events = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bw_note_queue_add(bw_note_queue *queue, unsigned char note, char pressed, float velocity, char force_went_off) {
|
||||||
|
if (!pressed && !queue->status[note].pressed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned char i;
|
||||||
|
for (i = 0; i < queue->n_events; i++)
|
||||||
|
if (queue->events[i].note == note)
|
||||||
|
break;
|
||||||
|
char went_off = 0;
|
||||||
|
if (i == queue->n_events)
|
||||||
|
queue->n_events++;
|
||||||
|
else
|
||||||
|
went_off = queue->events[i].went_off || queue->events[i].velocity <= 0.f;
|
||||||
|
|
||||||
|
queue->events[i] = { note, { pressed, velocity }, went_off || force_went_off };
|
||||||
|
if (pressed && !queue->status[note].pressed)
|
||||||
|
queue->n_pressed++;
|
||||||
|
else if (!pressed && queue->status[note].pressed)
|
||||||
|
queue->n_pressed--;
|
||||||
|
queue->status[note] = { pressed, velocity };
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
23
include/bw_voice.h
Normal file
23
include/bw_voice.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Brickworks
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Orastron Srl unipersonale
|
||||||
|
*
|
||||||
|
* Brickworks is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* Brickworks is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* File author: Stefano D'Angelo
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct _bw_voice {
|
||||||
|
};
|
||||||
|
typedef struct _bw_voice bw_voice;
|
47
include/bw_voice_alloc.h
Normal file
47
include/bw_voice_alloc.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Brickworks
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 Orastron Srl unipersonale
|
||||||
|
*
|
||||||
|
* Brickworks is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* Brickworks is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Brickworks. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* File author: Stefano D'Angelo
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <bw_note_queue.h>
|
||||||
|
#include <bw_voice.h>
|
||||||
|
|
||||||
|
typedef struct _bw_voice_alloc bw_voice_alloc;
|
||||||
|
|
||||||
|
void bw_voice_alloc_reset(bw_voice_alloc *voice_alloc);
|
||||||
|
|
||||||
|
void bw_voice_alloc_process(bw_voice_alloc *voice_alloc, bw_note_queue *queue);
|
||||||
|
|
||||||
|
void bw_voice_alloc_set_unison(bw_voice_alloc *voice_alloc, char value);
|
||||||
|
|
||||||
|
struct _bw_voice_alloc {
|
||||||
|
bw_voice *voices;
|
||||||
|
int n_voices;
|
||||||
|
|
||||||
|
char unison;
|
||||||
|
};
|
||||||
|
|
||||||
|
void bw_voice_alloc_reset(bw_voice_alloc *voice_alloc) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void bw_voice_alloc_process(bw_voice_alloc *voice_alloc, bw_note_queue *queue) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void bw_voice_alloc_set_unison(bw_voice_alloc *voice_alloc, char value) {
|
||||||
|
voice_alloc->unison = value;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user