commit b295c07984cd61ab9bc94505512a416c3dae7d24 Author: Steve Ayerhart Date: Mon Mar 28 15:05:17 2022 -0400 initial crap diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ebf685 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +*.ss~ +*.ss#* +.#*.ss + +*.scm~ +*.scm#* +.#*.scm + +*.x +*~ +*.log +*.go +*.la +*.o +*.lo +*.a +autom4te.cache/ +build-aux/ +Makefile +Makefile.in +/configure +/config.status +/config.log +/config.h* +/aclocal.m4 +/compile +/config.guess +/config.sub +/depcomp +/install-sh +/libtool +/ltmain.sh +/missing +/config.rpath +/m4 +.deps +.libs +/src/modules/pre-install-env +/stamp-h1 +/GPATH +/GRTAGS +/GTAGS diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..f521af6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,5 @@ +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = src + +EXTRA_DIST = autogen.sh diff --git a/TODO.org b/TODO.org new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/TODO.org @@ -0,0 +1 @@ +* diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..7fe4f3a --- /dev/null +++ b/configure.ac @@ -0,0 +1,37 @@ +AC_INIT([oriab], [0.1], [steve@ayerh.art]) + +AC_PREREQ([2.65]) + +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_AUX_DIR([build-aux]) +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_SRCDIR([configure.ac]) +AC_CONFIG_HEADERS([config.h]) + +AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability foreign subdir-objects]) + +AC_PROG_CC +AC_PROG_CC_STDC +AM_PROG_CC_C_O +AM_PROG_AR + +LT_INIT([disable-static]) + +GLIB_SETTINGS + +PKG_CHECK_MODULES(GLIB, ["glib-2.0 gobject-2.0"]) +AC_SUBST(GLIB_CFLAGS) +AC_SUBST(GLIB_LIBS) + +PKG_CHECK_MODULES(GSTREAMER, ["gstreamer-1.0 gstreamer-tag-1.0 gstreamer-fft-1.0 gstreamer-audio-1.0 gstreamer-app-1.0"]) +AC_SUBST(GSTREAMER_CFLAGS) +AC_SUBST(GSTREAMER_LIBS) + +PKG_CHECK_MODULES(RAYLIB, ["raylib"]) +AC_SUBST(RAYLIB_CFLAGS) +AC_SUBST(RAYLIB_LIBS) + +AC_CONFIG_FILES([Makefile + src/Makefile]) + +AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..dfd9821 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,13 @@ +bin_PROGRAMS = oriab + +C_FILES = \ + user-interface.c \ + gst-engine.c \ + oriab.c + +H_FILES = $(C_FILES.c=.h) + +oriab_SOURCES = $(C_FILES) + +oriab_CFLAGS = $(GLIB_CFLAGS) $(GSTREAMER_CFLAGS) $(RAYLIB_CFLAGS) +oriab_LDADD = $(GLIB_LIBS) $(GSTREAMER_LIBS) $(RAYLIB_LIBS) diff --git a/src/gst-engine.c b/src/gst-engine.c new file mode 100644 index 0000000..31c1d45 --- /dev/null +++ b/src/gst-engine.c @@ -0,0 +1,84 @@ +#include "gst-engine.h" +#include "user-interface.h" + +gboolean +bus_call (GstBus *bus, GstMessage *msg, gpointer data) +{ + UserInterface *ui = (UserInterface *) data; + GstEngine *engine = ui->engine; + + switch (GST_MESSAGE_TYPE (msg)) + { + case GST_MESSAGE_STATE_CHANGED: + { + g_debug ("state changed"); + break; + } + case GST_MESSAGE_TAG: + { + g_debug ("tag received"); + break; + } + case GST_MESSAGE_EOS: + { + g_debug ("end of stream"); + break; + } + case GST_MESSAGE_DURATION: + { + g_debug ("message duration received"); + break; + } + case GST_MESSAGE_WARNING: + { + g_debug ("warning received"); + break; + } + case GST_MESSAGE_ERROR: + { + g_debug ("error received"); + break; + } + default: + break; + } + + return TRUE; +} + +gboolean +engine_init (GstEngine *engine) +{ + g_debug ("engine init"); + + engine->playing = FALSE; + engine->direction_forward = TRUE; + engine->prev_done = TRUE; + + engine->has_started = FALSE; + engine->has_audio = FALSE; + + engine->loop = FALSE; + + engine->media_duration = -1; + engine->second = GST_SECOND; + engine->av_offset = 0; + engine->rate = 1.0; + + g_debug ("Initialized %s", gst_version_string ()); + + // engine->player = gst_element_factory_make ("playbin", "playbin"); + engine->player = gst_parse_launch ("pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ! spectrum bands=128 threshold=-60 post-messages=true ! fakesink", NULL); + + + /* + if (engine->player == NULL) + { + g_print ("ERROR: failed to created playbin element"); + return FALSE; + } + */ + + + return TRUE; +} diff --git a/src/gst-engine.h b/src/gst-engine.h new file mode 100644 index 0000000..6b881aa --- /dev/null +++ b/src/gst-engine.h @@ -0,0 +1,45 @@ +#ifndef __GST_ENGINE_H__ +#define __GST_ENGINE_H__ + +#include + +G_BEGIN_DECLS + +typedef struct _GstEngine GstEngine; + +struct _GstEngine +{ + gboolean playing, direction_forward, prev_done; + gboolean has_started; + gboolean has_audio; + gboolean loop; + + gint64 media_duration; + gint64 second; + gint64 av_offset; + gdouble rate; + + gchar *uri; + + GstBus *bus; + GstElement *player; +}; + +gboolean at_the_eos (GstEngine *engine); +gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data); +gboolean change_state (GstEngine *engine, gchar *state); +gboolean check_missing_plugins_error (GstEngine *engine, GstMessage *msg); +gboolean engine_init (GstEngine *engine); + +gboolean engine_play (GstEngine *engine); +gboolean engine_seek (GstEngine *engine); +gboolean gngine_stop (GstEngine *engine); + +GstState get_state (GstEngine *engine); + +gint64 query_position (GstEngine *engine); +gboolean update_media_duration (GstEngine *engine); + +G_END_DECLS + +#endif diff --git a/src/oriab b/src/oriab new file mode 100755 index 0000000..63db844 Binary files /dev/null and b/src/oriab differ diff --git a/src/oriab.c b/src/oriab.c new file mode 100644 index 0000000..518081a --- /dev/null +++ b/src/oriab.c @@ -0,0 +1,61 @@ +#include + +#include "gst-engine.h" +#include "user-interface.h" + +void +close_down (UserInterface *ui, GstEngine *engine) +{ + g_debug ("closing oriab\n"); + + gst_element_set_state (engine->player, GST_STATE_NULL); + // change_state (engine, "Null"); + + // UnloadShader (ui->shader); + + gst_object_unref (G_OBJECT (engine->player)); + // g_array_free (ui->spectrum_magnitudes, true); +} + + +int +main (int argc, char *argv[]) +{ + g_debug ("main"); + + UserInterface *ui = NULL; + GstEngine *engine = NULL; + + gboolean ok; + + gst_init (&argc, &argv); + + + ui = g_new (UserInterface, 1); + user_interface_init (ui); + + engine = g_new (GstEngine, 1); + ok = engine_init (engine); + if (!ok) + goto quit; + + ui->engine = engine; + + g_timeout_add (0, ui_loop, ui); + + + ui->engine->bus = gst_element_get_bus (ui->engine->player); + gst_bus_add_signal_watch (ui->engine->bus); + // g_signal_connect (G_OBJECT (ui->engine->bus), "message::element", G_CALLBACK (handle_element), ui); + + gst_element_set_state (ui->engine->player, GST_STATE_PLAYING); + + g_debug ("running"); + g_main_loop_run (ui->loop); + + close_down (ui, engine); + + quit: + + return 0; +} diff --git a/src/shaders/oriab.glsl b/src/shaders/oriab.glsl new file mode 100644 index 0000000..7b110af --- /dev/null +++ b/src/shaders/oriab.glsl @@ -0,0 +1,60 @@ +#version 330 + +#ifdef GL_ES +precision mediump float; +#endif + +in vec2 fragTexCoord; +in vec4 fragColor; + +uniform vec2 uResolution; +uniform float uTime; + +out vec4 finalColor; +//uniform sampler2D u_spectrum; + +/* +void +main () +{ + vec3 c; + float z = 0.1 * u_time; + vec2 uv = gl_FragCoord.xy / u_resolution; + vec2 p = uv - 0.5; + p.x *= u_resolution.x / u_resolution.y; + float l = 0.2 * length (p); + for (int i = 0; i < 3; i++) + { + z += 0.07; + uv += p / l * (sin (z) + 1.0) * abs (sin (l * 9.0 - z * 2.00)); + c[i] = 0.01 / length (abs (mod (uv, 1.0) - 0.5)); + } + float intensity = texture2D (u_spectrum, vec2 (l, 0.5)).x; + gl_FragColor = vec4 (c / l * intensity, u_time); +} +*/ + +void +main () + { + /* + const float stepCount = 128.0; + vec2 barWidth = u_resolution / stepCount; + + float isInsideBar = step (gl_FragCoord.y / u_resolution.y, texture (u_spectrum, vec2 (floor (gl_FragCoord.x / barWidth) / stepCount, 0.25)).x); + color = vec3(1.0) * isInsideBar; + color *= vec3 ((1.0 / stepCount) * floor (gl_FragCoord.x / barWidth), 1.0 - (1.0 / stepCount) * floor (gl_FragCoord.x / barWidth), 0.5); + */ + +// vec2 uv = (gl_FragCoord.xy-.5 * uresolution.xy) / uresolution.y; + // vec3 color = vec3 (0); + + // gl_FragColor = vec4 (color, 1.0); +// vec2 uv = gl_FragCoord.xy / u_resolution; + // gl_FragColor = vec4 (sin (u_spectrum) * 0.5 + 0.5); +// float amplitude = texture2D (u_spectrum, vec2 (uv.x, 0.0)).x; + + // gl_FragColor = vec4 (vec3 (amplitude), 1.0); + // vec2 uv = (fragTexCoord-.5*uResolution.xy) / uResolution.y; + gl_FragColor = vec4(1, 0, 0.5, 1); + } diff --git a/src/user-interface.c b/src/user-interface.c new file mode 100644 index 0000000..5ffcd07 --- /dev/null +++ b/src/user-interface.c @@ -0,0 +1,136 @@ +#include "user-interface.h" +#include +#include + +gboolean handle_element (GstBus *bus, GstMessage *msg, UserInterface *ui) +{ + const GstStructure *s= gst_message_get_structure (msg); + guint band; + const GValue *magnitudes; + + if (gst_structure_has_name (s, "spectrum")) + { + magnitudes = gst_structure_get_value (s, "magnitude"); + gfloat m; + Color *pixels = (Color *)malloc (1024 * sizeof (Color)); + + for (guint i = 0; i < 128; ++i) + { + m = g_value_get_float (gst_value_list_get_value (magnitudes, i)); + //g_debug ("m before = %f", m); + m = (m + 60) * 4.25; + //g_debug ("m = %u", (guint8) m); + pixels->r = (guint8) m; + pixels->g = (guint8) m; + pixels->b = (guint8) m; + pixels->a = 255; + } + + UpdateTexture (ui->spectrum, pixels); + free (pixels); + } + + return TRUE; +} + + +void +user_interface_init (UserInterface *ui) +{ + g_debug("loading ui"); + + InitWindow (DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WINDOW_TITLE); + + ui->loop = g_main_loop_new (NULL, FALSE); + // ui->spectrum_magnitudes = g_array_sized_new (FALSE, TRUE, sizeof (gfloat), 128); + + // Color *pixels = (Color *)malloc (1024 * sizeof (Color)); + //ui->spectrum =LoadTextureFromImage (LoadImageEx (pixels, 1024,1)); + //free (pixels); + + ui->canvas = LoadRenderTexture (GetScreenWidth (), GetScreenHeight ()); + + Shader shader = LoadShader (0, "shaders/oriab.glsl"); + + ui->time = 0.0f; + /* + + SetShaderValue (ui->shader, ui->time_location, &ui->time, UNIFORM_FLOAT); + gfloat res[2] = { (gfloat) GetScreenWidth (), (gfloat) GetScreenHeight () }; + gint loc = GetShaderLocation (ui->shader, "uresolution"); + g_debug ("why: %i", loc); + SetShaderValue (ui->shader, GetShaderLocation (ui->shader, "uresolution"), &res, UNIFORM_VEC2); + g_debug ("YEAH"); + */ + ui->shader = &shader; + + SetTargetFPS(TARGET_FPS); +} + +gboolean ui_loop (gpointer ui_data) +{ + UserInterface *ui = (UserInterface *) ui_data; + + if (WindowShouldClose()) + { + g_debug ("should close"); + g_main_loop_quit(ui->loop); + return FALSE; + } + + draw (ui); + + return TRUE; +} + +void +draw_now_playing (UserInterface *ui) +{ +} + +void +draw (UserInterface *ui) +{ + + /* + if (IsWindowResized ()) + { + g_debug ("NOOO"); + gfloat res[2] = { (gfloat) GetScreenWidth (), (gfloat) GetScreenHeight () }; + SetShaderValue (ui->shader, GetShaderLocation (ui->shader, "uresolution"), &res, UNIFORM_VEC2); + } + + */ + ui->time = GetTime (); + SetShaderValue (*ui->shader, ui->time_location, &ui->time, UNIFORM_FLOAT); + + //SetShaderValue (ui->shader, GetShaderLocation (ui->shader, "u_spectrum"), &ui->spectrum, UNIFORM_SAMPLER2D); + BeginDrawing (); + ClearBackground (RAYWHITE); + + BeginTextureMode (ui->canvas); + ClearBackground (RAYWHITE); + DrawRectangle (0, 0, GetScreenWidth (), GetScreenHeight (), GRAY); + EndTextureMode (); + + /* + BeginShaderMode (ui->shader); + DrawTextureRec (ui->canvas.texture, + (Rectangle) {0, 0, ui->canvas.texture.width, -ui->canvas.texture.height}, + (Vector2) {0.0f, 0.0f}, + PINK); + EndShaderMode (); + */ + + DrawFPS(0, 0); + + DrawText(FormatText ("time: %f", ui->time), GetScreenWidth () -180, GetScreenHeight () - 20,20, DARKGRAY); + + EndDrawing (); +} + +void +close_user_interface (void) +{ + CloseWindow (); +} diff --git a/src/user-interface.h b/src/user-interface.h new file mode 100644 index 0000000..19c00cf --- /dev/null +++ b/src/user-interface.h @@ -0,0 +1,55 @@ +#ifndef __USER_INTERFACE_H__ +#define __USER_INTERFACE_H__ + +#include + +#include "gst-engine.h" + +G_BEGIN_DECLS + +#define DEFAULT_WINDOW_TITLE "Oriab" +#define DEFAULT_WIDTH 1280 +#define DEFAULT_HEIGHT 780 +#define TARGET_FPS 60 + +typedef struct _UserInterface UserInterface; + +struct _UserInterface +{ + gint title_length, progress_id; + gint64 media_duration; + gfloat stage_width, stage_height; + gfloat screen_with, screen_height; + gfloat windowed_width, windowed_height; + + gfloat playback_position, volume; + + gchar *duration_str; + + // GArray *spectrum_magnitudes; + GMainLoop *loop; + GstEngine *engine; + + RenderTexture2D canvas; + + Shader *shader; + + Texture2D spectrum; + gfloat time; + + gint spectrum_location; + gint resolution_location; + gint time_location; + +}; + +void user_interface_init (UserInterface *ui); +void close_user_interface (void); +gboolean handle_element (GstBus *bus, GstMessage *msg, UserInterface *ui); +void draw_now_playing (UserInterface *ui); +gboolean ui_loop (gpointer ui_data); +void draw (UserInterface *ui); + +G_END_DECLS + +#endif