Workbench Library  0.1b
workbench.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 // clang-format off
7 #include "portaudio.h"
8 #include "portmidi.h"
9 #include "porttime.h"
10 #include "workbench_logger.h"
11 #include "workbench_config.h"
12 #include "workbench_audio.h"
13 #include "workbench_midi.h"
14 #include <stdbool.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 // clang-format on
18 
42 
68 typedef void (*AudioCallback)(const void *, void *, unsigned long, void *);
69 
81 void audio_init();
82 
90 void audio_deinit();
91 
134 typedef int (*MidiCallback)(const void *, void *, unsigned long, void *);
135 
147 void midi_init();
148 
156 void midi_deinit();
157 
170 void __midi_callback(int32_t timestamp, void *userData);
183 #define DEFAULT_IN_CHANNELS_COUNT \
184  1
185 #define DEFAULT_OUT_CHANNELS_COUNT \
186  2
199 #define FLAGS(FLAG) \
200  FLAG(DISABLE_MIDI) \
201  FLAG(DISABLE_AUDIO) \
202  FLAG(DISABLE_MIDI_IN) \
203  FLAG(DISABLE_MIDI_OUT) \
204  FLAG(DISABLE_AUDIO_IN) \
205  FLAG(DISABLE_AUDIO_OUT)
206 
211 
216 
248 #define CONFIG(FIELD) \
249  FIELD(char *, midi_input, NULL) \
250  FIELD(char *, midi_output, NULL) \
251  FIELD(int, midi_output_latecncy, 0) \
252  FIELD(int, midi_buffer_size, 1024) \
253  FIELD(char *, audio_input, NULL) \
254  FIELD(char *, audio_output, NULL) \
255  FIELD(double, sample_rate, 44100.0) \
256  FIELD(uint32_t, block_size, 512U) \
257  FIELD(uint32_t, audio_flags, 0U) \
258  FIELD(int, in_channel_count, DEFAULT_IN_CHANNELS_COUNT) \
259  FIELD(int, out_channel_count, DEFAULT_OUT_CHANNELS_COUNT) \
260  FIELD(double, suggested_latency, -1.0) \
261  FIELD(uint32_t, flags, 0U) \
262  FIELD(uint8_t, log_level, 4)
263 
287 typedef struct {
290  void *user_data;
292 } Config;
293 
303 Config *config_init(int argc, char **argv, AudioCallback audio_cb,
304  MidiCallback midi_cb, void *user_data);
305 
306 void config_deinit();
307 
311 void config_print();
312 
318 Config *config_get();
319 
321 
322 
335 uint8_t get_log_level();
336 
void audio_init()
Initializes the audio system.
Definition: workbench_audio.c:66
void audio_deinit()
Deinitializes the audio system.
Definition: workbench_audio.c:109
void(* AudioCallback)(const void *, void *, unsigned long, void *)
Type definition for audio callback functions.
Definition: workbench.h:68
SAMPLE AudioSample_t
Defines AudioSample_t as the type for audio samples.
Definition: workbench.h:41
Config * config_init(int argc, char **argv, AudioCallback audio_cb, MidiCallback midi_cb, void *user_data)
Initializes the configuration with the specified audio and MIDI callbacks.
Definition: workbench_config.c:41
#define CONFIG(FIELD)
Defines configuration fields and their default values using the X-macro technique.
Definition: workbench.h:248
Config * config_get()
Retrieves the current configuration.
Definition: workbench_config.c:33
flag_bits
Enumeration of flag bits for feature flags.
Definition: workbench.h:210
void config_print()
Prints the current configuration settings to the standard output.
Definition: workbench_config.c:220
uint8_t get_log_level()
Retrieves the log level.
Definition: workbench_config.c:34
flags
Enumeration of feature flags.
Definition: workbench.h:215
#define FLAGS(FLAG)
Defines a list of feature flags and their bitwise representations.
Definition: workbench.h:199
void midi_deinit()
Deinitializes the MIDI system.
Definition: workbench_midi.c:86
void midi_init()
Initializes the MIDI system.
Definition: workbench_midi.c:41
int(* MidiCallback)(const void *, void *, unsigned long, void *)
Type definition for MIDI callback functions.
Definition: workbench.h:134
Defines the structure for configuration settings.
Definition: workbench.h:287
AudioCallback audio_callback
Definition: workbench.h:288
void * user_data
Definition: workbench.h:290
MidiCallback midi_callback
Definition: workbench.h:289
#define WORKBENCH_FLAG_ENUMERATE(FLAG)
Enumerates flag bits.
Definition: workbench_config.h:143
Audio system configuration for Workbench applications.
#define SAMPLE
Defines the type for audio samples based on SAMPLE_FORMAT.
Definition: workbench_audio.h:35
Configuration settings and macros for Workbench audio and MIDI applications.
#define WORKBENCH_CONFIG_DEFINE_STRUCT(type, field, default)
Macro to define a field in the configuration structure.
Definition: workbench_config.h:26
#define WORKBENCH_CONFIG_DEFINE_SETTERS(type, field, default)
Macro to define setter function declarations for configuration fields.
Definition: workbench_config.h:59
#define WORKBENCH_FLAG_DEFINE(FLAG)
Defines actual values for feature flags.
Definition: workbench_config.h:132
A logging utility for C programs with configurable verbosity levels and optional context information.
MIDI message constants for Workbench applications.