summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/midi.c6
-rw-r--r--src/osc.c4
-rw-r--r--src/osc_sound.c2
-rw-r--r--src/sound.c17
-rw-r--r--src/synth_gui.c1
-rw-r--r--src/web.c8
-rw-r--r--tmpl/index.html68
7 files changed, 91 insertions, 15 deletions
diff --git a/src/midi.c b/src/midi.c
index a015de4..2ba97d6 100644
--- a/src/midi.c
+++ b/src/midi.c
@@ -159,7 +159,7 @@ init_midi(midi_t *m, synth_t *synth)
Pm_Initialize();
- printf("midi devs: %d\n", Pm_CountDevices());
+ //printf("midi devs: %d\n", Pm_CountDevices());
const PmDeviceInfo *info;
int i=0;
for (i = 0; i < Pm_CountDevices(); i++) {
@@ -167,10 +167,12 @@ init_midi(midi_t *m, synth_t *synth)
if (!info->input) {
continue;
}
- printf("%d: %s [input: %d output: %d opened: %d is_virt:%d] (interf: %s) -- %d\n", i, info->name, info->input, info->output, info->opened, info->is_virtual, info->interf, Pm_GetDefaultInputDeviceID());
+ //printf("%d: %s [input: %d output: %d opened: %d is_virt:%d] (interf: %s) -- %d\n", i, info->name, info->input, info->output, info->opened, info->is_virtual, info->interf, Pm_GetDefaultInputDeviceID());
if (!strcmp(synth->midi_device.name, info->name) && !info->input) break;
}
+ printf("Selected device: %s [input: %d output: %d opened: %d is_virt:%d] (interf: %s)\n", info->name, info->input, info->output, info->opened, info->is_virtual, info->interf);
+
Pt_Start(1, midiCallback, m);
Pm_OpenInput(&(m->stream),
diff --git a/src/osc.c b/src/osc.c
index 16e6894..28e35b4 100644
--- a/src/osc.c
+++ b/src/osc.c
@@ -66,8 +66,8 @@ osc_load_wav(osc_t * osc, const char * path)
return -1;
}
- printf("Opened %s: \n", path);
- printf("frames: %ld sr: %d chan: %d format: %d sections: %d seekable: %d\n", fileInfo.frames, fileInfo.samplerate, fileInfo.channels, fileInfo.format, fileInfo.sections, fileInfo.seekable);
+ /* printf("Opened %s: \n", path); */
+ /* printf("frames: %ld sr: %d chan: %d format: %d sections: %d seekable: %d\n", fileInfo.frames, fileInfo.samplerate, fileInfo.channels, fileInfo.format, fileInfo.sections, fileInfo.seekable); */
// Ensure the WAV file has only one channel
if (fileInfo.channels != 1) {
diff --git a/src/osc_sound.c b/src/osc_sound.c
index fbf8860..4d34834 100644
--- a/src/osc_sound.c
+++ b/src/osc_sound.c
@@ -24,7 +24,7 @@ osc_sound(float offset)
//osc_load_wav(&OSC_sound, "/home/grm/code/synth-project/waves/Free Wavetables[2048]/Filter Sweep[2048-44.1khz-32bit]/SweepSaw.wav");
//osc_load_wav(&OSC_sound, "/home/grm/code/synth-project/waves/Free Wavetables[2048]/Additive Synth[2048-44.1khz-32bit]/Add Synth7.wav");
//osc_load_wav(&OSC_sound, "/home/grm/code/synth-project/waves/Free Wavetables[2048]/Korg Analog Synth PhaseShift[2048-44.1khz-32bit]/MS 20 Saw MPS.wav");
- osc_load_wav(&OSC_sound, "/home/grm/code/synth-project/waves/Free Wavetables[2048]/Korg Analog Synth PhaseShift[2048-44.1khz-32bit]/MonoPoly Saw PS1.wav");
+ osc_load_wav(&OSC_sound, "/home/grm/code/synth-project-b/waves/Free Wavetables[2048]/Korg Analog Synth PhaseShift[2048-44.1khz-32bit]/MonoPoly Saw PS1.wav");
OSC_sound.start = wvt_size*0;
OSC_sound.len = OSC_sound.start + wvt_size;
}
diff --git a/src/sound.c b/src/sound.c
index d4b0242..570ec71 100644
--- a/src/sound.c
+++ b/src/sound.c
@@ -57,7 +57,12 @@ void
init_sound(synth_t * synth, PaStreamCallback *streamCallback, const char* device_name)
{
printf("Will try to initialized pulseaudion device [ %s ]\n", device_name);
- Pa_Initialize();
+ freopen("/dev/null","w",stderr);
+ PaError err = Pa_Initialize();
+ freopen("/dev/tty", "w", stderr);
+ if (err != paNoError) {
+ fprintf(stderr, "PortAudio error: %s\n", Pa_GetErrorText(err));
+ }
int i=0;
const PaDeviceInfo *deviceInfo;
@@ -77,7 +82,7 @@ init_sound(synth_t * synth, PaStreamCallback *streamCallback, const char* device
PaStreamParameters outputParameters;
outputParameters.device = i;// Pa_GetDefaultOutputDevice(); /* default output device */
- printf("-------\nSelected device: dev: %s || %f || id:%d out:%d || lil:%f lol:%f\n-------\n", deviceInfo->name,
+ printf("Selected device: dev: %s || %f || id:%d out:%d || lil:%f lol:%f\n", deviceInfo->name,
deviceInfo->defaultSampleRate, deviceInfo->maxInputChannels,
deviceInfo->maxOutputChannels, deviceInfo->defaultLowInputLatency,
deviceInfo->defaultLowOutputLatency);
@@ -86,7 +91,6 @@ init_sound(synth_t * synth, PaStreamCallback *streamCallback, const char* device
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
- PaError err;
err = Pa_OpenStream(&(synth->stream),
NULL, /* no input */
&outputParameters,
@@ -110,16 +114,17 @@ init_sound(synth_t * synth, PaStreamCallback *streamCallback, const char* device
Pa_SetStreamFinishedCallback(synth->stream, &StreamFinished);
Pa_StartStream(synth->stream);
- printf("<3 <3 <3 <3 Portaudio stream started <3 <3 <3 <3\n");
synth->sound_active = 1;
}
void
destroy_sound(synth_t * synth)
{
- printf(":( :( :( stopping stream </3 </3 </3\n");
synth->sound_active = 0;
Pa_StopStream( synth->stream );
Pa_CloseStream( synth->stream );
- Pa_Terminate();
+ PaError err = Pa_Terminate();
+ if( err != paNoError )
+ fprintf(stderr, "PortAudio error: %s\n", Pa_GetErrorText( err ) );
+
}
diff --git a/src/synth_gui.c b/src/synth_gui.c
index d1dc78e..215b8f5 100644
--- a/src/synth_gui.c
+++ b/src/synth_gui.c
@@ -882,6 +882,7 @@ rayrun(synth_t *synth){
/* int old_soundcard_id = synth->soundcard_id; */
/* int old_midi_device_id = synth->midi_device_id; */
+ SetTraceLogLevel(LOG_ERROR);
InitWindow(WIDTH, HEIGHT, "Raylib synth");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
while (!WindowShouldClose()) {
diff --git a/src/web.c b/src/web.c
index 3108545..f3aa5f7 100644
--- a/src/web.c
+++ b/src/web.c
@@ -58,8 +58,6 @@ char *read_file_to_string(const char *filename) {
return buffer;
}
-
-
int
key_to_number(char key) {
switch (key) {
@@ -207,13 +205,13 @@ void *websocket_server_thread(void *arg) {
info.pt_serv_buf_size = 32 * 1024;
info.options = LWS_SERVER_OPTION_VALIDATE_UTF8;
- context = lws_create_context(&info);
+ context = lws_create_context(&info);
if (!context) {
fprintf(stderr, "lws_create_context failed\n");
return NULL;
}
- printf("WebSocket server running on ws://localhost:%d\n", WS_PORT);
+ printf("WebSocket server running on ws://localhost:%d [http://localhost:%d]\n", WS_PORT, WS_PORT);
while (1) {
lws_service(context, 1000); // Service WebSocket events
@@ -259,6 +257,8 @@ init_web(synth_t * synth)
html_content = get_from_template();
synthx = synth;
+ lws_set_log_level(LLL_WARN, NULL);
+
// Create a new thread for the WebSocket server
if (pthread_create(&server_thread, NULL, websocket_server_thread, NULL) != 0) {
fprintf(stderr, "Failed to create server thread\n");
diff --git a/tmpl/index.html b/tmpl/index.html
new file mode 100644
index 0000000..23a0714
--- /dev/null
+++ b/tmpl/index.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>C SYNTH WEB!</title>
+ </head>
+ <body>
+ <input id='slider' style='width: 100%; height: 200px;' type='range'
+ min='1' max='22000' />
+ <button onclick='onButtonClick()'>Trigger</button>
+ <button id='but'>ws</button>
+ <script>
+ const ws = new WebSocket('ws://10.0.0.10:9967');
+ const slider = document.getElementById('slider');
+ const but = document.getElementById('but')
+ slider.oninput = function() { ws.send(slider.value); }
+ but.onmousedown = function() { ws.send('note_on'); };
+ but.onmouseup = function() { ws.send('note_off'); }
+ ws.onmessage = function(event) {
+ console.log('Message from server: ' + event.data);
+ slider.value = parseInt(event.data);
+ };
+ ws.onopen = function() {
+ console.log('Connected to WebSocket server');
+ };
+ ws.onerror = function(error) {
+ console.error('WebSocket error: ' + error);
+ };
+ // Function to send key events
+ const pressed_map = new Map();
+
+ const sendKeyEvent = (eventType, event) => {
+ if (ws.readyState === WebSocket.OPEN) {
+ if (event.repeat == true) return;
+ if (eventType == "keydown") {
+ if (pressed_map.get(event.key) == true) return;
+ pressed_map.set(event.key, true)
+ ws.send("+" + event.key);
+ } else if (eventType == "keyup") {
+ pressed_map.set(event.key, false)
+ ws.send("-" + event.key);
+ }
+ // console.log(event);
+ // ws.send(JSON.stringify({
+ // type: eventType,
+ // key: event.key,
+ // code: event.code,
+ // keyCode: event.keyCode,
+ // ctrl: event.ctrlKey,
+ // shift: event.shiftKey,
+ // alt: event.altKey,
+ // meta: event.metaKey
+ // }));
+ }
+ };
+ document.addEventListener("keydown", (event) => sendKeyEvent("keydown", event));
+ document.addEventListener("keyup", (event) => sendKeyEvent("keyup", event));
+
+ var fps = 60;
+
+ function loop() {
+ //document.getElementById("test").innerText = ;
+
+ setTimeout(loop, 1000 / fps);
+ }
+ loop();
+ </script>
+ </body>
+</html>