Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first wrapper: soloud #6

Merged
merged 8 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ script:
- nimble install -y
- nimble test
# see also: https://github.com/nimterop/wrappers?subdir=foo
- nimble --nimbleDir:`pwd`/build/fakenimble install -y "https://github.com/nimterop/wrappers"
# D20190131T164901:here Note: that can't work, it needs to be from current PR
# - nimble --verbose --nimbleDir:`pwd`/build/fakenimble install -y "https://github.com/nimterop/wrappers"
7 changes: 4 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ for:
7z x -y "nim-%NIM_VERSION%_x%ARCH%.zip"> nul &&
del "nim-%NIM_VERSION%_x%ARCH%.zip")
- SET PATH=c:\binaries\mingw%ARCH%\bin;c:\binaries\nim-%NIM_VERSION%\bin;%USERPROFILE%\.nimble\bin;%PATH%
- CD c:\projects\nimterop_wrappers
- CD c:\projects\wrappers
timotheecour marked this conversation as resolved.
Show resolved Hide resolved

on_finish:
- 7z a -r buildlogs-win-pkgs.zip %USERPROFILE%\.nimble\pkgs
Expand Down Expand Up @@ -69,7 +69,7 @@ for:
./koch nimble -d:release;
fi
- export PATH=/home/appveyor/binaries/nim-$NIM_VERSION/bin:~/.nimble/bin:$PATH
- cd /home/appveyor/projects/nimterop_wrappers
- cd /home/appveyor/projects/wrappers

on_finish:
- zip -r -q buildlogs-lin-pkgs.zip ~/.nimble/pkgs
Expand All @@ -85,6 +85,7 @@ build_script:

test_script:
- nimble test
- nimble --nimbleDir:`pwd`/build/fakenimble install -y "https://github.com/nimterop/wrappers"
# see D20190131T164901
# - nimble --nimbleDir:`pwd`/build/fakenimble install -y "https://github.com/nimterop/wrappers"

deploy: off
15 changes: 15 additions & 0 deletions src/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[
see D20190127T231316 workaround for fact that toast needs to build
scanner.cc, which would otherwise result in link errors such as:
"std::terminate()", referenced from:
___clang_call_terminate in scanner.cc.o
]#
when defined(MacOSX):
switch("clang.linkerexe", "g++")
else:
switch("gcc.linkerexe", "g++")

# Workaround for NilAccessError crash on Windows #98
when defined(Windows):
switch("gc", "markAndSweep")

timotheecour marked this conversation as resolved.
Show resolved Hide resolved
32 changes: 24 additions & 8 deletions src/wrappers.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
#[
Tool to help manage wrappers, eg:
* upgrade wrappers
* generate individual nimble pacakges
TODO:
* helpers to upgrade wrappers when new upstream library is released
* mabye: generate individual nimble packages (1 per wrapper)
]#

import wrapperspkg/submodule
import std/[os]
import wrapperspkg/paths

proc main() =
echo(getWelcomeMessage())
type Action = enum
list,

proc main(action = list) =
##[
Tool to help manage wrappers, for now:
* list all wrappers
]##
case action
of list:
var wrappers: seq[string]
for kind, path in walkDir(formulasDir(), relative = true):
wrappers.add path
echo wrappers

when isMainModule:
import cligen
dispatch(main)

var ret: seq[string]
for a in Action: ret.add $a
# TODO: make this work
# dispatch(main, help = {"action": $ret})
dispatch(main, help = {"action": "see wrappers.Action"})
2 changes: 2 additions & 0 deletions src/wrapperspkg/formulas/soloud/config.nims.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# see D20190131T165517
switch("define","ssl")
40 changes: 40 additions & 0 deletions src/wrapperspkg/formulas/soloud/demo.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import std/[os,httpclient]
import wrapperspkg/[paths]
#[
from outside this repo, use: (CHECKME); TODO: simplify
import wrappers/wrapperspkg/formulas/soloud/wrapper
]#
import "."/wrapper

timotheecour marked this conversation as resolved.
Show resolved Hide resolved
let urlDefault = "https://freewavesamples.com/files/Yamaha-V50-Rock-Beat-120bpm.wav"

proc main(file = "", url = urlDefault, volume = 10.0) =
##[
Demo program for `soloud` that plays a wav file
contained either in `file` or `url`
]##
var file = file
if file == "":
var content = newHttpClient().getContent(url)
file = reopBuildDir() / "D20190131T001105.wav"
file.writeFile content

var s = Soloud_create()
defer: s.Soloud_destroy()

doAssert s.Soloud_init() == 0
defer: Soloud_deinit(s)

Soloud_setGlobalVolume(s, volume)

var sample = Wav_create()
defer: sample.Wav_destroy()

doAssert sample.Wav_load(file.cstring) == 0
doAssert s.Soloud_play(sample) == 1 # check why this is 1
while s.Soloud_getActiveVoiceCount() > 0.cuint:
sleep(100)

when isMainModule:
import cligen
dispatch(main)
2 changes: 2 additions & 0 deletions src/wrapperspkg/formulas/soloud/nim.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# D20190131T165517:here TODO: pending nim 0.19.4 remove in favor of config.nims, see https://github.com/nim-lang/Nim/issues/10344#issuecomment-455976730
--define:ssl
51 changes: 51 additions & 0 deletions src/wrapperspkg/formulas/soloud/wrapper.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import std/[os]
import nimterop/[cimport, git]
import wrapperspkg/[paths]

const
# TODO: DRY (no: soloud)
baseDir = reopBuildDir()/"soloud"
incl = baseDir/"include"
src = baseDir/"src"

static:
gitPull("https://github.com/jarikomppa/soloud", baseDir, "include/*\nsrc/*\n")

cDisableCaching()

cOverride:
type
Soloud* = pointer
AlignedFloatBuffer* = pointer

proc Soloud_destroy*(aSoloud: ptr Soloud) {.importc: "Soloud_destroy", header: cSearchPath(incl/"soloud_c.h").}

# todo: factor common parts with nimtero/tests/tsoloud.nim
cSkipSymbol("WavStream_stop", "WavStream_setFilter")

timotheecour marked this conversation as resolved.
Show resolved Hide resolved
cIncludeDir(incl)

when defined(osx):
cDefine("WITH_COREAUDIO")
{.passL: "-framework CoreAudio -framework AudioToolbox".}
cCompile(src/"backend/coreaudio/*.cpp")
elif defined(Linux):
{.passL: "-lpthread".}
cDefine("WITH_OSS")
cCompile(src/"backend/oss/*.cpp")
elif defined(Windows):
{.passC: "-msse".}
{.passL: "-lwinmm".}
cDefine("WITH_WINMM")
cCompile(src/"backend/winmm/*.cpp")
else:
static: doAssert false

cCompile(src/"c_api/soloud_c.cpp")
cCompile(src/"core/*.cpp")
cCompile(src/"audiosource", "cpp")
cCompile(src/"audiosource", "c")
cCompile(src/"filter/*.cpp")

cImport(incl/"soloud_c.h")

18 changes: 18 additions & 0 deletions src/wrapperspkg/paths.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

proc repoRoot*(): string =
# TODO: check whether nim/nimble has a syntax for that eg: "$projectDir/../src" (that one is different though; also, that probably can't be used to return a string?)
currentSourcePath.parentDir.parentDir.parentDir

proc reopBuildDir*(): string =
## all generated files go under here (gitignored)
repoRoot() / "build"

proc repoSrcDir*(): string =
repoRoot() / "src"

proc formulasDir*(): string =
repoSrcDir() / "wrapperspkg" / "formulas"

proc repoExePath*(): string =
repoRoot() / ("wrappers".addFileExt ExeExt)
1 change: 0 additions & 1 deletion src/wrapperspkg/submodule.nim

This file was deleted.

2 changes: 1 addition & 1 deletion tests/config.nims
Original file line number Diff line number Diff line change
@@ -1 +1 @@
switch("path", "$projectDir/../src")
switch("path", "$projectDir/../src")
41 changes: 37 additions & 4 deletions tests/twrappers.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
import unittest
import std/[os,unittest,strformat]

import wrapperspkg/submodule
import wrapperspkg/[paths]

test "placeholder test":
check getWelcomeMessage() == "Hello, World!"
proc warnSkipped(cmd: string) =
echo "CAUTION: test skipped: " & cmd

proc runCmdCheck(cmd: string) =
## calls `check`, ie on error, fail after all commands are run instead of immediately
echo (runCmdCheck: cmd)
let ret = execShellCmd(cmd)
if ret != 0:
echo "runCmdCheck failed: " & $(ret: ret, cmd: cmd)
check false

test "wrappers exe":
runCmdCheck &"nim c -r {repoSrcDir()}/wrappers.nim -h"

test "import wrappers":
#[
An alternative is to import wrappers directly without
running shell commands
pros: simpler, faster
cons: can't run the rest if some dependency for 1 test is missing
]#

let cmd = &"nim c -r {formulasDir()}/soloud/demo.nim -h"
if defined(OSX) or defined(Windows) or not existsEnv("TRAVIS"):
runCmdCheck cmd
else:
#[
travis ubuntu fails:
Error: execution of an external compiler program 'gcc -c -w -I/home/travis/.nimble/pkgs/build/soloud/include -DWITH_OSS -I/home/travis/.choosenim/toolchains/nim-0.19.2/lib -o /home/travis/.cache/nim/demo_d/soloud_wav.cpp.o /home/travis/.nimble/pkgs/build/soloud/src/audiosource/wav/soloud_wav.cpp' failed with exit code: 1
In file included from /home/travis/.nimble/pkgs/build/soloud/src/audiosource/wav/soloud_wav.cpp:34:0:
/home/travis/.nimble/pkgs/build/soloud/src/audiosource/wav/dr_flac.h:145:43: error: missing binary operator before token "("
#elif (defined(__clang__) && __has_feature(attribute_deprecated))
^
]#
warnSkipped cmd