aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathansmith <nathansmith@posteo.com>2025-05-03 01:46:21 +0000
committernathansmith <nathansmith@posteo.com>2025-05-03 01:46:21 +0000
commit2d2f143d248ef9f173f711108feb770efdfe7d21 (patch)
treec82af5d97f4d4594f2630eabe9b31cec935ebf50 /src
parentffd314a245632a85ba5f310e8d86937091886d4d (diff)
downloadsldj-2d2f143d248ef9f173f711108feb770efdfe7d21.tar.gz
sldj-2d2f143d248ef9f173f711108feb770efdfe7d21.tar.bz2
sldj-2d2f143d248ef9f173f711108feb770efdfe7d21.zip
Shorter lines
Diffstat (limited to 'src')
-rw-r--r--src/Makefile3
-rw-r--r--src/ffmpeg.c58
-rw-r--r--src/ffmpeg.h9
-rw-r--r--src/scripting.c6
-rw-r--r--src/scripting.h3
-rw-r--r--src/sldj.c35
6 files changed, 81 insertions, 33 deletions
diff --git a/src/Makefile b/src/Makefile
index 10581e7..17381b3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -9,7 +9,8 @@ LIBSLDJ = libsldj/libsldj.so
%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $<
$(TARGET): $(OBJECTS) $(LIBSLDJ)
- $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) $(wildcard "libsldj/*.o") $(LDFLAGS)
+ $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) $(wildcard "libsldj/*.o") \
+$(LDFLAGS)
$(LIBSLDJ): $(wildcard libsldj/*.c libsldj/*.h)
@$(MAKE) -C libsldj
diff --git a/src/ffmpeg.c b/src/ffmpeg.c
index 37d5185..21692d0 100644
--- a/src/ffmpeg.c
+++ b/src/ffmpeg.c
@@ -7,13 +7,15 @@
#include "ffmpeg.h"
-FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint32_t fps)
+FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height,
+uint32_t fps)
{
int pipefd[2];
if (pipe(pipefd) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: Could not create a pipe: %s", strerror(errno));
+ TraceLog(LOG_ERROR, "FFMPEG: Could not create a pipe: %s",
+ strerror(errno));
return NULL;
}
@@ -21,7 +23,8 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
if (child < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: could not fork a child: %s", strerror(errno));
+ TraceLog(LOG_ERROR, "FFMPEG: could not fork a child: %s",
+ strerror(errno));
return NULL;
}
@@ -29,14 +32,18 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
{
if (dup2(pipefd[READ_END], STDIN_FILENO) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG CHILD: could not reopen read end of pipe as stdin: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG CHILD: could not reopen read end of pipe as stdin: %s",
+ strerror(errno));
exit(1);
}
close(pipefd[WRITE_END]);
char resolution[64];
- snprintf(resolution, sizeof(resolution), "%zux%zu", (size_t)width, (size_t)height);
+ snprintf(resolution, sizeof(resolution), "%zux%zu", (size_t)width,
+ (size_t)height);
char framerate[64];
snprintf(framerate, sizeof(framerate), "%zu", (size_t)fps);
@@ -61,7 +68,10 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
if (ret < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG CHILD: could not run ffmpeg as a child process: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG CHILD: could not run ffmpeg as a child process: %s",
+ strerror(errno));
exit(1);
}
@@ -71,7 +81,10 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
if (close(pipefd[READ_END]) < 0)
{
- TraceLog(LOG_WARNING, "FFMPEG: could not close read end of the pipe on the parent's end: %s", strerror(errno));
+ TraceLog(
+ LOG_WARNING,
+ "FFMPEG: could not close read end of the pipe on the parent's end:%s",
+ strerror(errno));
}
FFMPEG* ffmpeg = malloc(sizeof(FFMPEG));
@@ -81,13 +94,18 @@ FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint3
return ffmpeg;
}
-int ffmpegSendFrame(FFMPEG* ffmpeg, void* data, uint32_t width, uint32_t height)
+int ffmpegSendFrame(FFMPEG* ffmpeg, void* data, uint32_t width, uint32_t
+height)
{
for (uint32_t y = height; y > 0; --y)
{
- if (write(ffmpeg->pipe, (uint32_t*)data + (y - 1) * width, sizeof(uint32_t) * width) < 0)
+ if (write(ffmpeg->pipe, (uint32_t*)data + (y - 1) * width,
+ sizeof(uint32_t) * width) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: failed to write into ffmpeg pipe: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: failed to write into ffmpeg pipe: %s",
+ strerror(errno));
return -1;
}
}
@@ -104,7 +122,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (close(pipe) < 0)
{
- TraceLog(LOG_WARNING, "FFMPEG: could not close write end of the pipe on the parent's end: %s", strerror(errno));
+ TraceLog(
+ LOG_WARNING,
+ "FFMPEG: could not close write end of the pipe on the parent's end:%s",
+ strerror(errno));
}
if (cancel)
@@ -118,7 +139,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (waitpid(pid, &wstatus, 0) < 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: could not wait for ffmpeg child process to finish: %s", strerror(errno));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: could not wait for ffmpeg child process to finish:%s",
+ strerror(errno));
return -1;
}
@@ -128,7 +152,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (exit_status != 0)
{
- TraceLog(LOG_ERROR, "FFMPEG: ffmpeg exited with code %d", exit_status);
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: ffmpeg exited with code %d",
+ exit_status);
return -1;
}
@@ -137,7 +164,10 @@ int ffmpegEnd(FFMPEG* ffmpeg, bool cancel)
if (WIFSIGNALED(wstatus))
{
- TraceLog(LOG_ERROR, "FFMPEG: ffmpeg got terminated by %s", strsignal(WTERMSIG(wstatus)));
+ TraceLog(
+ LOG_ERROR,
+ "FFMPEG: ffmpeg got terminated by %s",
+ strsignal(WTERMSIG(wstatus)));
return -1;
}
}
diff --git a/src/ffmpeg.h b/src/ffmpeg.h
index ea1f3c6..6fa4007 100644
--- a/src/ffmpeg.h
+++ b/src/ffmpeg.h
@@ -7,7 +7,8 @@
#include <raylib.h>
-// stolen code: https://github.com/tsoding/musializer/blob/master/src/ffmpeg_posix.c
+// stolen code:
+// https://github.com/tsoding/musializer/blob/master/src/ffmpeg_posix.c
#ifndef FFMPEG_H
#define FFMPEG_H
@@ -20,8 +21,10 @@ typedef struct FFMPEG {
pid_t pid;
} FFMPEG;
-FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height, uint32_t fps);
-int ffmpegSendFrame(FFMPEG* ffmpeg, void* data, uint32_t width, uint32_t height);
+FFMPEG* ffmpegStart(const char* filename, uint32_t width, uint32_t height,
+ uint32_t fps);
+int ffmpegSendFrame(FFMPEG* ffmpeg, void* data, uint32_t width, uint32_t
+ height);
int ffmpegEnd(FFMPEG* ffmpeg, bool cancel);
#endif
diff --git a/src/scripting.c b/src/scripting.c
index 8dbdec5..dd9f6c7 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -37,7 +37,8 @@ void compileScript(SldjScripting* scripting, const char filePath[SLDJ_NAMEMAX])
{
scripting->fileBuf = (char*)malloc(scripting->fileSize);
} else {
- scripting->fileBuf = (char*)realloc(scripting->fileBuf, scripting->fileSize);
+ scripting->fileBuf = (char*)realloc(scripting->fileBuf,
+ scripting->fileSize);
}
if (scripting->fileBuf == NULL)
@@ -72,7 +73,8 @@ void compileScript(SldjScripting* scripting, const char filePath[SLDJ_NAMEMAX])
return;
}
- tcc_set_error_func(scripting->state, stderr, handle_tcc_error);
+ tcc_set_error_func(scripting->state, stderr,
+ handle_tcc_error);
tcc_set_output_type(scripting->state, TCC_OUTPUT_MEMORY);
tcc_add_library_path(scripting->state, "./libsldj");
diff --git a/src/scripting.h b/src/scripting.h
index 2a7220a..f60a65e 100644
--- a/src/scripting.h
+++ b/src/scripting.h
@@ -31,6 +31,7 @@ typedef struct SldjScripting {
void initScripting(SldjScripting* scripting);
void closeScripting(SldjScripting* scripting);
-void compileScript(SldjScripting* scripting, const char filePath[SLDJ_NAMEMAX]);
+void compileScript(SldjScripting* scripting,
+ const char filePath[SLDJ_NAMEMAX]);
#endif
diff --git a/src/sldj.c b/src/sldj.c
index 08dd1b9..5f66c95 100644
--- a/src/sldj.c
+++ b/src/sldj.c
@@ -11,7 +11,8 @@ void initSldj(Sldj *sldj)
SetTargetFPS(DEFAULT_FRAME_RATE);
sldj->targetFps = DEFAULT_FRAME_RATE;
- sldj->viewport = LoadRenderTexture(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT);
+ sldj->viewport = LoadRenderTexture(DEFAULT_SCREEN_WIDTH,
+ DEFAULT_SCREEN_HEIGHT);
sldj->frameCounter = 0;
sldj->xCount = UINT16_MAX / DEFAULT_SCREEN_WIDTH;
sldj->yCount = UINT16_MAX / DEFAULT_SCREEN_HEIGHT;
@@ -55,20 +56,24 @@ void updateGui(Sldj* sldj)
if (sldj->gui.fpsSliderValue != oldFps)
{
sldj->targetFps = (uint32_t)sldj->gui.fpsSliderValue;
- sldj->targetFps = sldj->targetFps > FRAME_RATE_MAX ? 0 : sldj->targetFps;
+ sldj->targetFps =
+ sldj->targetFps > FRAME_RATE_MAX ? 0 : sldj->targetFps;
SetTargetFPS(sldj->targetFps);
}
// Width and height.
- GuiSlider(sldj->gui.widthSlider, "Width", TextFormat("%d", (int)sldj->gui.widthSliderValue),
- &sldj->gui.widthSliderValue, SCREEN_MIN, SCREEN_MAX);
- GuiSlider(sldj->gui.heightSlider, "Height", TextFormat("%d", (int)sldj->gui.heightSliderValue),
- &sldj->gui.heightSliderValue, SCREEN_MIN, SCREEN_MAX);
+ GuiSlider(sldj->gui.widthSlider, "Width",
+ TextFormat("%d",(int)sldj->gui.widthSliderValue),
+ &sldj->gui.widthSliderValue, SCREEN_MIN, SCREEN_MAX);
+ GuiSlider(sldj->gui.heightSlider, "Height",
+ TextFormat("%d", (int)sldj->gui.heightSliderValue),
+ &sldj->gui.heightSliderValue, SCREEN_MIN, SCREEN_MAX);
if (GuiButton(sldj->gui.viewportButton, "Reset view"))
{
- resetViewport(sldj, sldj->gui.widthSliderValue, sldj->gui.heightSliderValue);
+ resetViewport(sldj,
+ sldj->gui.widthSliderValue, sldj->gui.heightSliderValue);
resizeGui(sldj);
}
}
@@ -93,7 +98,9 @@ void updateSldj(Sldj* sldj)
for (int x = 0; x < sldj->viewport.texture.width; ++x)
{
- DrawPixel(x, y, sldj->scripting.lineScanner(xScan, yScan, sldj->frameCounter));
+ DrawPixel(x, y,
+ sldj->scripting.lineScanner(
+ xScan, yScan, sldj->frameCounter));
xScan += sldj->xCount;
}
@@ -147,15 +154,19 @@ void resizeGui(Sldj* sldj)
sldj->gui.fpsSlider = (Rectangle){startX, startY, sliderWidth, guiHeight};
- sldj->gui.widthSlider = (Rectangle){startX, startY + guiHeight, sliderWidth, guiHeight};
- sldj->gui.heightSlider = (Rectangle){startX, startY + guiHeight * 2.0, sliderWidth, guiHeight};
- sldj->gui.viewportButton = (Rectangle){startX, startY + guiHeight * 3.0, guiWidth * 2.0, guiHeight};
+ sldj->gui.widthSlider = (Rectangle){startX, startY + guiHeight,
+ sliderWidth, guiHeight};
+ sldj->gui.heightSlider = (Rectangle){startX, startY + guiHeight * 2.0,
+ sliderWidth, guiHeight};
+ sldj->gui.viewportButton = (Rectangle){startX, startY + guiHeight * 3.0,
+ guiWidth * 2.0, guiHeight};
}
void resetViewportRect(Sldj* sldj, float scale)
{
Texture texture = sldj->viewport.texture;
- sldj->viewPortRect = (Rectangle){0.0, 0.0, texture.width * scale, texture.height * scale};
+ sldj->viewPortRect = (Rectangle){0.0, 0.0, texture.width * scale,
+ texture.height * scale};
}
void resetViewport(Sldj* sldj, int width, int height)