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

Hydrogen python bindings #1313

Open
wants to merge 25 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c175f5d
Python bindings, second try
charbeljc Jul 3, 2021
c794279
ban more symbols
charbeljc Jul 3, 2021
6e012e6
compiles and loads with stock hydrogen dev branch
charbeljc Jul 3, 2021
0b68f86
typos
charbeljc Jul 3, 2021
3f4116e
missing includes for bindings
charbeljc Jul 3, 2021
626747f
integrate with build system
charbeljc Jul 3, 2021
9ccdd4f
group banned symbols add more __repr__() methods
charbeljc Jul 4, 2021
761b73e
add missing CMakeLists.txt
charbeljc Jul 6, 2021
767ba80
bind get/set method pairs as properties, ban Sample::get_{pan,velocit…
charbeljc Jul 6, 2021
ec1249c
build python bindings on linux
charbeljc Jul 6, 2021
eef2375
build python bindings on linux, second try with pip installed pybind11
charbeljc Jul 6, 2021
397a14e
[hydragen] option to export enum values
charbeljc Jul 6, 2021
401fd21
[hydragen] arithmetic on enum is opt-in
charbeljc Jul 6, 2021
09f67f8
ban more symbols, wrap abstract classes
charbeljc Jul 7, 2021
21a8f74
kill __class_name attribute
charbeljc Jul 7, 2021
d5cce31
wait for envelopes/envelope points
charbeljc Jul 7, 2021
08f3065
rework envelope, make envelope points lightweight
charbeljc Jul 4, 2021
749830d
sample editor: instant audiovisual feedback
charbeljc Jul 4, 2021
e5681e1
property support
charbeljc Jul 5, 2021
80928b2
ban more symbols
charbeljc Jul 7, 2021
728fb57
bug in hydragen enum code generator
charbeljc Jul 8, 2021
0327b33
ban a QColor constructor not present in appveyor's Qt version
charbeljc Jul 8, 2021
6be8c47
don't ban, shield
charbeljc Jul 8, 2021
7dcd01d
expose adsr state
charbeljc Jul 15, 2021
a68b3c7
Merge branch 'development' into hydragen_bindings
charbeljc Aug 8, 2021
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
4 changes: 3 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ for:
sudo apt-get update
sudo apt-get install -y clang qt5-default qttools5-dev qttools5-dev-tools libqt5xmlpatterns5-dev libarchive-dev libsndfile1-dev libasound2-dev libjack-jackd2-dev
sudo apt-get install -y liblo-dev libpulse-dev libportmidi-dev portaudio19-dev libcppunit-dev liblrdf-dev librubberband-dev ladspa-sdk
sudo apt-get install -y python3-dev python3-pip
sudo pip3 install "pybind11[global]"
sudo rm /usr/local/bin/doxygen

build_script: |-
git submodule init && git submodule update
mkdir build && cd build && cmake -DWANT_LASH=1 -DWANT_LRDF=1 -DWANT_RUBBERBAND=1 .. && make
mkdir build && cd build && cmake -DWANT_PYBINDINGS=1 -DWANT_LASH=1 -DWANT_LRDF=1 -DWANT_RUBBERBAND=1 .. && make

test_script: |-
TMPDIR=/tmp src/tests/tests --appveyor
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ ENDIF()

OPTION(WANT_CPPUNIT "Include CppUnit test suite" ON)
OPTION(FIXME_DISABLE_OPTIMIZATIONS "Fix broken builds by turning off optimizations" OFF)
OPTION(WANT_PYBINDINGS "Build python extension module" OFF)

include(Sanitizers)
INCLUDE(StatusSupportOptions)
Expand Down Expand Up @@ -400,6 +401,9 @@ ADD_SUBDIRECTORY(src/gui)
IF(EXISTS ${CMAKE_SOURCE_DIR}/data/doc/CMakeLists.txt)
ADD_SUBDIRECTORY(data/doc)
ENDIF()
IF(WANT_PYBINDINGS)
ADD_SUBDIRECTORY(src/bindings)
ENDIF()
INSTALL(DIRECTORY data DESTINATION ${H2_DATA_PATH} PATTERN ".git" EXCLUDE PATTERN "i18n" EXCLUDE PATTERN doc EXCLUDE)
IF(NOT MINGW AND NOT APPLE)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/linux/org.hydrogenmusic.Hydrogen.appdata.xml DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/appdata")
Expand Down
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

QTDIR=${QTDIR:-/usr/lib/qt}
VERBOSE=${VERBOSE:-0}
WANT_PYBINDINGS=${WANT_PYBINDINGS:-0}
CMAKE_OPTIONS="
-DCMAKE_COLOR_MAKEFILE=1 \
-DWANT_DEBUG=1 \
Expand All @@ -37,6 +38,9 @@ CMAKE_OPTIONS="
-DWANT_COREAUDIO=1 \
-DWANT_COREMIDI=1
"
if [ ${WANT_PYBINDINGS} -ne 0 ]; then
CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWANT_PYBINDINGS=1"
fi
MAKE_OPTS="-j 3"
H2FLAGS="-V0xf"
BUILD_DIR=./build
Expand Down
46 changes: 46 additions & 0 deletions src/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.4...3.18)

find_package(Python COMPONENTS Interpreter Development REQUIRED)
find_package(pybind11 CONFIG REQUIRED)

set(core_bindings_library "h2core")
set(CMAKE_AUTOMOC OFF)
set(CMAKE_AUTOUIC OFF)

set(core_wrapped_header ${CMAKE_CURRENT_SOURCE_DIR}/h2core_module.hpp)
# Add custom target to run binder to generate the binding cpp files.
set(core_generated_sources
${CMAKE_CURRENT_SOURCE_DIR}/h2core_module.cpp
)

add_library(${core_bindings_library} MODULE ${core_generated_sources})
target_link_libraries(${core_bindings_library} PRIVATE
pybind11::module pybind11::lto pybind11::windows_extras
hydrogen-core-${VERSION}
Qt5::Core
Qt5::Xml
Qt5::XmlPatterns
)

target_include_directories(${core_bindings_library} PRIVATE
${QT_INCLUDES}
# Apply relevant include and link flags.
${python_include_dir}
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/bindings/include
)

execute_process(COMMAND
"${_Python_EXECUTABLE}"
"-c"
"from distutils import sysconfig as s;print(s.get_python_lib(plat_specific=True), end='');"
RESULT_VARIABLE _PYTHON_SUCCESS
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES)
message("python site packages: [${PYTHON_SITE_PACKAGES}]")

pybind11_extension(${core_bindings_library})
install(TARGETS ${core_bindings_library}
LIBRARY DESTINATION "${PYTHON_SITE_PACKAGES}"
)
14 changes: 14 additions & 0 deletions src/bindings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Python Bindings

To generate bindings after a change in hydrogen headers/API,
install [HydraGen](https://github.com/charbeljc/HydraGen)

```bash
pip3 install git+https://github.com/charbeljc/HydraGen.git
```

Then, edit include_paths in `h2core.yaml` (sorry, this is work in progress), and finally
```bash
cd src/bindings
hydragen h2core.yaml .
```
1,414 changes: 1,414 additions & 0 deletions src/bindings/err

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/bindings/examples/test_SongPlay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import h2core
from h2core import Logger, Object, Filesystem, Preferences, Hydrogen, Song
import time
print(h2core)
# log_levels = Logger.log_levels
LogLevel = Logger.log_levels
logger = Logger.bootstrap(LogLevel.Debug | LogLevel.Info | LogLevel.Warning | LogLevel.Error)
Object.bootstrap(logger, True)
Filesystem.bootstrap(logger, "/usr/local/share/hydrogen/data/")
Preferences.create_instance()
prefs = Preferences.instance
Hydrogen.create_instance()
hydrogen = Hydrogen.instance
# dk = Drumkit.load_file(
# "/home/rebelcat/.hydrogen/data/drumkits/RoRBateria/drumkit.xml", False
# )
song = Song.load("/home/rebelcat/envelope_test.h2song")
hydrogen.song = song
hydrogen.sequencer_play()
time.sleep(3)
hydrogen.sequencer_stop()
# hydrogen.setSong(None)
print(song)
del song
del hydrogen
del prefs
del logger
print("alive:", Object.alive_object_count)

Loading