cannam@162: # piper-vamp-js/examples/docker/Dockerfile cannam@162: # cannam@162: # Example of the whole process of taking an existing Vamp plugin cannam@162: # and turning it into a Piper Javascript module. cannam@162: # cannam@162: # The process is not automatic: you have to create a C++ main file and cannam@162: # adjust build properties in the Makefile. cannam@162: # cannam@162: # Normally you would create a repo for your converted module and keep cannam@162: # your newly-created files in that. (The other examples in this repo, cannam@162: # examples/vamp-example-plugins and examples/vamp-test-plugin, cannam@162: # illustrate that.) cannam@162: # cannam@162: # However in this example we will start with a Vamp plugin that we cannam@162: # have not yet written any of these files for, and illustrate creating cannam@162: # those -- although using batch processing tools rather than an cannam@162: # interactive editor. cannam@162: # cannam@162: # This is provided as a Docker file in order to ensure it can be cannam@162: # reproducibly run, and illustrate all the steps from a clean cannam@162: # environment. cannam@162: # cannam@162: # There are four phases to this: cannam@162: # cannam@162: # 1. Install prerequisite packages, download all needed repos, and cannam@162: # build dependencies and required tools. cannam@162: # cannam@162: # 2. Obtain the Vamp plugin that we are actually intending to convert, cannam@162: # and compile it in the normal way (i.e. as a C++ plugin) so that cannam@162: # the generator can load and examine it. cannam@162: # cannam@162: # 3. Make a new working folder for our conversion, generate an cannam@162: # initial version of the C++ main entry point for the module, and cannam@162: # edit anything that the generator got wrong. cannam@162: # cannam@162: # 4. Create a Makefile and run the JS module build. cannam@162: # cannam@162: # Let's go... cannam@162: # cannam@162: # (Using Arch Linux base: installing Emscripten on Ubuntu is a right cannam@162: # mess unless you want to recompile the whole thing) cannam@162: # cannam@162: FROM base/archlinux:2017.06.01 cannam@162: MAINTAINER Chris Cannam cannam@162: cannam@162: cannam@162: # Phase 1. Install prerequisite packages... cannam@162: # cannam@162: RUN echo 'Server = http://archlinux.mirrors.uk2.net/$repo/os/$arch' > /etc/pacman.d/mirrorlist cannam@162: RUN pacman --noconfirm -Syu && \ cannam@162: pacman --noconfirm -Sy \ cannam@162: gcc \ cannam@162: make \ cannam@162: boost \ cannam@162: pkg-config \ cannam@162: emscripten \ cannam@162: python \ cannam@162: jre8-openjdk-headless \ cannam@162: nodejs \ cannam@162: libsndfile \ cannam@162: curl \ cannam@162: git \ cannam@162: mercurial cannam@162: RUN rm -rf /var/cache/pacman/pkg/* cannam@162: ENV PATH $PATH:/usr/lib/emscripten cannam@162: RUN locale-gen en_US.UTF-8 cannam@162: ENV LANG en_US.UTF-8 cannam@162: # cannam@162: # ... download all needed repos, including this one! ... cannam@162: # cannam@162: RUN git clone https://github.com/piper-audio/piper cannam@162: RUN git clone https://github.com/piper-audio/piper-vamp-js cannam@162: RUN git clone https://github.com/piper-audio/piper-vamp-cpp cannam@162: RUN git clone https://github.com/c4dm/vamp-plugin-sdk cannam@162: RUN git clone https://github.com/c4dm/vamp-test-plugin cannam@162: # cannam@162: # ... and build the dependencies and required tools cannam@162: # cannam@162: WORKDIR vamp-plugin-sdk cannam@162: RUN ./configure && make && make install cannam@162: ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib cannam@162: WORKDIR .. cannam@162: WORKDIR piper-vamp-js cannam@162: # (Get the first run of Emscripten, which sets it up, out of the way) cannam@162: RUN em++ --version cannam@162: RUN make cannam@162: WORKDIR .. cannam@162: cannam@162: cannam@162: # Phase 2. Obtain the Vamp plugin that we are actually intending to cannam@162: # convert, and compile it in the normal way (i.e. as a C++ plugin) cannam@162: # so that the generator can load and examine it. cannam@162: # For this example we are going to convert the Simple Cepstral Pitch cannam@162: # Tracker plugin, see cannam@162: # https://code.soundsoftware.ac.uk/projects/cepstral-pitchtracker cannam@162: # cannam@162: RUN git clone https://github.com/cannam/cepstral-pitchtracker cannam@162: WORKDIR cepstral-pitchtracker cannam@162: RUN make -f Makefile.linux64 cannam@162: WORKDIR .. cannam@162: cannam@162: cannam@162: # Phase 3. Make a new working folder for our conversion... cannam@162: # cannam@162: RUN mkdir js-cepstral-pitchtracker cannam@162: WORKDIR js-cepstral-pitchtracker cannam@162: # cannam@162: # ... generate an initial version of the C++ main entry point for cannam@162: # the module... cannam@162: # cannam@162: RUN VAMP_PATH=../cepstral-pitchtracker \ cannam@162: ../piper-vamp-js/bin/piper-vamp-stub-generator cepstral-pitchtracker \ cannam@162: | tee cepstral-pitchtracker.cpp cannam@162: # cannam@162: # ... and edit anything that the generator got wrong. In this case, cannam@162: # the only problem is that it has written [cC]epstralPitchtracker where cannam@162: # the original code has [cC]epstralPitchTracker. Let's also remove the cannam@162: # prompt comments the generator included. cannam@162: # cannam@162: RUN perl -i -p -e 's/Pitchtracker/PitchTracker/g' cepstral-pitchtracker.cpp cannam@162: RUN perl -i -p -e 's,^//.*\n,,' cepstral-pitchtracker.cpp cannam@162: RUN cat cepstral-pitchtracker.cpp cannam@162: cannam@162: cannam@163: # Phase 4. Create a Makefile and run the JS module build. This is a cannam@163: # bit ugly because we're trying to stuff the whole content of the cannam@163: # Makefile into our Docker script! cannam@162: # cannam@162: RUN echo \ cannam@162: 'PIPER_VAMP_JS_DIR := ../piper-vamp-js\n\n\ cannam@162: PLUGIN_DIR := ../cepstral-pitchtracker\n\ cannam@162: SRC_DIR := $(PLUGIN_DIR)\n\n\ cannam@162: MODULE_NAME := CepstralPitchTracker\n\ cannam@162: MODULE_SOURCE := cepstral-pitchtracker.cpp\n\n\ cannam@162: PLUGIN_SOURCES := $(SRC_DIR)/AgentFeeder.cpp $(SRC_DIR)/CepstralPitchTracker.cpp $(SRC_DIR)/NoteHypothesis.cpp $(SRC_DIR)/PeakInterpolator.cpp\n\n\ cannam@162: INCLUDES := -I$(SRC_DIR)\n\n\ cannam@162: include $(PIPER_VAMP_JS_DIR)/Makefile.inc' | sed 's/\\n/\n/g' > Makefile cannam@162: RUN cat Makefile cannam@162: RUN make em cannam@162: RUN ls -l cannam@162: RUN make test cannam@162: