diff --git a/.gitignore b/.gitignore index bc87d63..a390d19 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,5 @@ compile_commands.json *_qmlcache.qrc +# Conan build dir +build/ diff --git a/README.md b/README.md index ac4d29c..e224d41 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # daw-project -Think about the name \ No newline at end of file + +## Build + diff --git a/conanfile.py b/conanfile.py index 9e57b7a..87a42a6 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,34 +1,24 @@ -import os from conan import ConanFile from conan.tools.meson import MesonToolchain, Meson -from conan.tools.layout import basic_layout -from conan.tools.files import copy +from conan.tools.gnu import PkgConfigDeps -class daw_expConan(ConanFile): - name = "daw-exp" - version = "1.0" - package_type = "library" - # Binary configuration +class daw_projectConan(ConanFile): + name = "daw-project" + version = "0.0.1" + package_type = "application" + settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False], "fPIC": [True, False]} - default_options = {"shared": False, "fPIC": True} - # Sources are located in the same place as this recipe, copy them to the recipe exports_sources = "meson.build", "src/*" - def config_options(self): - if self.settings.os == "Windows": - self.options.rm_safe("fPIC") - - def configure(self): - if self.options.shared: - self.options.rm_safe("fPIC") - def layout(self): - basic_layout(self) + self.folders.build = "build" + self.folders.generators = "build/scripts" def generate(self): + deps = PkgConfigDeps(self) + deps.generate() tc = MesonToolchain(self) tc.generate() @@ -40,6 +30,3 @@ class daw_expConan(ConanFile): def package(self): meson = Meson(self) meson.install() - - def package_info(self): - self.cpp_info.libs = ["daw-exp"] diff --git a/meson.build b/meson.build index 7bb58df..29ce0bb 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,8 @@ project('daw-exp ', 'cpp') -qt6 = import('qt6') + qt_dep = dependency('qt6', modules: ['Core', 'Widgets']) -exe = executable('myapp', 'src/main.cpp', - dependencies: [qt_dep], +jack_dep = dependency('jack', required : true) + +executable('daw-project', 'src/main.cpp', + dependencies: [qt_dep, jack_dep], install: true) diff --git a/src/main.cpp b/src/main.cpp index 428bdee..05a834e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,61 @@ -#include -#include +// src/main.cpp +#include +#include +#include +#include -int main(int argc, char *argv[]) { - QApplication app(argc, argv); - QLabel label("Hello from Qt + Meson + Conan!"); - label.show(); - return app.exec(); +static std::atomic g_client{nullptr}; +static float g_phase = 0.0f; +static const float kFreq = 440.0f; + +int process(jack_nframes_t nframes, void* arg) { + jack_port_t* port = static_cast(arg); + float* out = (float*)jack_port_get_buffer(port, nframes); + jack_client_t* client = g_client.load(); + if (!client) return 0; + + jack_nframes_t sr = jack_get_sample_rate(client); + for (jack_nframes_t i = 0; i < nframes; ++i) { + out[i] = std::sinf(g_phase); + g_phase += 2.0f * static_cast(M_PI) * kFreq / static_cast(sr); + if (g_phase > 2.0f * static_cast(M_PI)) g_phase -= 2.0f * static_cast(M_PI); + } + return 0; +} + +int main() { + jack_status_t status; + jack_client_t* client = jack_client_open("cpp_jack_player", JackNullOption, &status); + if (!client) { + std::cerr << "Failed to open JACK client (status=" << status << ")\n"; + return 1; + } + g_client.store(client); + + jack_port_t* outport = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE, + JackPortIsOutput, 0); + if (!outport) { + std::cerr << "Failed to register output port\n"; + jack_client_close(client); + return 1; + } + + if (jack_set_process_callback(client, process, outport) != 0) { + std::cerr << "Failed to set process callback\n"; + jack_client_close(client); + return 1; + } + + if (jack_activate(client) != 0) { + std::cerr << "Failed to activate JACK client\n"; + jack_client_close(client); + return 1; + } + + std::cout << "Client active. Connect " << jack_get_client_name(client) + << ":output to system:playback (e.g. with qjackctl). Press Enter to quit.\n"; + std::cin.get(); + + jack_client_close(client); + return 0; } diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 4f97134..254d1ef 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,26 +1,14 @@ import os from conan import ConanFile from conan.tools.build import can_run -from conan.tools.meson import MesonToolchain, Meson -from conan.tools.layout import basic_layout -class daw_expTestConan(ConanFile): +class daw_projectTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "PkgConfigDeps", "MesonToolchain" def requirements(self): self.requires(self.tested_reference_str) - def build(self): - meson = Meson(self) - meson.configure() - meson.build() - - def layout(self): - basic_layout(self) - def test(self): if can_run(self): - cmd = os.path.join(self.cpp.build.bindir, "example") - self.run(cmd, env="conanrun") + self.run("daw-project", env="conanrun") diff --git a/test_package/meson.build b/test_package/meson.build deleted file mode 100644 index 01ce3d6..0000000 --- a/test_package/meson.build +++ /dev/null @@ -1,3 +0,0 @@ -project('Testdaw-exp', 'cpp') -daw-exp = dependency('daw-exp', version : '>=0.1') -executable('example', 'src/example.cpp', dependencies: daw-exp) diff --git a/test_package/src/example.cpp b/test_package/src/example.cpp deleted file mode 100644 index 873a717..0000000 --- a/test_package/src/example.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "daw-exp.h" -#include -#include - -int main() { - daw_exp(); - - std::vector vec; - vec.push_back("test_package"); - - daw_exp_print_vector(vec); -}