clang-format in src/sound

This commit is contained in:
Jasmine Iwanek
2022-07-21 22:01:01 -04:00
parent 4723ee7912
commit 26c5b53ffd

View File

@@ -15,12 +15,12 @@
*/ */
#if defined __has_include #if defined __has_include
# if __has_include (<RtMidi.h>) # if __has_include(<RtMidi.h>)
# include <RtMidi.h> # include <RtMidi.h>
# endif # endif
# if __has_include (<rtmidi/RtMidi.h>) # if __has_include(<rtmidi/RtMidi.h>)
# include <rtmidi/RtMidi.h> # include <rtmidi/RtMidi.h>
# endif # endif
#endif #endif
#include <cstdint> #include <cstdint>
@@ -38,16 +38,15 @@ extern "C"
// Disable c99-designator to avoid the warnings in rtmidi_*_device // Disable c99-designator to avoid the warnings in rtmidi_*_device
#ifdef __clang__ #ifdef __clang__
#if __has_warning("-Wc99-designator") # if __has_warning("-Wc99-designator")
#pragma clang diagnostic ignored "-Wc99-designator" # pragma clang diagnostic ignored "-Wc99-designator"
#endif # endif
#endif #endif
static RtMidiOut * midiout = nullptr; static RtMidiOut *midiout = nullptr;
static RtMidiIn * midiin = nullptr; static RtMidiIn *midiin = nullptr;
static int midi_out_id = 0, midi_in_id = 0; static int midi_out_id = 0, midi_in_id = 0;
static const int midi_lengths[8] = {3, 3, 3, 3, 2, 2, 3, 1}; static const int midi_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 1 };
int int
rtmidi_write(uint8_t val) rtmidi_write(uint8_t val)
@@ -55,55 +54,53 @@ rtmidi_write(uint8_t val)
return 0; return 0;
} }
void void
rtmidi_play_msg(uint8_t *msg) rtmidi_play_msg(uint8_t *msg)
{ {
if (midiout) if (midiout)
midiout->sendMessage(msg, midi_lengths[(msg[0] >> 4) & 7]); midiout->sendMessage(msg, midi_lengths[(msg[0] >> 4) & 7]);
} }
void void
rtmidi_play_sysex(uint8_t *sysex, unsigned int len) rtmidi_play_sysex(uint8_t *sysex, unsigned int len)
{ {
if (midiout) if (midiout)
midiout->sendMessage(sysex, len); midiout->sendMessage(sysex, len);
} }
void* void*
rtmidi_output_init(const device_t *info) rtmidi_output_init(const device_t *info)
{ {
midi_device_t* dev = (midi_device_t*)malloc(sizeof(midi_device_t)); midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t));
dev->play_msg = rtmidi_play_msg; dev->play_msg = rtmidi_play_msg;
dev->play_sysex = rtmidi_play_sysex; dev->play_sysex = rtmidi_play_sysex;
dev->write = rtmidi_write; dev->write = rtmidi_write;
try { try {
if (!midiout) midiout = new RtMidiOut; if (!midiout)
} catch (RtMidiError& error) { midiout = new RtMidiOut;
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str()); } catch (RtMidiError &error) {
return nullptr;
}
midi_out_id = config_get_int((char*)SYSTEM_MIDI_NAME, (char*)"midi", 0);
try {
midiout->openPort(midi_out_id);
} catch (RtMidiError& error) {
pclog("Fallback to default MIDI output port: %s\n", error.getMessage().c_str());
try {
midiout->openPort(0);
} catch (RtMidiError& error) {
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
delete midiout;
midiout = nullptr;
return nullptr; return nullptr;
} }
midi_out_id = config_get_int((char *) SYSTEM_MIDI_NAME, (char *) "midi", 0);
try {
midiout->openPort(midi_out_id);
} catch (RtMidiError &error) {
pclog("Fallback to default MIDI output port: %s\n", error.getMessage().c_str());
try {
midiout->openPort(0);
} catch (RtMidiError &error) {
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
delete midiout;
midiout = nullptr;
return nullptr;
}
} }
midi_out_init(dev); midi_out_init(dev);
@@ -111,12 +108,11 @@ rtmidi_output_init(const device_t *info)
return dev; return dev;
} }
void void
rtmidi_output_close(void *p) rtmidi_output_close(void *p)
{ {
if (!midiout) if (!midiout)
return; return;
midiout->closePort(); midiout->closePort();
@@ -126,68 +122,64 @@ rtmidi_output_close(void *p)
midi_out_close(); midi_out_close();
} }
int int
rtmidi_out_get_num_devs(void) rtmidi_out_get_num_devs(void)
{ {
if (!midiout) { if (!midiout) {
try { try {
midiout = new RtMidiOut; midiout = new RtMidiOut;
} catch (RtMidiError& error) { } catch (RtMidiError &error) {
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
} }
} }
return midiout ? midiout->getPortCount() : 0; return midiout ? midiout->getPortCount() : 0;
} }
void void
rtmidi_out_get_dev_name(int num, char *s) rtmidi_out_get_dev_name(int num, char *s)
{ {
strcpy(s, midiout->getPortName(num).c_str()); strcpy(s, midiout->getPortName(num).c_str());
} }
void void
rtmidi_input_callback(double timeStamp, std::vector<unsigned char> *message, void *userData) rtmidi_input_callback(double timeStamp, std::vector<unsigned char> *message, void *userData)
{ {
if (message->front() == 0xF0) if (message->front() == 0xF0)
midi_in_sysex(message->data(), message->size()); midi_in_sysex(message->data(), message->size());
else else
midi_in_msg(message->data(), message->size()); midi_in_msg(message->data(), message->size());
} }
void* void*
rtmidi_input_init(const device_t *info) rtmidi_input_init(const device_t *info)
{ {
midi_device_t* dev = (midi_device_t*)malloc(sizeof(midi_device_t)); midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t));
try { try {
if (!midiin) if (!midiin)
midiin = new RtMidiIn; midiin = new RtMidiIn;
} catch (RtMidiError& error) { } catch (RtMidiError &error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
return nullptr;
}
midi_in_id = config_get_int((char*)MIDI_INPUT_NAME, (char*)"midi_input", 0);
try {
midiin->openPort(midi_in_id);
} catch (RtMidiError& error) {
pclog("Fallback to default MIDI input port: %s\n", error.getMessage().c_str());
try {
midiin->openPort(0);
} catch (RtMidiError& error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
delete midiin;
midiin = nullptr;
return nullptr; return nullptr;
} }
midi_in_id = config_get_int((char *) MIDI_INPUT_NAME, (char *) "midi_input", 0);
try {
midiin->openPort(midi_in_id);
} catch (RtMidiError &error) {
pclog("Fallback to default MIDI input port: %s\n", error.getMessage().c_str());
try {
midiin->openPort(0);
} catch (RtMidiError &error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
delete midiin;
midiin = nullptr;
return nullptr;
}
} }
midiin->setCallback(&rtmidi_input_callback); midiin->setCallback(&rtmidi_input_callback);
@@ -198,15 +190,14 @@ rtmidi_input_init(const device_t *info)
midi_in_init(dev, &midi_in); midi_in_init(dev, &midi_in);
midi_in->midi_realtime = device_get_config_int("realtime"); midi_in->midi_realtime = device_get_config_int("realtime");
midi_in->thruchan = device_get_config_int("thruchan"); midi_in->thruchan = device_get_config_int("thruchan");
midi_in->midi_clockout = device_get_config_int("clockout"); midi_in->midi_clockout = device_get_config_int("clockout");
return dev; return dev;
} }
void void
rtmidi_input_close(void* p) rtmidi_input_close(void *p)
{ {
midiin->cancelCallback(); midiin->cancelCallback();
midiin->closePort(); midiin->closePort();
@@ -217,22 +208,20 @@ rtmidi_input_close(void* p)
midi_out_close(); midi_out_close();
} }
int int
rtmidi_in_get_num_devs(void) rtmidi_in_get_num_devs(void)
{ {
if (!midiin) { if (!midiin) {
try { try {
midiin = new RtMidiIn; midiin = new RtMidiIn;
} catch (RtMidiError& error) { } catch (RtMidiError &error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
} }
} }
return midiin ? midiin->getPortCount() : 0; return midiin ? midiin->getPortCount() : 0;
} }
void void
rtmidi_in_get_dev_name(int num, char *s) rtmidi_in_get_dev_name(int num, char *s)
{ {
@@ -313,5 +302,4 @@ const device_t rtmidi_input_device = {
.force_redraw = NULL, .force_redraw = NULL,
.config = midi_input_config .config = midi_input_config
}; };
} }