From 9c5fb1af8ca737d6bd18e3ad22b50f70c915f566 Mon Sep 17 00:00:00 2001 From: falsycat Date: Sat, 5 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Replaced the test program with the subproject of sjplayer. --- dub.json | 2 +- sjplayer/dub.json | 5 ++++ sjplayer/standalone/dub.json | 14 +++++++++ sjplayer/standalone/main.d | 57 ++++++++++++++++++++++++++++++++++++ sjplayer/test.d | 47 ----------------------------- 5 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 sjplayer/standalone/dub.json create mode 100644 sjplayer/standalone/main.d delete mode 100755 sjplayer/test.d diff --git a/dub.json b/dub.json index ca5e01c..34dbb23 100644 --- a/dub.json +++ b/dub.json @@ -3,5 +3,5 @@ "targetType": "none", - "subPackages": ["sjscript"] + "subPackages": ["sjscript", "sjplayer"] } diff --git a/sjplayer/dub.json b/sjplayer/dub.json index 5a24f13..8a38f53 100644 --- a/sjplayer/dub.json +++ b/sjplayer/dub.json @@ -3,7 +3,12 @@ "targetPath": ".bin", + "subPackages": [ + "standalone" + ], + "dependencies": { + "sjscript": {"path": "../sjscript"}, "gl4d": {"path": "../thirdparty/gl4d"} } } diff --git a/sjplayer/standalone/dub.json b/sjplayer/standalone/dub.json new file mode 100644 index 0000000..038568b --- /dev/null +++ b/sjplayer/standalone/dub.json @@ -0,0 +1,14 @@ +{ + "name": "standalone", + + "sourcePaths": ["."], + "mainSourceFile": "main.d", + + "targetPath": ".bin", + + "dependencies": { + "sjplayer": {"path": "../"}, + "gl4d": {"path": "../../thirdparty/gl4d"}, + "derelict-sfml2": "~>4.0.0-beta.2" + } +} diff --git a/sjplayer/standalone/main.d b/sjplayer/standalone/main.d new file mode 100644 index 0000000..c829f81 --- /dev/null +++ b/sjplayer/standalone/main.d @@ -0,0 +1,57 @@ +/// License: MIT +import std; + +import derelict.sfml2.audio, + derelict.sfml2.system, + derelict.sfml2.window; + +import gl4d; + +int main(string[] args) { + (args.length == 4).enforce; + const music_file = args[1]; + const bpm = args[2].to!float; + const script_file = args[3]; + + auto win = Initialize(); + scope(exit) sfWindow_destroy(win); + + auto music = sfMusic_createFromFile(music_file.toStringz).enforce; + scope(exit) sfMusic_destroy(music); + sfMusic_play(music); + + while (true) { + sfEvent e; + sfWindow_pollEvent(win, &e); + if (e.type == sfEvtClosed) break; + + const msecs = sfMusic_getPlayingOffset(music).microseconds * 1e-6f; + const beat = msecs/60f * bpm; + + sfWindow_display(win); + } + return 0; +} + +sfWindow* Initialize() { + DerelictSFML2System.load(); + DerelictSFML2Window.load(); + DerelictSFML2Audio .load(); + + sfContextSettings specs; + specs.depthBits = 24; + specs.stencilBits = 8; + specs.antialiasingLevel = 1; + specs.majorVersion = 3; + specs.minorVersion = 3; + specs.attributeFlags = sfContextCore; + + auto win = sfWindow_create(sfVideoMode(600, 600), + "sjplayer".toStringz, sfClose | sfTitlebar, &specs).enforce; + sfWindow_setVerticalSyncEnabled(win, true); + + sfWindow_setActive(win, true).enforce; + gl.ApplyContext(); + + return win; +} diff --git a/sjplayer/test.d b/sjplayer/test.d deleted file mode 100755 index b0ff3bc..0000000 --- a/sjplayer/test.d +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env dub -/+ dub.json: -{ - "name": "sjplayer", - "dependencies": { - "sjscript": {"path": "../sjscript"}, - "derelict-sfml2": "~>4.0.0-beta.2" - }, - "lflags-posix": ["-L../thirdparty/dsfml/lib"], - "lflags-windows": ["/LIBPATH:..\\thirdparty\\dsfml\\lib\\"] -} +/ - -import std; - -import derelict.sfml2.audio, - derelict.sfml2.system, - derelict.sfml2.window; - -int main(string[] args) { - DerelictSFML2System.load(); - DerelictSFML2Window.load(); - DerelictSFML2Audio.load(); - - sfContextSettings specs; - specs.depthBits = 32; - specs.stencilBits = 32; - specs.antialiasingLevel = 1; - specs.majorVersion = 3; - specs.minorVersion = 3; - - auto win = sfWindow_create( - sfVideoMode(600, 600), "sjplayer".toStringz, sfDefaultStyle, &specs); - scope(exit) sfWindow_destroy(win); - - sfWindow_setActive(win, true); - - auto running = true; - while (running) { - sfEvent e; - sfWindow_pollEvent(win, &e); - - running = e.type != sfEvtClosed; - - sfWindow_display(win); - } - return 0; -}