├── README ├── knob.png ├── led_on.png ├── led_off.png ├── .gitignore ├── manifest.ttl ├── drmr_hydrogen.h ├── Makefile.legacy ├── nknob.h ├── CMakeLists.txt ├── README.md ├── drmr.h ├── nknob.c ├── drmr_hydrogen.c ├── drmr.c ├── drmr.ttl ├── drmr_ui.c └── COPYING /README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /knob.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falkTX/drmr/HEAD/knob.png -------------------------------------------------------------------------------- /led_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falkTX/drmr/HEAD/led_on.png -------------------------------------------------------------------------------- /led_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/falkTX/drmr/HEAD/led_off.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | drmr.so 2 | drmr_ui.xml 3 | drmr_ui.so 4 | drmr.lv2 5 | build 6 | /logo.xcf 7 | /htest 8 | /knobt 9 | -------------------------------------------------------------------------------- /manifest.ttl: -------------------------------------------------------------------------------- 1 | @prefix lv2: . 2 | @prefix rdfs: . 3 | 4 | a lv2:Plugin; 5 | rdfs:seeAlso . -------------------------------------------------------------------------------- /drmr_hydrogen.h: -------------------------------------------------------------------------------- 1 | /* drmr_hydrogen.h 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * Public License v3. source code is available at 6 | * 7 | 8 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | 18 | #ifndef DRMR_HYDRO_H 19 | #define DRMR_HYDRO_H 20 | 21 | kits* scan_kits(); 22 | void free_kits(kits* kits); 23 | void free_samples(drmr_sample* samples, int num_samples); 24 | int load_sample(char* path,drmr_layer* layer,double target_rate); 25 | drmr_sample *load_hydrogen_kit(char *path, double rate, int *num_samples); 26 | 27 | #endif // DRMR_HYDRO_H 28 | -------------------------------------------------------------------------------- /Makefile.legacy: -------------------------------------------------------------------------------- 1 | BUNDLE = drmr.lv2 2 | INSTALL_DIR = /usr/local/lib/lv2 3 | CC=gcc 4 | 5 | $(BUNDLE): manifest.ttl drmr.ttl drmr.so drmr_ui.so knob.png 6 | rm -rf $(BUNDLE) 7 | mkdir $(BUNDLE) 8 | cp manifest.ttl drmr.ttl drmr.so drmr_ui.so knob.png $(BUNDLE) 9 | 10 | drmr.so: drmr.c drmr_hydrogen.c 11 | $(CC) -shared -Wall -fPIC -DPIC drmr.c drmr_hydrogen.c `pkg-config --cflags --libs lv2-plugin sndfile samplerate` -lexpat -lm -o drmr.so 12 | 13 | drmr_ui.so: drmr_ui.c drmr_hydrogen.c nknob.c 14 | $(CC) -DINSTALL_DIR=\"$(INSTALL_DIR)\" -shared -Wall -fPIC -DPIC drmr_ui.c drmr_hydrogen.c nknob.c `pkg-config --cflags --libs lv2-plugin gtk+-2.0 sndfile samplerate` -lexpat -lm -o drmr_ui.so 15 | 16 | htest: drmr_hydrogen.c 17 | $(CC) -D_TEST_HYDROGEN_PARSER -Wall -fPIC -DPIC drmr_hydrogen.c `pkg-config --cflags --libs sndfile samplerate` -lexpat -lm -o htest 18 | 19 | knobt: nknob.c 20 | $(CC) -D_TEST_N_KNOB -DINSTALL_DIR=\"$(INSTALL_DIR)\" -Wall -fPIC -DPIC nknob.c `pkg-config --cflags --libs gtk+-2.0 ` -lm -o knobt 21 | 22 | install: $(BUNDLE) 23 | mkdir -p $(INSTALL_DIR) 24 | rm -rf $(INSTALL_DIR)/$(BUNDLE) 25 | cp -R $(BUNDLE) $(INSTALL_DIR) 26 | 27 | clean: 28 | rm -rf $(BUNDLE) drmr.so drmr_ui.so -------------------------------------------------------------------------------- /nknob.h: -------------------------------------------------------------------------------- 1 | /* nknob.h 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * NKnob - A simplified version of phatknob that just is a new gui 6 | * over a GtkRange (i.e. it can be used exactly like a 7 | * GtkRange from the outside) 8 | * 9 | * From PhatKnob code: 10 | * Most of this code comes from gAlan 0.2.0, copyright (C) 1999 11 | * Tony Garnock-Jones, with modifications by Sean Bolton, 12 | * copyright (c) 2004. (gtkdial.c rolls over in its grave.) 13 | * 14 | * Phatised by Loki Davison. 15 | * 16 | * GNU Public License v3. source code is available at 17 | * 18 | * 19 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 20 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 22 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 23 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 24 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 25 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 26 | * 27 | */ 28 | 29 | 30 | #if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) 31 | #error "Only can be included directly." 32 | #endif 33 | 34 | #ifndef __NKNOB_H__ 35 | #define __NKNOB_H__ 36 | 37 | #include 38 | 39 | G_BEGIN_DECLS 40 | 41 | #define N_TYPE_KNOB (n_knob_get_type ( )) 42 | #define N_KNOB(obj) GTK_CHECK_CAST(obj, n_knob_get_type(), NKnob) 43 | #define N_KNOB_CLASS(klass) GTK_CHECK_CLASS_CAST(klass, n_knob_get_type(), NKnobClass) 44 | #define N_IS_KNOB(obj) GTK_CHECK_TYPE(obj, n_knob_get_type()) 45 | #define N_IS_KNOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), N_TYPE_KNOB)) 46 | #define N_KNOB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), N_TYPE_KNOB, NKnobClass)) 47 | 48 | 49 | typedef struct _NKnob NKnob; 50 | typedef struct _NKnobClass NKnobClass; 51 | 52 | struct _NKnob { 53 | GtkRange range; 54 | 55 | /* image prefix */ 56 | gchar *load_prefix; 57 | 58 | /* State of widget (to do with user interaction) */ 59 | guint8 state; 60 | gint saved_x, saved_y; 61 | 62 | /* size of the widget */ 63 | gint size; 64 | 65 | /* Pixmap for knob */ 66 | GdkPixbuf *pixbuf; 67 | }; 68 | 69 | struct _NKnobClass { 70 | GtkRangeClass parent_class; 71 | }; 72 | 73 | GType n_knob_get_type ( ) G_GNUC_CONST; 74 | 75 | GtkWidget* n_knob_new (GtkAdjustment* adjustment); 76 | 77 | GtkWidget* n_knob_new_with_range (double value, 78 | double lower, 79 | double upper, 80 | double step); 81 | 82 | void n_knob_set_load_prefix(NKnob* knob, gchar* prefix); 83 | gchar* n_knob_get_load_prefix(NKnob* knob); 84 | 85 | G_END_DECLS 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #CMake file for DrMr 2 | 3 | cmake_minimum_required(VERSION 2.6) 4 | project (DrMr) 5 | 6 | set(LV2_INSTALL_DIR lib/lv2 CACHE PATH "Specifies where the LV2 libraries should be installed") 7 | set(CMAKE_C_FLAGS "-Wall") 8 | 9 | # Availble options 10 | option(USE_NKNOB "Use custom NKnob widgets for gain/pan instead of Gtk sliders" ON) 11 | SET(SAMP_ZERO_POS "0" CACHE STRING "Default sample zero position 0=top left (tl) 1=bl 2=tr 3=br") 12 | 13 | # check for our various libraries 14 | find_package(PkgConfig) 15 | pkg_check_modules(LV2 REQUIRED lv2>=0.1.0) 16 | pkg_check_modules(SNDFILE REQUIRED sndfile>=1.0.20) 17 | pkg_check_modules(SAMPLERATE REQUIRED samplerate>=0.1.5) 18 | pkg_check_modules (GTK2 REQUIRED gtk+-2.0>=2.22.0) 19 | find_package (EXPAT REQUIRED) 20 | 21 | include_directories (${LV2_INCLUDE_DIRS} ${EXPAT_INCLUDE_DIRS} ${SNDFILE_INCLUDE_DIRS} ${SAMPLERATE_INCLUDE_DIRS} ${GTK2_INCLUDE_DIRS}) 22 | link_directories (${LV2_LIBRARY_DIRS} ${EXPAT_LIBRARY_DIRS} ${SNDFILE_LIBRARY_DIRS} ${SAMPLERATE_LIBRARY_DIRS} ${GTK2_LIBRARY_DIRS}) 23 | 24 | # config libraries 25 | 26 | add_library(drmr SHARED 27 | drmr.c 28 | drmr_hydrogen.c 29 | drmr.h 30 | drmr_hydrogen.h 31 | ) 32 | 33 | add_library(drmr_ui SHARED 34 | drmr_ui.c 35 | drmr_hydrogen.c 36 | nknob.c 37 | drmr_hydrogen.h 38 | nknob.h 39 | ) 40 | 41 | set_target_properties(drmr PROPERTIES PREFIX "") 42 | set_target_properties(drmr_ui PROPERTIES PREFIX "") 43 | set_target_properties(drmr_ui 44 | PROPERTIES 45 | LINK_FLAGS "-Wl,-znodelete" 46 | ) 47 | 48 | target_link_libraries(drmr ${LV2_LIBRARIES} ${SNDFILE_LIBRARIES} ${SAMPLERATE_LIBRARIES} ${EXPAT_LIBRARIES} m) 49 | target_link_libraries(drmr_ui ${LV2_LIBRARIES} ${GTK2_LIBRARIES} ${SNDFILE_LIBRARIES} ${SAMPLERATE_LIBRARIES} ${EXPAT_LIBRARIES} m) 50 | 51 | 52 | add_definitions ( -DPIC ) 53 | 54 | set_target_properties (drmr 55 | PROPERTIES 56 | COMPILE_FLAGS "-std=gnu99" 57 | ) 58 | 59 | set (ui_compile_flags "-std=gnu99") 60 | 61 | if (NOT USE_NKNOB) 62 | set (ui_compile_flags "${ui_compile_flags} -DNO_NKNOB") 63 | endif (NOT USE_NKNOB) 64 | 65 | if (SAMP_ZERO_POS GREATER "-1" AND SAMP_ZERO_POS LESS "4") 66 | set (ui_compile_flags "${ui_compile_flags} -DDRMR_UI_ZERO_SAMP=${SAMP_ZERO_POS}") 67 | else (SAMP_ZERO_POS GREATER "-1" AND SAMP_ZERO_POS LESS "4") 68 | message(WARNING "Invalid SAMP_ZERO_POS, defaulting to 0 \(top left\). Valid values are 0,1,2,3") 69 | set (ui_compile_flags "${ui_compile_flags} -DDRMR_UI_ZERO_SAMP=0") 70 | endif (SAMP_ZERO_POS GREATER "-1" AND SAMP_ZERO_POS LESS "4") 71 | 72 | set_target_properties (drmr_ui 73 | PROPERTIES 74 | COMPILE_FLAGS ${ui_compile_flags} 75 | ) 76 | 77 | # Custom test commands 78 | add_executable ( htest 79 | EXCLUDE_FROM_ALL 80 | drmr_hydrogen.c 81 | ) 82 | 83 | add_executable ( knobt 84 | EXCLUDE_FROM_ALL 85 | nknob.c 86 | ) 87 | 88 | # config test executables 89 | target_link_libraries(htest ${LV2_LIBRARIES} ${GTK2_LIBRARIES} ${SNDFILE_LIBRARIES} ${SAMPLERATE_LIBRARIES} ${EXPAT_LIBRARIES} m) 90 | set_target_properties ( htest 91 | PROPERTIES 92 | COMPILE_FLAGS "-D_TEST_HYDROGEN_PARSER" 93 | ) 94 | target_link_libraries(knobt ${LV2_LIBRARIES} ${GTK2_LIBRARIES} ${SNDFILE_LIBRARIES} ${SAMPLERATE_LIBRARIES} ${EXPAT_LIBRARIES} m) 95 | set_target_properties ( knobt 96 | PROPERTIES 97 | COMPILE_FLAGS "-D_TEST_N_KNOB" 98 | ) 99 | 100 | # config install 101 | install(TARGETS drmr drmr_ui 102 | LIBRARY 103 | DESTINATION ${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}/drmr.lv2 104 | ) 105 | 106 | install (FILES manifest.ttl drmr.ttl knob.png led_on.png led_off.png 107 | DESTINATION ${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}/drmr.lv2 108 | ) 109 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DrMr 2 | ==== 3 | 4 | DrMr is an LV2 sampler plugin. It's main reason to exist is to give a way for lv2 hosts to have a built in drum synth that can save its entire state (i.e. no need to go out to external tools and no need to save extra state). See the wiki (click the wiki tab above) for some screenshots. DrMr currently supports the following: 5 | 6 | - Control via midi 7 | - Scan for and load hydrogen drum kits (see note 2) 8 | - Multi-layer hydrogen kits (will pick layer based on that samples set gain) 9 | - LV2 controls for gain on first 32 samples of kit (see note 1 below) 10 | - LV2 controls for pan on first 32 samples of kit (see note 1 below) 11 | - GTK ui that can select a kit and control gain/pan on each sample 12 | - Custom knob widget for GTK ui based on phatknob that is both functional and awesome looking. (see wiki for screenshot) 13 | - Sample grid can start in any corner of the window, to match the layout of your controller. 14 | 15 | Hopefully coming soon: 16 | 17 | - Creating / Saving custom kits on a per sample basis using the GTK UI 18 | - ASDR envelope on samples (Will be automatable and controllable in the UI) 19 | 20 | 21 | DrMr is a new project, so the code should be considered alpha. Bug reports are much appreciated. 22 | 23 | Regarding This Branch 24 | --------------------- 25 | 26 | This (lv2unstable) branch of DrMr uses the lv2-atom and lv2-state extensions, which are both experimental lv2 extensions. As such, you'll need to have the svn version of lv2 installed (see [here](http://lv2plug.in/trac/wiki/SVN_repository) for info about how to install lv2 from svn). You'll also need a host that supports these extensions. Known working hosts are [jalv](http://drobilla.net/software/jalv/) and [ardour3](http://ardour.org/download_full), both from svn (i.e. Ardour3-beta3 won't work). Using these new extensions allows DrMr to have a number of new and planned features. 27 | 28 | The intention is to have this version become the main stable version as the lv2 spec stabilizes and more hosts support the required extensions. 29 | 30 | New features include: 31 | 32 | - Kits are now selected via their path and not the hacky integer port as before 33 | - The kit path is now saved and restored using lv2-state, so you can install/remove/modify hydrogen kits and your state won't be messed up. 34 | - No need to scan kits in the plugin core so the plugin loads faster 35 | - Led indicator in the UI when a sample is triggered 36 | - Led indicator can be clicked to trigger sample for preview 37 | 38 | Coming soon features: 39 | 40 | - Loading of individual samples into each slot (so you can tweak the kit to use your own samples). New sample locations will also be saved using lv2-state so modifications will be persistent. 41 | - New kit creation and saving (a bit further down the road) 42 | 43 | 44 | One thing to note is that the kit index port has been removed. This means if you have projects using the master branch version of plugin you should note the kit externally as that state will not be reloaded. 45 | 46 | Download 47 | -------- 48 | Only via git for now, just check out this repo 49 | 50 | Compilation and Install 51 | ----------------------- 52 | DrMr is built with [CMake](http://www.cmake.org). 53 | 54 | To build it simply do (from this dir): 55 | 56 | mkdir build 57 | cd build 58 | cmake .. (or "cmake -DUSE_NKNOB=OFF .." if you want old style sliders) 59 | 60 | Then do: 61 | 62 | make 63 | make install 64 | 65 | to install. There are some customizable variables for cmake. To see them do "cmake -L". The important ones are: 66 | 67 | USE_NKNOB - Use custom knob widget for controls instead of the default gtk sliders. This defaults to ON. Try turning it off if you are experiencing problems, or just prefer the sliders. 68 | 69 | SAMP_ZERO_POS - Controls where sample zero will position itself in the sample table. This is just the default value, and can be changed in the ui when DrMr is running. Valid values are: 70 | 71 | 0 - Top Left (default) 72 | 1 - Bottom Right (This will align with many drum machines and MIDI pads) 73 | 2 - Top Right 74 | 3 - Bottom Right 75 | Any other value will emit a warning and use 0. 76 | 77 | LV2_INSTALL_DIR - The directory to install the DrMr plugin to. To install to your home directory, use "~/.lv2" and clear the CMAKE_INSTALL_PREFIX. This defaults to "lib/lv2" (this is relative to CMAKE_INSTALL_PREFIX, which is usually /usr/local) 78 | 79 | You can also use "ccmake .." or "cmake-gui .." for a more interactive configuration process. 80 | 81 | A legacy Makefile is included, that will possibly work for you if you don't want to use cmake. To use it just do (from this dir): 82 | 83 | make -f Makefile.legacy 84 | make -f Makefile.legacy install 85 | 86 | You'll need the following libraries to build and install DrMr: 87 | 88 | - [libsndfile](http://www.mega-nerd.com/libsndfile/) 89 | - [libsamplerate](http://www.mega-nerd.com/SRC/index.html) 90 | - [lv2](http://lv2plug.in/) 91 | - [libexpat](http://expat.sourceforge.net) 92 | - [gtk+](http://www.gtk.org) 93 | 94 | DrMr scans the following directories for hydrogen drum kits: 95 | 96 | - /usr/share/hydrogen/data/drumkits/ 97 | - /usr/local/share/hydrogen/data/drumkits/ 98 | - /usr/share/drmr/drumkits/ 99 | - ~/.hydrogen/data/drumkits/ 100 | - ~/.drmr/drumkits/ 101 | 102 | If you want to add others, add them to the default_drumkit_locations array at the top of drmr_hydrogen.c 103 | 104 | ### Note 1 105 | DrMr is currently using a static ttl file. This means I have to decide statically how many gain/pan controls to expose. I've settled on 32 for the moment, but that is arbitrary. At some point DrMr will probably move to using the LV2 Dynamic Manifest feature to expose the appropriate number of gain controls for the current sample set, although how force a host update of the manifest when the kit is changed is unclear (if you know how, please let me know) 106 | 107 | ### Note 2 108 | DrMr only currently supports a subset of things that can be specified in a hydrogen drumkit.xml file. Specifically, DrMr will not use gain/pan/pitch/asdr information. DrMr basically only uses the filename and layer min/max information to build it's internal sample representation. Values specified in .xml files will be used as DrMr begins to support the features needed for those values to make sense. -------------------------------------------------------------------------------- /drmr.h: -------------------------------------------------------------------------------- 1 | /* drmr.h 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * Public License v3. source code is available at 6 | * 7 | 8 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #ifndef DRMR_H 18 | #define DRMR_H 19 | 20 | #include 21 | #include 22 | 23 | #include "lv2/lv2plug.in/ns/ext/atom/forge.h" 24 | // util includes atom.h 25 | #include "lv2/lv2plug.in/ns/ext/atom/util.h" 26 | #include "lv2/lv2plug.in/ns/lv2core/lv2.h" 27 | #include "lv2/lv2plug.in/ns/ext/urid/urid.h" 28 | #include "lv2/lv2plug.in/ns/ext/state/state.h" 29 | 30 | // drumkit scanned from a hydrogen xml file 31 | typedef struct { 32 | char* name; 33 | char* desc; 34 | char* path; 35 | char** sample_names; 36 | int samples; 37 | } scanned_kit; 38 | 39 | typedef struct { 40 | int num_kits; 41 | scanned_kit* kits; 42 | } kits; 43 | 44 | // libsndfile stuff 45 | 46 | typedef struct { 47 | float min; 48 | float max; 49 | 50 | SF_INFO *info; 51 | uint32_t limit; 52 | float* data; 53 | } drmr_layer; 54 | 55 | typedef struct { 56 | SF_INFO *info; 57 | char active; 58 | uint32_t offset; 59 | uint32_t limit; 60 | uint32_t layer_count; 61 | float velocity; 62 | drmr_layer *layers; 63 | float* data; 64 | int dataoffset; 65 | } drmr_sample; 66 | 67 | // lv2 stuff 68 | 69 | #define DRMR_URI "http://github.com/nicklan/drmr" 70 | #define GAIN_MIN -60.0f 71 | #define GAIN_MAX 6.0f 72 | 73 | typedef enum { 74 | DRMR_CONTROL = 0, 75 | DRMR_LEFT, 76 | DRMR_RIGHT, 77 | DRMR_BASENOTE, 78 | DRMR_GAIN_ONE, 79 | DRMR_GAIN_TWO, 80 | DRMR_GAIN_THREE, 81 | DRMR_GAIN_FOUR, 82 | DRMR_GAIN_FIVE, 83 | DRMR_GAIN_SIX, 84 | DRMR_GAIN_SEVEN, 85 | DRMR_GAIN_EIGHT, 86 | DRMR_GAIN_NINE, 87 | DRMR_GAIN_TEN, 88 | DRMR_GAIN_ELEVEN, 89 | DRMR_GAIN_TWELVE, 90 | DRMR_GAIN_THIRTEEN, 91 | DRMR_GAIN_FOURTEEN, 92 | DRMR_GAIN_FIFTEEN, 93 | DRMR_GAIN_SIXTEEN, 94 | DRMR_GAIN_SEVENTEEN, 95 | DRMR_GAIN_EIGHTEEN, 96 | DRMR_GAIN_NINETEEN, 97 | DRMR_GAIN_TWENTY, 98 | DRMR_GAIN_TWENTYONE, 99 | DRMR_GAIN_TWENTYTWO, 100 | DRMR_GAIN_TWENTYTHREE, 101 | DRMR_GAIN_TWENTYFOUR, 102 | DRMR_GAIN_TWENTYFIVE, 103 | DRMR_GAIN_TWENTYSIX, 104 | DRMR_GAIN_TWENTYSEVEN, 105 | DRMR_GAIN_TWENTYEIGHT, 106 | DRMR_GAIN_TWENTYNINE, 107 | DRMR_GAIN_THIRTY, 108 | DRMR_GAIN_THIRTYONE, 109 | DRMR_GAIN_THIRTYTWO, 110 | DRMR_PAN_ONE, 111 | DRMR_PAN_TWO, 112 | DRMR_PAN_THREE, 113 | DRMR_PAN_FOUR, 114 | DRMR_PAN_FIVE, 115 | DRMR_PAN_SIX, 116 | DRMR_PAN_SEVEN, 117 | DRMR_PAN_EIGHT, 118 | DRMR_PAN_NINE, 119 | DRMR_PAN_TEN, 120 | DRMR_PAN_ELEVEN, 121 | DRMR_PAN_TWELVE, 122 | DRMR_PAN_THIRTEEN, 123 | DRMR_PAN_FOURTEEN, 124 | DRMR_PAN_FIFTEEN, 125 | DRMR_PAN_SIXTEEN, 126 | DRMR_PAN_SEVENTEEN, 127 | DRMR_PAN_EIGHTEEN, 128 | DRMR_PAN_NINETEEN, 129 | DRMR_PAN_TWENTY, 130 | DRMR_PAN_TWENTYONE, 131 | DRMR_PAN_TWENTYTWO, 132 | DRMR_PAN_TWENTYTHREE, 133 | DRMR_PAN_TWENTYFOUR, 134 | DRMR_PAN_TWENTYFIVE, 135 | DRMR_PAN_TWENTYSIX, 136 | DRMR_PAN_TWENTYSEVEN, 137 | DRMR_PAN_TWENTYEIGHT, 138 | DRMR_PAN_TWENTYNINE, 139 | DRMR_PAN_THIRTY, 140 | DRMR_PAN_THIRTYONE, 141 | DRMR_PAN_THIRTYTWO, 142 | DRMR_CORE_EVENT, 143 | DRMR_NUM_PORTS 144 | } DrMrPortIndex; 145 | 146 | typedef struct { 147 | LV2_URID midi_event; 148 | LV2_URID ui_msg; 149 | LV2_URID kit_path; 150 | LV2_URID atom_eventTransfer; 151 | LV2_URID atom_resource; 152 | LV2_URID string_urid; 153 | LV2_URID bool_urid; 154 | LV2_URID int_urid; 155 | LV2_URID get_state; 156 | LV2_URID midi_info; 157 | LV2_URID sample_trigger; 158 | LV2_URID velocity_toggle; 159 | LV2_URID note_off_toggle; 160 | LV2_URID zero_position; 161 | } drmr_uris; 162 | 163 | typedef struct { 164 | // Ports 165 | float* left; 166 | float* right; 167 | LV2_Atom_Sequence *control_port; 168 | LV2_Atom_Sequence *core_event_port; 169 | 170 | LV2_Atom_Forge forge; 171 | 172 | // params 173 | bool ignore_velocity; 174 | bool ignore_note_off; 175 | int zero_position; 176 | float** gains; 177 | float** pans; 178 | float* baseNote; 179 | double rate; 180 | 181 | // URIs 182 | LV2_URID_Map* map; 183 | drmr_uris uris; 184 | 185 | // Kit info 186 | char* current_path; 187 | char** request_buf; 188 | int curReq; 189 | 190 | // Samples 191 | drmr_sample* samples; 192 | uint8_t num_samples; 193 | 194 | // loading thread stuff 195 | pthread_mutex_t load_mutex; 196 | pthread_cond_t load_cond; 197 | pthread_t load_thread; 198 | 199 | } DrMr; 200 | 201 | static inline 202 | void map_drmr_uris(LV2_URID_Map *map, 203 | drmr_uris *uris) { 204 | uris->midi_event = 205 | map->map(map->handle, 206 | "http://lv2plug.in/ns/ext/midi#MidiEvent"); 207 | uris->string_urid = 208 | map->map(map->handle, LV2_ATOM__String); 209 | uris->bool_urid = 210 | map->map(map->handle, LV2_ATOM__Bool); 211 | uris->int_urid = 212 | map->map(map->handle, LV2_ATOM__Int); 213 | uris->ui_msg = 214 | map->map(map->handle, 215 | DRMR_URI "#uimsg"); 216 | uris->kit_path = 217 | map->map(map->handle, 218 | DRMR_URI "#kitpath"); 219 | uris->get_state = 220 | map->map(map->handle, 221 | DRMR_URI "#getstate"); 222 | uris->midi_info = 223 | map->map(map->handle, 224 | DRMR_URI "#midiinfo"); 225 | uris->sample_trigger = 226 | map->map(map->handle, 227 | DRMR_URI "#sampletrigger"); 228 | uris->velocity_toggle = 229 | map->map(map->handle, 230 | DRMR_URI "#velocitytoggle"); 231 | uris->note_off_toggle = 232 | map->map(map->handle, 233 | DRMR_URI "#noteofftoggle"); 234 | uris->zero_position = 235 | map->map(map->handle, 236 | DRMR_URI "#zeroposition"); 237 | uris->atom_eventTransfer = 238 | map->map(map->handle, LV2_ATOM__eventTransfer); 239 | uris->atom_resource = 240 | map->map(map->handle, LV2_ATOM__Resource); 241 | } 242 | 243 | 244 | #endif // DRMR_H 245 | -------------------------------------------------------------------------------- /nknob.c: -------------------------------------------------------------------------------- 1 | /* nknob.c 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * NKnob - A simplified version of phatknob that just is a new gui 6 | * over a GtkRange (i.e. it can be used exactly like a 7 | * GtkRange from the outside) 8 | * 9 | * In addition, this knob makes the drmr_ui.so module memory resident 10 | * so it can avoid attempting to re-load itself when shown/hidden in 11 | * a ui. 12 | * 13 | * From PhatKnob code: 14 | * Most of this code comes from gAlan 0.2.0, copyright (C) 1999 15 | * Tony Garnock-Jones, with modifications by Sean Bolton, 16 | * copyright (c) 2004. (gtkdial.c rolls over in its grave.) 17 | * 18 | * Phatised by Loki Davison. 19 | * 20 | * GNU Public License v3. source code is available at 21 | * 22 | * 23 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 24 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 25 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 26 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 27 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 28 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 29 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 30 | * 31 | */ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "nknob.h" 39 | 40 | #define SCROLL_DELAY_LENGTH 100 41 | #define KNOB_SIZE 50 42 | 43 | enum { 44 | STATE_IDLE, 45 | STATE_PRESSED, 46 | STATE_DRAGGING, 47 | STATE_SCROLL, 48 | }; 49 | 50 | 51 | /* properties */ 52 | enum 53 | { 54 | PROP_0, /* oops, no props any more */ 55 | }; 56 | 57 | static void n_knob_class_init (NKnobClass *klass); 58 | static void n_knob_init (NKnob *knob); 59 | static void n_knob_destroy (GtkObject *object); 60 | static void n_knob_realize (GtkWidget *widget); 61 | static void n_knob_size_request (GtkWidget *widget, 62 | GtkRequisition *requisition); 63 | static gint n_knob_expose (GtkWidget *widget, 64 | GdkEventExpose *event); 65 | static gint n_knob_button_press (GtkWidget *widget, 66 | GdkEventButton *event); 67 | static gint n_knob_button_release (GtkWidget *widget, 68 | GdkEventButton *event); 69 | static gint n_knob_motion_notify (GtkWidget *widget, 70 | GdkEventMotion *event); 71 | static gint n_knob_scroll (GtkWidget *widget, 72 | GdkEventScroll *event); 73 | static void n_knob_update_mouse (NKnob *knob, 74 | gint x, 75 | gint y, 76 | gboolean absolute); 77 | 78 | 79 | static void n_knob_set_property (GObject *object, 80 | guint prop_id, 81 | const GValue *value, 82 | GParamSpec *pspec); 83 | static void n_knob_get_property (GObject *object, 84 | guint prop_id, 85 | GValue *value, 86 | GParamSpec *pspec); 87 | 88 | GError *gerror; 89 | 90 | /* global pixbufs for less mem usage */ 91 | static GdkPixbuf **pixbuf = NULL; 92 | 93 | // Can't use G_DEFINE_TYPE because ardour is at gtk 2.22 94 | static NKnobClass *parent_class; 95 | GType 96 | n_knob_get_type (void) { 97 | static GType nknob_type; 98 | if (!nknob_type) { 99 | static const GTypeInfo object_info = { 100 | sizeof (NKnobClass), 101 | (GBaseInitFunc) NULL, 102 | (GBaseFinalizeFunc) NULL, 103 | (GClassInitFunc) n_knob_class_init, 104 | (GClassFinalizeFunc) NULL, 105 | NULL, // class data 106 | sizeof (NKnob), 107 | 0, // preallocs 108 | (GInstanceInitFunc) n_knob_init, 109 | NULL // value table 110 | }; 111 | nknob_type = g_type_register_static(GTK_TYPE_RANGE,"NKnob",&object_info,0); 112 | } 113 | return nknob_type; 114 | } 115 | 116 | static void n_knob_class_init (NKnobClass *klass) { 117 | GtkObjectClass *object_class; 118 | GtkWidgetClass *widget_class; 119 | GObjectClass *g_object_class; 120 | 121 | object_class = GTK_OBJECT_CLASS(klass); 122 | widget_class = GTK_WIDGET_CLASS(klass); 123 | g_object_class = G_OBJECT_CLASS(klass); 124 | 125 | parent_class = g_type_class_peek_parent (klass); 126 | 127 | g_object_class->set_property = n_knob_set_property; 128 | g_object_class->get_property = n_knob_get_property; 129 | 130 | object_class->destroy = n_knob_destroy; 131 | 132 | widget_class->realize = n_knob_realize; 133 | widget_class->expose_event = n_knob_expose; 134 | widget_class->size_request = n_knob_size_request; 135 | widget_class->button_press_event = n_knob_button_press; 136 | widget_class->button_release_event = n_knob_button_release; 137 | widget_class->motion_notify_event = n_knob_motion_notify; 138 | widget_class->scroll_event = n_knob_scroll; 139 | } 140 | 141 | static gboolean tooltip_callback(GtkWidget *widget, 142 | gint x, 143 | gint y, 144 | gboolean keyboard_mode, 145 | GtkTooltip *tooltip, 146 | gpointer user_data) { 147 | if (gtk_widget_get_has_tooltip(widget)) { 148 | gchar buf[16]; 149 | snprintf(buf,16,"%.2f",gtk_range_get_value(GTK_RANGE(widget))); 150 | gtk_tooltip_set_text(tooltip,buf); 151 | return TRUE; 152 | } 153 | return FALSE; 154 | } 155 | 156 | static void n_knob_init (NKnob *knob) { 157 | knob->state = STATE_IDLE; 158 | knob->saved_x = knob->saved_y = 0; 159 | knob->size = KNOB_SIZE; 160 | knob->pixbuf = NULL; 161 | knob->load_prefix = NULL; 162 | g_signal_connect(G_OBJECT(knob),"query-tooltip",G_CALLBACK(tooltip_callback),NULL); 163 | } 164 | 165 | 166 | /** 167 | * n_knob_new: 168 | * @adjustment: a #GtkAdjustment or NULL 169 | * 170 | * Creates a new #NKnob with the supplied 171 | * #GtkAdjustment. if adjustment is NULL or 172 | * invalid, a new #GtkAdjustment will be created 173 | * with the default values of: 174 | * 0.0, 0.0, 10.0, 0.1, 0.1, 0.2 175 | * 176 | * Returns: a newly created #NKnob 177 | * 178 | */ 179 | GtkWidget *n_knob_new(GtkAdjustment *adjustment) { 180 | return g_object_new (N_TYPE_KNOB, 181 | "adjustment", 182 | adjustment, 183 | NULL); 184 | } 185 | 186 | /** 187 | * n_knob_new_with_range: 188 | * @value: the initial value the new knob should have 189 | * @lower: the lowest value the new knob will allow 190 | * @upper: the highest value the new knob will allow 191 | * @step: increment added or subtracted when mouse scrolling 192 | * 193 | * Creates a new #NKnob. The knob will create a new 194 | * #GtkAdjustment from @value, @lower, @upper, and @step. If these 195 | * parameters represent a bogus configuration, the program will 196 | * terminate. 197 | * 198 | * Returns: a newly created #NKnob 199 | * 200 | */ 201 | GtkWidget* n_knob_new_with_range (gdouble value, gdouble lower, 202 | gdouble upper, gdouble step) { 203 | GtkAdjustment* adj; 204 | adj = (GtkAdjustment*) gtk_adjustment_new (value, lower, upper, step, step, 0); 205 | return n_knob_new (adj); 206 | } 207 | 208 | void n_knob_set_load_prefix(NKnob* knob, gchar* prefix) { 209 | if (knob->load_prefix) g_free(knob->load_prefix); 210 | knob->load_prefix = g_strdup(prefix); 211 | } 212 | gchar* n_knob_get_load_prefix(NKnob* knob) { 213 | return knob->load_prefix; 214 | } 215 | 216 | 217 | static void n_knob_destroy(GtkObject *object) { 218 | NKnob *knob; 219 | 220 | g_return_if_fail(object != NULL); 221 | g_return_if_fail(N_IS_KNOB(object)); 222 | 223 | knob = N_KNOB(object); 224 | knob->pixbuf = NULL; 225 | 226 | if (knob->load_prefix) g_free(knob->load_prefix); 227 | knob->load_prefix = NULL; 228 | 229 | if (GTK_OBJECT_CLASS(parent_class)->destroy) 230 | (*GTK_OBJECT_CLASS(parent_class)->destroy)(object); 231 | } 232 | 233 | 234 | static void n_knob_realize(GtkWidget *widget) { 235 | NKnob *knob; 236 | extern GdkPixbuf **pixbuf; 237 | int i=0; 238 | 239 | g_return_if_fail(widget != NULL); 240 | g_return_if_fail(N_IS_KNOB(widget)); 241 | 242 | if (GTK_WIDGET_CLASS(parent_class)->realize) 243 | (*GTK_WIDGET_CLASS(parent_class)->realize)(widget); 244 | 245 | knob = N_KNOB(widget); 246 | 247 | /* init first pixbuf */ 248 | if(pixbuf == NULL){ 249 | pixbuf = g_malloc0(sizeof(GdkPixbuf *)); 250 | } 251 | /* check for fitting pixbuf or NULL */ 252 | while(pixbuf[i] != NULL && gdk_pixbuf_get_height(pixbuf[i]) != knob->size){ 253 | i++; 254 | } 255 | /* if NULL realloc pixbuf pointer array one bigger 256 | * malloc new pixbuf with new size 257 | * set local pixbuf pointer to global 258 | * set last pixbuf pointer to NULL */ 259 | if(pixbuf[i] == NULL){ 260 | gchar* path; 261 | if (knob->load_prefix) 262 | path = g_build_path("/",knob->load_prefix,"knob.png",NULL); 263 | else { 264 | g_warning("Trying to show knob with no load prefix, looking only in cwd\n"); 265 | path = "knob.png"; 266 | } 267 | pixbuf[i] = gdk_pixbuf_new_from_file_at_size(path,52*knob->size,knob->size,&gerror); 268 | if (knob->load_prefix) 269 | g_free(path); 270 | knob->pixbuf = pixbuf[i]; 271 | pixbuf=g_realloc(pixbuf,sizeof(GdkPixbuf *) * (i+2)); 272 | pixbuf[i+1] = NULL; 273 | } else { /* if not NULL set fitting pixbuf */ 274 | knob->pixbuf = pixbuf[i]; 275 | } 276 | } 277 | 278 | static void n_knob_size_request (GtkWidget *widget, GtkRequisition *requisition) { 279 | NKnob *knob; 280 | 281 | knob = N_KNOB(widget); 282 | requisition->width = knob->size; 283 | requisition->height = knob->size; 284 | } 285 | 286 | static inline gdouble get_zero_one_value(NKnob *knob) { 287 | GtkAdjustment* adj = gtk_range_get_adjustment(GTK_RANGE(knob)); 288 | return (adj->value - adj->lower)/(adj->upper - adj->lower); 289 | } 290 | 291 | static inline gdouble get_adj_value(NKnob *knob, gdouble val) { 292 | GtkAdjustment* adj = gtk_range_get_adjustment(GTK_RANGE(knob)); 293 | return val*(adj->upper - adj->lower) + adj->lower; 294 | } 295 | 296 | static gint n_knob_expose(GtkWidget *widget, GdkEventExpose *event) 297 | { 298 | NKnob *knob; 299 | gint dx,xoff; 300 | 301 | g_return_val_if_fail(widget != NULL, FALSE); 302 | g_return_val_if_fail(N_IS_KNOB(widget), FALSE); 303 | g_return_val_if_fail(event != NULL, FALSE); 304 | 305 | if (event->count > 0) 306 | return FALSE; 307 | 308 | knob = N_KNOB(widget); 309 | 310 | xoff = widget->allocation.width/2 - knob->size/2; 311 | dx = (gint)(51 * get_zero_one_value(knob)) * knob->size; 312 | 313 | gdk_pixbuf_render_to_drawable_alpha( knob->pixbuf, widget->window, 314 | dx, 0, widget->allocation.x+xoff, widget->allocation.y, 315 | knob->size, knob->size, GDK_PIXBUF_ALPHA_FULL, 0, 0,0,0 ); 316 | 317 | return FALSE; 318 | } 319 | 320 | static gint n_knob_button_press(GtkWidget *widget, GdkEventButton *event) { 321 | NKnob *knob; 322 | 323 | g_return_val_if_fail(widget != NULL, FALSE); 324 | g_return_val_if_fail(N_IS_KNOB(widget), FALSE); 325 | g_return_val_if_fail(event != NULL, FALSE); 326 | 327 | knob = N_KNOB(widget); 328 | 329 | switch (knob->state) { 330 | case STATE_IDLE: 331 | switch (event->button) { 332 | case 1: 333 | case 3: 334 | gtk_grab_add(widget); 335 | knob->state = STATE_PRESSED; 336 | knob->saved_x = event->x; 337 | knob->saved_y = event->y; 338 | break; 339 | 340 | default: 341 | break; 342 | } 343 | break; 344 | default: 345 | break; 346 | } 347 | 348 | return FALSE; 349 | } 350 | 351 | static gint n_knob_button_release(GtkWidget *widget, GdkEventButton *event) { 352 | NKnob *knob; 353 | 354 | g_return_val_if_fail(widget != NULL, FALSE); 355 | g_return_val_if_fail(N_IS_KNOB(widget), FALSE); 356 | g_return_val_if_fail(event != NULL, FALSE); 357 | 358 | knob = N_KNOB(widget); 359 | 360 | switch (event->button) { 361 | case 1: 362 | case 3: 363 | switch (knob->state) { 364 | case STATE_PRESSED: 365 | gtk_grab_remove(widget); 366 | knob->state = STATE_IDLE; 367 | case STATE_DRAGGING: 368 | gtk_grab_remove(widget); 369 | knob->state = STATE_IDLE; 370 | 371 | break; 372 | default: 373 | break; 374 | } 375 | break; 376 | case 2: { 377 | gtk_range_set_value(GTK_RANGE(knob),0.0); 378 | } 379 | } 380 | 381 | return FALSE; 382 | } 383 | 384 | static gint n_knob_motion_notify(GtkWidget *widget, GdkEventMotion *event) { 385 | NKnob *knob; 386 | GdkModifierType mods; 387 | gint x, y, xoff; 388 | 389 | g_return_val_if_fail(widget != NULL, FALSE); 390 | g_return_val_if_fail(N_IS_KNOB(widget), FALSE); 391 | g_return_val_if_fail(event != NULL, FALSE); 392 | 393 | knob = N_KNOB(widget); 394 | 395 | x = event->x; 396 | y = event->y; 397 | 398 | 399 | if (event->is_hint || (event->window != widget->window)) 400 | gdk_window_get_pointer(widget->window, &x, &y, &mods); 401 | 402 | xoff = widget->allocation.width/2 - knob->size/2; 403 | x-=xoff; 404 | 405 | switch (knob->state) { 406 | case STATE_PRESSED: 407 | knob->state = STATE_DRAGGING; 408 | /* fall through */ 409 | case STATE_DRAGGING: 410 | if (mods & GDK_BUTTON1_MASK) { 411 | n_knob_update_mouse(knob, x-widget->allocation.x, y-widget->allocation.y , TRUE); 412 | return TRUE; 413 | } else if (mods & GDK_BUTTON3_MASK) { 414 | n_knob_update_mouse(knob, x-widget->allocation.x, y-widget->allocation.y , FALSE); 415 | return TRUE; 416 | } 417 | break; 418 | 419 | default: 420 | break; 421 | } 422 | 423 | return FALSE; 424 | } 425 | 426 | static gint n_knob_scroll (GtkWidget *widget, GdkEventScroll *event) { 427 | NKnob *knob; 428 | GtkRange *range; 429 | GtkAdjustment *adj; 430 | 431 | gdouble oldval,newval; 432 | gboolean handled; 433 | GtkScrollType type; 434 | 435 | knob = N_KNOB(widget); 436 | range = GTK_RANGE(widget); 437 | adj = gtk_range_get_adjustment(range); 438 | 439 | gtk_widget_grab_focus (widget); 440 | 441 | knob->state = STATE_SCROLL; 442 | 443 | oldval = gtk_range_get_value(range); 444 | 445 | switch (event->direction) { 446 | case GDK_SCROLL_UP: 447 | newval = oldval + 448 | gtk_adjustment_get_step_increment(adj); 449 | type = GTK_SCROLL_STEP_UP; 450 | break; 451 | case GDK_SCROLL_DOWN: 452 | newval = oldval - 453 | gtk_adjustment_get_step_increment(adj); 454 | type = GTK_SCROLL_STEP_DOWN; 455 | default: // only handle those for now 456 | break; 457 | } 458 | 459 | gtk_range_set_value(range,newval); 460 | newval = gtk_range_get_value(range); 461 | if (newval != oldval) 462 | g_signal_emit_by_name (range, "change-value", type, gtk_range_get_value(range), &handled); 463 | 464 | knob->state = STATE_IDLE; 465 | 466 | return TRUE; 467 | } 468 | 469 | 470 | 471 | static void n_knob_update_mouse(NKnob *knob, gint x, gint y, 472 | gboolean absolute) { 473 | gdouble old_adj_val,old_value, new_value, dv, dh; 474 | gdouble angle,handled; 475 | 476 | g_return_if_fail(knob != NULL); 477 | g_return_if_fail(N_IS_KNOB(knob)); 478 | 479 | old_adj_val = gtk_range_get_value(GTK_RANGE(knob)); 480 | old_value = get_zero_one_value(knob); 481 | 482 | angle = atan2(-y + (knob->size>>1), x - (knob->size>>1)); 483 | 484 | if (absolute) { 485 | angle /= G_PI; 486 | if (angle < -0.5) 487 | angle += 2; 488 | 489 | new_value = -(2.0/3.0) * (angle - 1.25); /* map [1.25pi, -0.25pi] onto [0, 1] */ 490 | 491 | } else { 492 | dv = knob->saved_y - y; /* inverted cartesian graphics coordinate system */ 493 | dh = x - knob->saved_x; 494 | knob->saved_x = x; 495 | knob->saved_y = y; 496 | 497 | if (x >= 0 && x <= knob->size) 498 | dh = 0; /* dead zone */ 499 | else { 500 | angle = cos(angle); 501 | dh *= angle * angle; 502 | } 503 | 504 | new_value = old_value + 505 | dv * 0.1 + /* "step" == 0.1 */ 506 | dh / 200.0f; 507 | } 508 | new_value = get_adj_value(knob,new_value); 509 | gtk_range_set_value(GTK_RANGE(knob),new_value); 510 | new_value = gtk_range_get_value(GTK_RANGE(knob)); 511 | if (new_value != old_adj_val) { 512 | g_signal_emit_by_name (knob, "change-value", GTK_SCROLL_JUMP, 513 | new_value, &handled); 514 | } 515 | } 516 | 517 | 518 | 519 | static void 520 | n_knob_set_property (GObject *object, 521 | guint prop_id, 522 | const GValue *value, 523 | GParamSpec *pspec) 524 | { 525 | switch (prop_id) { 526 | default: 527 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 528 | break; 529 | } 530 | } 531 | 532 | static void 533 | n_knob_get_property (GObject *object, 534 | guint prop_id, 535 | GValue *value, 536 | GParamSpec *pspec) 537 | { 538 | switch (prop_id) { 539 | default: 540 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 541 | break; 542 | } 543 | } 544 | 545 | #ifdef _TEST_N_KNOB 546 | static gboolean timeout_func(gpointer data) { 547 | GtkRange *range = GTK_RANGE(data); 548 | GtkAdjustment *adj = gtk_range_get_adjustment(range); 549 | gdouble val = gtk_range_get_value(range); 550 | 551 | if (val == adj->upper) 552 | val = adj->lower; 553 | else 554 | val += gtk_adjustment_get_step_increment(adj); 555 | gtk_range_set_value(range,val); 556 | return TRUE; 557 | } 558 | 559 | static gboolean changed_callback(GtkRange* range, GtkScrollType type, gdouble value, gpointer data) { 560 | printf("Changed to: %f\n",value); 561 | return FALSE; 562 | } 563 | 564 | int main(int argc, char* argv[]) { 565 | GtkWidget* window; 566 | GtkWidget* knob; 567 | GtkWidget* vbox; 568 | 569 | gtk_init (&argc, &argv); 570 | 571 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 572 | gtk_window_set_title (GTK_WINDOW (window), "NKnob Test"); 573 | gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); 574 | g_signal_connect (G_OBJECT (window), "delete-event", 575 | G_CALLBACK (gtk_main_quit), NULL); 576 | 577 | vbox = gtk_vbox_new (FALSE, 0); 578 | gtk_container_add (GTK_CONTAINER (window), vbox); 579 | 580 | /* knob */ 581 | knob = n_knob_new_with_range (-90, -90, 0, 1); 582 | n_knob_set_load_prefix(N_KNOB(knob),"../"); 583 | gtk_box_pack_start (GTK_BOX (vbox), knob, TRUE, FALSE, 0); 584 | g_signal_connect (G_OBJECT (knob), "change-value", 585 | G_CALLBACK (changed_callback), NULL); 586 | 587 | 588 | gtk_widget_show_all (window); 589 | 590 | if (0) 591 | g_timeout_add(5,timeout_func,knob); 592 | 593 | gtk_main ( ); 594 | 595 | return 0; 596 | } 597 | 598 | #endif 599 | -------------------------------------------------------------------------------- /drmr_hydrogen.c: -------------------------------------------------------------------------------- 1 | /* drmr_hydrogen.c 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * Public License v3. source code is available at 6 | * 7 | 8 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | // Utilities for loading up a hydrogen kit 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "samplerate.h" 30 | #include "drmr.h" 31 | #include "drmr_hydrogen.h" 32 | #include "expat.h" 33 | 34 | /* Below is a list of the locations that DrMr will 35 | * search for drumkit files. It will scan each sub-directory 36 | * in these locations (non-recursive) for a drumkit.xml 37 | * file, and if found, parse it and add it to the list 38 | * of available kits. 39 | * 40 | * Strings that start with a ~ will be expanded to the HOME 41 | * environment variable. NB: only a ~ at the start of a string 42 | * will be expanded, ones in the middle will be left in place. 43 | */ 44 | static char* default_drumkit_locations[] = { 45 | "/usr/share/hydrogen/data/drumkits/", 46 | "/usr/local/share/hydrogen/data/drumkits/", 47 | "/usr/share/drmr/drumkits/", 48 | "~/.hydrogen/data/drumkits/", 49 | "~/.drmr/drumkits/", 50 | NULL 51 | }; 52 | 53 | // Quality of conversion for libsamplerate. 54 | // See http://www.mega-nerd.com/SRC/api_misc.html#Converters 55 | // for info about availble qualities 56 | #define RATE_CONV_QUALITY SRC_SINC_MEDIUM_QUALITY 57 | 58 | #define MAX_CHAR_DATA 512 59 | 60 | char *unknownstr = "(Unknown)"; 61 | 62 | struct instrument_layer { 63 | char* filename; 64 | float min; 65 | float max; 66 | float gain; 67 | struct instrument_layer *next; 68 | }; 69 | 70 | struct instrument_info { 71 | int id; 72 | char* filename; 73 | char* name; 74 | float gain; 75 | struct instrument_layer *layers; 76 | struct instrument_info *next; 77 | // maybe pan/vol/etc.. 78 | }; 79 | 80 | struct kit_info { 81 | char* name; 82 | char* desc; 83 | // linked list of intruments, null terminated 84 | struct instrument_info* instruments; 85 | }; 86 | 87 | struct hp_info { 88 | char scan_only; 89 | char in_info; 90 | char in_instrument_list; 91 | char in_instrument; 92 | char in_layer; 93 | char in_drumkit_component; 94 | 95 | char counted_cur_inst; 96 | int cur_off; 97 | char cur_buf[MAX_CHAR_DATA]; 98 | struct instrument_info* cur_instrument; 99 | struct instrument_layer* cur_layer; 100 | struct kit_info* kit_info; 101 | }; 102 | 103 | 104 | static void XMLCALL 105 | startElement(void *userData, const char *name, const char **atts) 106 | { 107 | struct hp_info* info = (struct hp_info*)userData; 108 | info->cur_off = 0; 109 | if (info->in_info) { 110 | if (info->in_instrument) { 111 | if (!strcmp(name,"layer") && !info->scan_only) { 112 | info->in_layer = 1; 113 | info->cur_layer = malloc(sizeof(struct instrument_layer)); 114 | memset(info->cur_layer,0,sizeof(struct instrument_layer)); 115 | } 116 | } 117 | if (info->in_instrument_list) { 118 | if (!strcmp(name,"instrument")) { 119 | info->in_instrument = 1; 120 | info->cur_instrument = malloc(sizeof(struct instrument_info)); 121 | memset(info->cur_instrument,0,sizeof(struct instrument_info)); 122 | } 123 | } else { 124 | if (!strcmp(name,"instrumentList")) 125 | info->in_instrument_list = 1; 126 | 127 | if (! strcmp (name,"drumkitComponent")) 128 | info->in_drumkit_component = 1; 129 | 130 | } 131 | } else { 132 | if (!strcmp(name,"drumkit_info")) 133 | info->in_info = 1; 134 | } 135 | } 136 | 137 | static void XMLCALL 138 | endElement(void *userData, const char *name) 139 | { 140 | struct hp_info* info = (struct hp_info*)userData; 141 | if (info->cur_off == MAX_CHAR_DATA) info->cur_off--; 142 | info->cur_buf[info->cur_off]='\0'; 143 | 144 | if (info->in_info && ! info->in_drumkit_component && !info->in_instrument_list && !strcmp(name,"name")) 145 | info->kit_info->name = strdup(info->cur_buf); 146 | if (info->scan_only && info->in_info && !info->in_instrument_list && !strcmp(name,"info")) 147 | info->kit_info->desc = strdup(info->cur_buf); 148 | 149 | if (info->in_layer && !info->scan_only) { 150 | if (!strcmp(name,"filename")) 151 | info->cur_layer->filename = strdup(info->cur_buf); 152 | if (!strcmp(name,"min")) 153 | info->cur_layer->min = atof(info->cur_buf); 154 | if (!strcmp(name,"max")) 155 | info->cur_layer->max = atof(info->cur_buf); 156 | if (!strcmp(name,"gain")) 157 | info->cur_layer->gain = atof(info->cur_buf); 158 | } 159 | 160 | if (info->in_instrument && !info->in_layer) { 161 | if (!strcmp(name,"id")) 162 | info->cur_instrument->id = atoi(info->cur_buf); 163 | if (!info->scan_only && !strcmp(name,"filename")) 164 | info->cur_instrument->filename = strdup(info->cur_buf); 165 | if (!strcmp(name,"name")) 166 | info->cur_instrument->name = strdup(info->cur_buf); 167 | } 168 | 169 | info->cur_off = 0; 170 | 171 | if (!info->scan_only && 172 | info->in_layer && 173 | !strcmp(name,"layer") && 174 | info->cur_layer->filename) { 175 | struct instrument_layer *cur_l = info->cur_instrument->layers; 176 | if (cur_l) { 177 | while(cur_l->next) cur_l = cur_l->next; 178 | cur_l->next = info->cur_layer; 179 | } else 180 | info->cur_instrument->layers = info->cur_layer; 181 | info->cur_layer = NULL; 182 | info->in_layer = 0; 183 | } 184 | 185 | 186 | if (info->in_instrument && info->cur_instrument && !strcmp(name,"instrument")) { 187 | struct instrument_info * cur_i = info->kit_info->instruments; 188 | if (cur_i) { 189 | while(cur_i->next) cur_i = cur_i->next; 190 | cur_i->next = info->cur_instrument; 191 | } else 192 | info->kit_info->instruments = info->cur_instrument; 193 | info->cur_instrument = NULL; 194 | info->in_instrument = 0; 195 | } 196 | if (info->in_instrument_list && !strcmp(name,"instrumentList")) info->in_instrument_list = 0; 197 | if (info->in_drumkit_component && ! strcmp (name, "drumkitComponent")) 198 | info->in_drumkit_component = 0; 199 | 200 | if (info->in_info && !strcmp(name,"drumkit_info")) info->in_info = 0; 201 | } 202 | 203 | static void XMLCALL 204 | charData(void *userData, 205 | const char* data, 206 | int len) { 207 | int i; 208 | struct hp_info* info = (struct hp_info*)userData; 209 | if (!info->in_info) return; 210 | for(i = 0;icur_off < MAX_CHAR_DATA) { 212 | info->cur_buf[info->cur_off] = data[i]; 213 | info->cur_off++; 214 | } 215 | } 216 | } 217 | 218 | struct kit_list { 219 | scanned_kit* skit; 220 | struct kit_list* next; 221 | }; 222 | 223 | // see note above at default_drumkit_locations 224 | // for how this function works 225 | static char* expand_path(char* path, char* buf) { 226 | char *home_dir; 227 | int n; 228 | if (*path != '~') return path; 229 | home_dir = getenv("HOME"); 230 | if (!home_dir) { 231 | fprintf(stderr,"Home dir not set, can't expand ~ paths\n"); 232 | return 0; 233 | } 234 | n = snprintf(buf,BUFSIZ,"%s%s",home_dir,path+1); 235 | if (n >= BUFSIZ) { 236 | fprintf(stderr,"Path too long for buffer, can't expand: %s\n",path); 237 | return 0; 238 | } 239 | return buf; 240 | } 241 | 242 | kits* scan_kits() { 243 | DIR* dp; 244 | FILE* file; 245 | XML_Parser parser; 246 | int done; 247 | struct hp_info info; 248 | struct kit_info kit_info; 249 | struct dirent *ep; 250 | int cp = 0; 251 | char* cur_path = default_drumkit_locations[cp++]; 252 | kits* ret = malloc(sizeof(kits)); 253 | struct kit_list* scanned_kits = NULL; 254 | char buf[BUFSIZ], path_buf[BUFSIZ]; 255 | 256 | ret->num_kits = 0; 257 | 258 | while (cur_path) { 259 | cur_path = expand_path(cur_path,path_buf); 260 | if (!cur_path) { 261 | cur_path = default_drumkit_locations[cp++]; 262 | continue; 263 | } 264 | dp = opendir (cur_path); 265 | if (dp != NULL) { 266 | while ((ep = readdir (dp))) { 267 | if (ep->d_name[0]=='.') continue; 268 | if (snprintf(buf,BUFSIZ,"%s/%s/drumkit.xml",cur_path,ep->d_name) >= BUFSIZ) { 269 | fprintf(stderr,"Warning: Skipping scan of %s as path name is too long\n",cur_path); 270 | continue; 271 | } 272 | file = fopen(buf,"r"); 273 | if (!file) continue; // couldn't open file 274 | parser = XML_ParserCreate(NULL); 275 | memset(&info,0,sizeof(struct hp_info)); 276 | memset(&kit_info,0,sizeof(struct kit_info)); 277 | info.kit_info = &kit_info; 278 | info.scan_only = 1; 279 | XML_SetUserData(parser, &info); 280 | XML_SetElementHandler(parser, startElement, endElement); 281 | XML_SetCharacterDataHandler(parser, charData); 282 | do { 283 | int len = (int)fread(buf, 1, sizeof(buf), file); 284 | done = len < sizeof(buf); 285 | if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { 286 | fprintf(stderr, 287 | "%s at line %lu\n", 288 | XML_ErrorString(XML_GetErrorCode(parser)), 289 | XML_GetCurrentLineNumber(parser)); 290 | break; 291 | } 292 | } while (!done); 293 | XML_ParserFree(parser); 294 | if (info.kit_info->name) { 295 | int i = 0; 296 | scanned_kit* kit = malloc(sizeof(scanned_kit)); 297 | struct kit_list* node = malloc(sizeof(struct kit_list)); 298 | memset(kit,0,sizeof(scanned_kit)); 299 | memset(node,0,sizeof(struct kit_list)); 300 | kit->name = info.kit_info->name; 301 | kit->desc = info.kit_info->desc; 302 | 303 | struct instrument_info *cur_i = info.kit_info->instruments; 304 | while (cur_i) { 305 | kit->samples++; 306 | cur_i = cur_i->next; 307 | } 308 | kit->sample_names = malloc(kit->samples*sizeof(char*)); 309 | cur_i = info.kit_info->instruments; 310 | while (cur_i) { 311 | struct instrument_info *to_free = cur_i; 312 | if (cur_i->name) 313 | kit->sample_names[i++] = cur_i->name; 314 | else 315 | kit->sample_names[i++] = unknownstr; 316 | cur_i = cur_i->next; 317 | free(to_free); 318 | } 319 | 320 | snprintf(buf,BUFSIZ,"%s/%s/",cur_path,ep->d_name); 321 | kit->path = realpath(buf,NULL); // realpath will malloc for us 322 | node->skit = kit; 323 | struct kit_list * cur_k = scanned_kits; 324 | if (cur_k) { 325 | while(cur_k->next) cur_k = cur_k->next; 326 | cur_k->next = node; 327 | } else 328 | scanned_kits = node; 329 | } 330 | } 331 | (void) closedir (dp); 332 | } 333 | else if (errno != ENOENT) 334 | fprintf(stderr,"Couldn't open %s: %s\n",cur_path,strerror(errno)); 335 | cur_path = default_drumkit_locations[cp++]; 336 | } 337 | 338 | // valid kits are in scanned_kits at this point 339 | cp = 0; 340 | struct kit_list * cur_k = scanned_kits; 341 | while(cur_k) { 342 | //printf("found kit: %s\nat:%s\n\n",cur_k->skit->name,cur_k->skit->path); 343 | cur_k = cur_k->next; 344 | cp++; 345 | } 346 | 347 | printf("found %i kits\n",cp); 348 | ret->num_kits = cp; 349 | ret->kits = malloc(cp*sizeof(scanned_kit)); 350 | 351 | cur_k = scanned_kits; 352 | cp = 0; 353 | while(cur_k) { 354 | ret->kits[cp].name = cur_k->skit->name; 355 | ret->kits[cp].desc = cur_k->skit->desc; 356 | ret->kits[cp].path = cur_k->skit->path; 357 | ret->kits[cp].samples = cur_k->skit->samples; 358 | ret->kits[cp].sample_names = cur_k->skit->sample_names; 359 | cp++; 360 | free(cur_k->skit); 361 | cur_k = cur_k->next; 362 | // free each node as we go along 363 | free(scanned_kits); 364 | scanned_kits = cur_k; 365 | } 366 | 367 | return ret; 368 | } 369 | 370 | void free_samples(drmr_sample* samples, int num_samples) { 371 | int i,j; 372 | for (i=0;inum_kits;i++) { 390 | free(kits->kits[i].name); 391 | free(kits->kits[i].desc); 392 | free(kits->kits[i].path); 393 | } 394 | free(kits->kits); 395 | free(kits); 396 | } 397 | 398 | int load_sample(char* path, drmr_layer* layer, double target_rate) { 399 | SNDFILE* sndf; 400 | long size; 401 | 402 | //printf("Loading: %s\n",path); 403 | 404 | layer->info = malloc(sizeof(SF_INFO)); 405 | memset(layer->info,0,sizeof(SF_INFO)); 406 | sndf = sf_open(path,SFM_READ,layer->info); 407 | 408 | if (!sndf) { 409 | fprintf(stderr,"Failed to open sound file: %s - %s\n",path,sf_strerror(sndf)); 410 | free(layer->info); 411 | return 1; 412 | } 413 | 414 | if (layer->info->channels > 2) { 415 | fprintf(stderr, "File has too many channels. Can only handle mono/stereo samples\n"); 416 | free(layer->info); 417 | return 1; 418 | } 419 | 420 | size = layer->info->frames * layer->info->channels; 421 | layer->limit = size; 422 | layer->data = malloc(size*sizeof(float)); 423 | if (!layer->data) { 424 | fprintf(stderr,"Failed to allocate sample memory for %s\n",path); 425 | free(layer->info); 426 | return 1; 427 | } 428 | 429 | sf_read_float(sndf,layer->data,size); 430 | sf_close(sndf); 431 | 432 | // convert rate if needed 433 | if (layer->info->samplerate != target_rate) { 434 | SRC_DATA src_data; 435 | int stat; 436 | double ratio = (target_rate/layer->info->samplerate); 437 | long out_frames = (long)ceil(layer->info->frames * ratio); 438 | long out_size = out_frames*layer->info->channels; 439 | float *data_out = malloc(sizeof(float)*out_size); 440 | 441 | src_data.data_in = layer->data; 442 | src_data.input_frames = layer->info->frames; 443 | src_data.data_out = data_out; 444 | src_data.output_frames = out_frames; 445 | src_data.src_ratio = ratio; 446 | 447 | stat = src_simple(&src_data,RATE_CONV_QUALITY,layer->info->channels); 448 | if (stat) { 449 | fprintf(stderr,"Failed to convert rate for %s: %s. Using original rate\n", 450 | path,src_strerror(stat)); 451 | free(data_out); 452 | return 0; 453 | } 454 | 455 | if (src_data.input_frames_used != layer->info->frames) 456 | fprintf(stderr,"Didn't consume all input frames. used: %li had: %li gened: %li\n", 457 | src_data.input_frames_used, layer->info->frames,src_data.output_frames_gen); 458 | 459 | free(layer->data); 460 | 461 | layer->data = data_out; 462 | layer->limit = src_data.output_frames_gen*layer->info->channels; 463 | layer->info->samplerate = target_rate; 464 | layer->info->frames = src_data.output_frames_gen; 465 | } 466 | return 0; 467 | } 468 | 469 | drmr_sample* load_hydrogen_kit(char *path, double rate, int *num_samples) { 470 | FILE* file; 471 | char buf[BUFSIZ]; 472 | XML_Parser parser; 473 | int done; 474 | struct hp_info info; 475 | struct kit_info kit_info; 476 | drmr_sample *samples; 477 | struct instrument_info * cur_i, *i_to_free; 478 | int i = 0, num_inst = 0; 479 | 480 | snprintf(buf,BUFSIZ,"%s/drumkit.xml",path); 481 | 482 | printf("trying to load: %s\n",buf); 483 | 484 | file = fopen(buf,"r"); 485 | if (!file) { 486 | perror("Unable to open file:"); 487 | return NULL; 488 | } 489 | 490 | parser = XML_ParserCreate(NULL); 491 | memset(&info,0,sizeof(struct hp_info)); 492 | memset(&kit_info,0,sizeof(struct kit_info)); 493 | 494 | info.kit_info = &kit_info; 495 | 496 | XML_SetUserData(parser, &info); 497 | XML_SetElementHandler(parser, startElement, endElement); 498 | XML_SetCharacterDataHandler(parser, charData); 499 | 500 | do { 501 | int len = (int)fread(buf, 1, sizeof(buf), file); 502 | done = len < sizeof(buf); 503 | if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR) { 504 | fprintf(stderr, 505 | "%s at line %lu\n", 506 | XML_ErrorString(XML_GetErrorCode(parser)), 507 | XML_GetCurrentLineNumber(parser)); 508 | return NULL; 509 | } 510 | } while (!done); 511 | XML_ParserFree(parser); 512 | 513 | printf("Read kit: %s\n",kit_info.name); 514 | cur_i = kit_info.instruments; 515 | while(cur_i) { // first count how many samples we have 516 | num_inst ++; 517 | cur_i = cur_i->next; 518 | } 519 | printf("Loading %i instruments\n",num_inst); 520 | samples = malloc(num_inst*sizeof(drmr_sample)); 521 | cur_i = kit_info.instruments; 522 | while(cur_i) { 523 | if (cur_i->filename) { // top level filename, just make one dummy layer 524 | drmr_layer *layer = malloc(sizeof(drmr_layer)); 525 | layer->min = 0; 526 | layer->max = 1; 527 | snprintf(buf,BUFSIZ,"%s/%s",path,cur_i->filename); 528 | if (load_sample(buf,layer,rate)) { 529 | fprintf(stderr,"Could not load sample: %s\n",buf); 530 | // set limit to zero, will never try and play 531 | layer->info = NULL; 532 | layer->limit = 0; 533 | layer->data = NULL; 534 | } 535 | samples[i].layer_count = 0; 536 | samples[i].layers = NULL; 537 | samples[i].offset = 0; 538 | samples[i].info = layer->info; 539 | samples[i].limit = layer->limit; 540 | samples[i].data = layer->data; 541 | free(layer); 542 | } else if (cur_i->layers) { 543 | int layer_count = 0; 544 | int j; 545 | struct instrument_layer *cur_l = cur_i->layers; 546 | while(cur_l) { 547 | layer_count++; 548 | cur_l = cur_l->next; 549 | } 550 | samples[i].layer_count = layer_count; 551 | samples[i].layers = malloc(sizeof(drmr_layer)*layer_count); 552 | cur_l = cur_i->layers; 553 | j = 0; 554 | while(cur_l) { 555 | snprintf(buf,BUFSIZ,"%s/%s",path,cur_l->filename); 556 | if (load_sample(buf,samples[i].layers+j,rate)) { 557 | fprintf(stderr,"Could not load sample: %s\n",buf); 558 | // set limit to zero, will never try and play 559 | samples[i].layers[j].info = NULL; 560 | samples[i].layers[j].limit = 0; 561 | samples[i].layers[j].data = NULL; 562 | } 563 | samples[i].layers[j].min = cur_l->min; 564 | samples[i].layers[j].max = cur_l->max; 565 | j++; 566 | cur_l = cur_l->next; 567 | } 568 | } else { // no layer or file, empty inst 569 | samples[i].layer_count = 0; 570 | samples[i].layers = NULL; 571 | samples[i].offset = 0; 572 | samples[i].info = NULL; 573 | samples[i].limit = 0; 574 | samples[i].data = NULL; 575 | } 576 | samples[i].active = 0; 577 | samples[i].dataoffset = 0; 578 | i_to_free = cur_i; 579 | cur_i = cur_i->next; 580 | 581 | if (i_to_free->name) free(i_to_free->name); 582 | if (i_to_free->filename) free(i_to_free->filename); 583 | if (samples[i].layer_count > 0) { 584 | struct instrument_layer *ltf = i_to_free->layers; 585 | while (ltf) { 586 | free(ltf->filename); 587 | ltf = ltf->next; 588 | } 589 | } 590 | free(i_to_free); 591 | i++; 592 | } 593 | if (kit_info.name) free(kit_info.name); 594 | *num_samples = num_inst; 595 | return samples; 596 | } 597 | 598 | #ifdef _TEST_HYDROGEN_PARSER 599 | 600 | int main(int argc, char* argv[]) { 601 | kits *kits; 602 | int i,j; 603 | kits = scan_kits(); 604 | for (i=0;inum_kits;i++) { 605 | printf("\t%s:\n\t\tpath: %s\n\t\tsamples: %i\n",kits->kits[i].name,kits->kits[i].path,kits->kits[i].samples); 606 | printf("\t\t"); 607 | for (j=0;jkits[i].samples;j++) { 608 | printf("%s, ",kits->kits[i].sample_names[j]); 609 | } 610 | printf("\n\n"); 611 | } 612 | 613 | return 0; 614 | } 615 | 616 | #endif // _TEST_HYDROGEN_PARSER 617 | -------------------------------------------------------------------------------- /drmr.c: -------------------------------------------------------------------------------- 1 | /* drmr.c 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * Public License v3. source code is available at 6 | * 7 | 8 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "drmr.h" 23 | #include "drmr_hydrogen.h" 24 | 25 | #define REQ_BUF_SIZE 10 26 | #define VELOCITY_MAX 127 27 | 28 | static int current_kit_changed = 0; 29 | 30 | static void* load_thread(void* arg) { 31 | DrMr* drmr = (DrMr*)arg; 32 | drmr_sample *loaded_samples,*old_samples; 33 | int loaded_count, old_scount; 34 | char *request, *request_orig; 35 | for(;;) { 36 | pthread_mutex_lock(&drmr->load_mutex); 37 | pthread_cond_wait(&drmr->load_cond, 38 | &drmr->load_mutex); 39 | pthread_mutex_unlock(&drmr->load_mutex); 40 | old_samples = drmr->samples; 41 | old_scount = drmr->num_samples; 42 | request_orig = request = drmr->request_buf[drmr->curReq]; 43 | if (!strncmp(request, "file://", 7)) 44 | request += 7; 45 | loaded_samples = load_hydrogen_kit(request,drmr->rate,&loaded_count); 46 | if (!loaded_samples) { 47 | fprintf(stderr,"Failed to load kit at: %s\n",request); 48 | pthread_mutex_lock(&drmr->load_mutex); 49 | drmr->num_samples = 0; 50 | drmr->samples = NULL; 51 | pthread_mutex_unlock(&drmr->load_mutex); 52 | } 53 | else { 54 | // just lock for the critical moment when we swap in the new kit 55 | printf("loaded kit at: %s\n",request); 56 | pthread_mutex_lock(&drmr->load_mutex); 57 | drmr->samples = loaded_samples; 58 | drmr->num_samples = loaded_count; 59 | pthread_mutex_unlock(&drmr->load_mutex); 60 | } 61 | if (old_scount > 0) free_samples(old_samples,old_scount); 62 | drmr->current_path = request_orig; 63 | current_kit_changed = 1; 64 | } 65 | return 0; 66 | } 67 | 68 | static LV2_Handle 69 | instantiate(const LV2_Descriptor* descriptor, 70 | double rate, 71 | const char* bundle_path, 72 | const LV2_Feature* const* features) { 73 | int i; 74 | DrMr* drmr = malloc(sizeof(DrMr)); 75 | drmr->map = NULL; 76 | drmr->samples = NULL; 77 | drmr->num_samples = 0; 78 | drmr->current_path = NULL; 79 | drmr->curReq = -1; 80 | drmr->rate = rate; 81 | drmr->ignore_velocity = false; 82 | drmr->ignore_note_off = true; 83 | 84 | #ifdef DRMR_UI_ZERO_SAMP 85 | drmr->zero_position = DRMR_UI_ZERO_SAMP; 86 | #else 87 | drmr->zero_position = 0; 88 | #endif 89 | 90 | if (pthread_mutex_init(&drmr->load_mutex, 0)) { 91 | fprintf(stderr, "Could not initialize load_mutex.\n"); 92 | free(drmr); 93 | return 0; 94 | } 95 | if (pthread_cond_init(&drmr->load_cond, 0)) { 96 | fprintf(stderr, "Could not initialize load_cond.\n"); 97 | free(drmr); 98 | return 0; 99 | } 100 | 101 | while(*features) { 102 | if (!strcmp((*features)->URI, LV2_URID_URI "#map")) 103 | drmr->map = (LV2_URID_Map *)((*features)->data); 104 | features++; 105 | } 106 | if (!drmr->map) { 107 | fprintf(stderr, "LV2 host does not support urid#map.\n"); 108 | free(drmr); 109 | return 0; 110 | } 111 | map_drmr_uris(drmr->map,&(drmr->uris)); 112 | 113 | lv2_atom_forge_init(&drmr->forge, drmr->map); 114 | 115 | if (pthread_create(&drmr->load_thread, 0, load_thread, drmr)) { 116 | fprintf(stderr, "Could not initialize loading thread.\n"); 117 | free(drmr); 118 | return 0; 119 | } 120 | 121 | drmr->request_buf = malloc(REQ_BUF_SIZE*sizeof(char*)); 122 | memset(drmr->request_buf,0,REQ_BUF_SIZE*sizeof(char*)); 123 | 124 | drmr->gains = malloc(32*sizeof(float*)); 125 | drmr->pans = malloc(32*sizeof(float*)); 126 | for(i = 0;i<32;i++) { 127 | drmr->gains[i] = NULL; 128 | drmr->pans[i] = NULL; 129 | } 130 | 131 | return (LV2_Handle)drmr; 132 | } 133 | 134 | static void 135 | connect_port(LV2_Handle instance, 136 | uint32_t port, 137 | void* data) { 138 | DrMr* drmr = (DrMr*)instance; 139 | DrMrPortIndex port_index = (DrMrPortIndex)port; 140 | switch (port_index) { 141 | case DRMR_CONTROL: 142 | drmr->control_port = (LV2_Atom_Sequence*)data; 143 | break; 144 | case DRMR_CORE_EVENT: 145 | drmr->core_event_port = (LV2_Atom_Sequence*)data; 146 | break; 147 | case DRMR_LEFT: 148 | drmr->left = (float*)data; 149 | break; 150 | case DRMR_RIGHT: 151 | drmr->right = (float*)data; 152 | break; 153 | case DRMR_BASENOTE: 154 | if (data) drmr->baseNote = (float*)data; 155 | default: 156 | break; 157 | } 158 | 159 | if (port_index >= DRMR_GAIN_ONE && port_index <= DRMR_GAIN_THIRTYTWO) { 160 | int goff = port_index - DRMR_GAIN_ONE; 161 | drmr->gains[goff] = (float*)data; 162 | } 163 | 164 | if (port_index >= DRMR_PAN_ONE && port_index <= DRMR_PAN_THIRTYTWO) { 165 | int poff = port_index - DRMR_PAN_ONE; 166 | drmr->pans[poff] = (float*)data; 167 | } 168 | } 169 | 170 | static inline LV2_Atom *build_update_message(DrMr *drmr) { 171 | LV2_Atom_Forge_Frame set_frame; 172 | LV2_Atom* msg = (LV2_Atom*)lv2_atom_forge_resource 173 | (&drmr->forge, &set_frame, 1, drmr->uris.ui_msg); 174 | if (drmr->current_path) { 175 | lv2_atom_forge_property_head(&drmr->forge, drmr->uris.kit_path,0); 176 | lv2_atom_forge_string(&drmr->forge, drmr->current_path, strlen(drmr->current_path)); 177 | } 178 | lv2_atom_forge_pop(&drmr->forge,&set_frame); 179 | return msg; 180 | } 181 | 182 | static inline LV2_Atom *build_state_message(DrMr *drmr) { 183 | LV2_Atom_Forge_Frame set_frame; 184 | LV2_Atom* msg = (LV2_Atom*)lv2_atom_forge_resource 185 | (&drmr->forge, &set_frame, 1, drmr->uris.get_state); 186 | if (drmr->current_path) { 187 | lv2_atom_forge_property_head(&drmr->forge, drmr->uris.kit_path,0); 188 | lv2_atom_forge_string(&drmr->forge, drmr->current_path, strlen(drmr->current_path)); 189 | } 190 | lv2_atom_forge_property_head(&drmr->forge, drmr->uris.velocity_toggle,0); 191 | lv2_atom_forge_bool(&drmr->forge, drmr->ignore_velocity?true:false); 192 | lv2_atom_forge_property_head(&drmr->forge, drmr->uris.note_off_toggle,0); 193 | lv2_atom_forge_bool(&drmr->forge, drmr->ignore_note_off?true:false); 194 | lv2_atom_forge_property_head(&drmr->forge, drmr->uris.zero_position,0); 195 | lv2_atom_forge_int(&drmr->forge, drmr->zero_position); 196 | lv2_atom_forge_pop(&drmr->forge,&set_frame); 197 | return msg; 198 | } 199 | 200 | static inline LV2_Atom *build_midi_info_message(DrMr *drmr, uint8_t *data) { 201 | LV2_Atom_Forge_Frame set_frame; 202 | LV2_Atom* msg = (LV2_Atom*)lv2_atom_forge_resource 203 | (&drmr->forge, &set_frame, 1, drmr->uris.midi_info); 204 | lv2_atom_forge_property_head(&drmr->forge, drmr->uris.midi_event,0); 205 | lv2_atom_forge_write(&drmr->forge, data, 3); 206 | lv2_atom_forge_pop(&drmr->forge,&set_frame); 207 | return msg; 208 | } 209 | 210 | static inline void layer_to_sample(drmr_sample *sample, float gain) { 211 | int i; 212 | float mapped_gain = (1-(gain/GAIN_MIN)); 213 | if (mapped_gain > 1.0f) mapped_gain = 1.0f; 214 | for(i = 0;i < sample->layer_count;i++) { 215 | if (sample->layers[i].min <= mapped_gain && 216 | (sample->layers[i].max > mapped_gain || 217 | (sample->layers[i].max == 1 && mapped_gain == 1))) { 218 | sample->limit = sample->layers[i].limit; 219 | sample->info = sample->layers[i].info; 220 | sample->data = sample->layers[i].data; 221 | return; 222 | } 223 | } 224 | fprintf(stderr,"Couldn't find layer for gain %f in sample\n\n",gain); 225 | /* to avoid not playing something, and to deal with kits like the 226 | k-27_trash_kit, let's just use the first layer */ 227 | sample->limit = sample->layers[0].limit; 228 | sample->info = sample->layers[0].info; 229 | sample->data = sample->layers[0].data; 230 | } 231 | 232 | static inline void trigger_sample(DrMr *drmr, int nn, uint8_t* const data, uint32_t offset) { 233 | // need to mutex this to avoid getting the samples array 234 | // changed after the check that the midi-note is valid 235 | pthread_mutex_lock(&drmr->load_mutex); 236 | if (nn >= 0 && nn < drmr->num_samples) { 237 | if (drmr->samples[nn].layer_count > 0) { 238 | layer_to_sample(drmr->samples+nn,*(drmr->gains[nn])); 239 | if (drmr->samples[nn].limit == 0) 240 | fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); 241 | } 242 | if (data) { 243 | lv2_atom_forge_frame_time(&drmr->forge, 0); 244 | build_midi_info_message(drmr,data); 245 | } 246 | drmr->samples[nn].active = 1; 247 | drmr->samples[nn].offset = 0; 248 | drmr->samples[nn].velocity = drmr->ignore_velocity?1.0f:((float)data[2])/VELOCITY_MAX; 249 | drmr->samples[nn].dataoffset = offset; 250 | } 251 | pthread_mutex_unlock(&drmr->load_mutex); 252 | } 253 | 254 | static inline void untrigger_sample(DrMr *drmr, int nn, uint32_t offset) { 255 | pthread_mutex_lock(&drmr->load_mutex); 256 | if (nn >= 0 && nn < drmr->num_samples) { 257 | if (drmr->samples[nn].layer_count > 0) { 258 | layer_to_sample(drmr->samples+nn,*(drmr->gains[nn])); 259 | if (drmr->samples[nn].limit == 0) 260 | fprintf(stderr,"Failed to find layer at: %i for %f\n",nn,*drmr->gains[nn]); 261 | } 262 | drmr->samples[nn].active = 0; 263 | drmr->samples[nn].dataoffset = offset; 264 | } 265 | pthread_mutex_unlock(&drmr->load_mutex); 266 | } 267 | 268 | #define DB3SCALE -0.8317830986718104f 269 | #define DB3SCALEPO 1.8317830986718104f 270 | // taken from lv2 example amp plugin 271 | #define DB_CO(g) ((g) > GAIN_MIN ? powf(10.0f, (g) * 0.05f) : 0.0f) 272 | 273 | static void run(LV2_Handle instance, uint32_t n_samples) { 274 | int i,baseNote; 275 | DrMr* drmr = (DrMr*)instance; 276 | 277 | baseNote = (int)floorf(*(drmr->baseNote)); 278 | 279 | const uint32_t event_capacity = drmr->core_event_port->atom.size; 280 | lv2_atom_forge_set_buffer(&drmr->forge, 281 | (uint8_t*)drmr->core_event_port, 282 | event_capacity); 283 | LV2_Atom_Forge_Frame seq_frame; 284 | lv2_atom_forge_sequence_head(&drmr->forge, &seq_frame, 0); 285 | 286 | LV2_ATOM_SEQUENCE_FOREACH(drmr->control_port, ev) { 287 | if (ev->body.type == drmr->uris.midi_event) { 288 | uint8_t nn; 289 | uint8_t* const data = (uint8_t* const)(ev + 1); 290 | uint32_t offset = (ev->time.frames > 0 && ev->time.frames < n_samples) ? ev->time.frames : 0; 291 | //int channel = *data & 15; 292 | switch ((*data) >> 4) { 293 | case 8: 294 | if (!drmr->ignore_note_off) { 295 | nn = data[1]; 296 | nn-=baseNote; 297 | untrigger_sample(drmr,nn,offset); 298 | } 299 | break; 300 | case 9: { 301 | nn = data[1]; 302 | nn-=baseNote; 303 | trigger_sample(drmr,nn,data,offset); 304 | break; 305 | } 306 | default: 307 | //printf("Unhandeled status: %i\n",(*data)>>4); 308 | break; 309 | } 310 | } 311 | else if (ev->body.type == drmr->uris.atom_resource) { 312 | const LV2_Atom_Object *obj = (LV2_Atom_Object*)&ev->body; 313 | if (obj->body.otype == drmr->uris.ui_msg) { 314 | const LV2_Atom* path = NULL; 315 | const LV2_Atom* trigger = NULL; 316 | const LV2_Atom* ignvel = NULL; 317 | const LV2_Atom* ignno = NULL; 318 | const LV2_Atom* zerop = NULL; 319 | lv2_atom_object_get(obj, 320 | drmr->uris.kit_path, &path, 321 | drmr->uris.sample_trigger, &trigger, 322 | drmr->uris.velocity_toggle, &ignvel, 323 | drmr->uris.note_off_toggle, &ignno, 324 | drmr->uris.zero_position, &zerop, 325 | 0); 326 | if (path) { 327 | int reqPos = (drmr->curReq+1)%REQ_BUF_SIZE; 328 | char *tmp = NULL; 329 | if (reqPos >= 0 && 330 | drmr->request_buf[reqPos]) 331 | tmp = drmr->request_buf[reqPos]; 332 | drmr->request_buf[reqPos] = strdup(LV2_ATOM_BODY(path)); 333 | drmr->curReq = reqPos; 334 | if (tmp) free(tmp); 335 | } 336 | if (trigger) { 337 | int32_t si = ((const LV2_Atom_Int*)trigger)->body; 338 | uint8_t mdata[3]; 339 | uint32_t offset = (ev->time.frames > 0 && ev->time.frames < n_samples) ? ev->time.frames : 0; 340 | mdata[0] = 0x90; // note on 341 | mdata[1] = si+baseNote; 342 | mdata[2] = 0x7f; 343 | trigger_sample(drmr,si,mdata,offset); 344 | } 345 | if (ignvel) 346 | drmr->ignore_velocity = ((const LV2_Atom_Bool*)ignvel)->body; 347 | if (ignno) 348 | drmr->ignore_note_off = ((const LV2_Atom_Bool*)ignno)->body; 349 | if (zerop) 350 | drmr->zero_position = ((const LV2_Atom_Int*)zerop)->body; 351 | } else if (obj->body.otype == drmr->uris.get_state) { 352 | lv2_atom_forge_frame_time(&drmr->forge, 0); 353 | build_state_message(drmr); 354 | } 355 | } 356 | //else printf("unrecognized event\n"); 357 | } 358 | 359 | if ((drmr->curReq >= 0) && 360 | drmr->request_buf[drmr->curReq] && 361 | (!drmr->current_path || 362 | strcmp(drmr->current_path, 363 | drmr->request_buf[drmr->curReq]))) 364 | pthread_cond_signal(&drmr->load_cond); 365 | 366 | if (current_kit_changed) { 367 | current_kit_changed = 0; 368 | lv2_atom_forge_frame_time(&drmr->forge, 0); 369 | build_update_message(drmr); 370 | } 371 | 372 | lv2_atom_forge_pop(&drmr->forge, &seq_frame); 373 | 374 | for(i = 0;ileft[i] = 0.0f; 376 | drmr->right[i] = 0.0f; 377 | } 378 | 379 | pthread_mutex_lock(&drmr->load_mutex); 380 | for (i = 0;i < drmr->num_samples;i++) { 381 | int pos,lim; 382 | drmr_sample* cs = drmr->samples+i; 383 | if ((cs->active || cs->dataoffset) && (cs->limit > 0)) { 384 | float coef_right, coef_left; 385 | if (i < 32) { 386 | float gain = DB_CO(*(drmr->gains[i])); 387 | float pan_right = ((*drmr->pans[i])+1)/2.0f; 388 | float pan_left = 1-pan_right; 389 | coef_right = (pan_right * (DB3SCALE * pan_right + DB3SCALEPO))*gain*cs->velocity; 390 | coef_left = (pan_left * (DB3SCALE * pan_left + DB3SCALEPO))*gain*cs->velocity; 391 | } 392 | else { 393 | coef_right = coef_left = 1.0f; 394 | } 395 | 396 | int datastart, dataend; 397 | if (cs->active) { 398 | datastart = cs->dataoffset; 399 | dataend = n_samples; 400 | } else { 401 | datastart = 0; 402 | dataend = cs->dataoffset; 403 | } 404 | cs->dataoffset = 0; 405 | 406 | if (cs->info->channels == 1) { // play mono sample 407 | lim = (n_samples < (cs->limit - cs->offset)?n_samples:(cs->limit-cs->offset)); 408 | for (pos = datastart; pos < lim && pos < dataend; pos++) { 409 | drmr->left[pos] += cs->data[cs->offset]*coef_left; 410 | drmr->right[pos] += cs->data[cs->offset]*coef_right; 411 | cs->offset++; 412 | } 413 | } else { // play stereo sample 414 | lim = (cs->limit-cs->offset)/cs->info->channels; 415 | if (lim > n_samples) lim = n_samples; 416 | for (pos = datastart; pos < lim && pos < dataend; pos++) { 417 | drmr->left[pos] += cs->data[cs->offset++]*coef_left; 418 | drmr->right[pos] += cs->data[cs->offset++]*coef_right; 419 | } 420 | } 421 | if (cs->offset >= cs->limit) cs->active = 0; 422 | } 423 | } 424 | pthread_mutex_unlock(&drmr->load_mutex); 425 | } 426 | 427 | static void cleanup(LV2_Handle instance) { 428 | DrMr* drmr = (DrMr*)instance; 429 | pthread_cancel(drmr->load_thread); 430 | pthread_join(drmr->load_thread, 0); 431 | if (drmr->num_samples > 0) 432 | free_samples(drmr->samples,drmr->num_samples); 433 | free(drmr->gains); 434 | free(instance); 435 | } 436 | 437 | static LV2_State_Status 438 | save_state(LV2_Handle instance, 439 | LV2_State_Store_Function store, 440 | void* handle, 441 | uint32_t flags, 442 | const LV2_Feature *const * features) { 443 | DrMr *drmr = (DrMr*)instance; 444 | LV2_State_Map_Path* map_path = NULL; 445 | int32_t flag; 446 | LV2_State_Status stat = LV2_STATE_SUCCESS; 447 | 448 | while(*features) { 449 | if (!strcmp((*features)->URI, LV2_STATE__mapPath)) 450 | map_path = (LV2_State_Map_Path*)((*features)->data); 451 | features++; 452 | } 453 | 454 | if (map_path == NULL) { 455 | fprintf(stderr,"Host does not support map_path, cannot save state\n"); 456 | return LV2_STATE_ERR_NO_FEATURE; 457 | } 458 | 459 | if (drmr->current_path != NULL) { 460 | char* mapped_path = map_path->abstract_path(map_path->handle, 461 | drmr->current_path); 462 | 463 | stat = store(handle, 464 | drmr->uris.kit_path, 465 | mapped_path, 466 | strlen(mapped_path) + 1, 467 | drmr->uris.string_urid, 468 | LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); 469 | if (stat) return stat; 470 | } 471 | 472 | flag = drmr->ignore_velocity?1:0; 473 | stat = store(handle, 474 | drmr->uris.velocity_toggle, 475 | &flag, 476 | sizeof(int32_t), 477 | drmr->uris.bool_urid, 478 | LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); 479 | if (stat) return stat; 480 | 481 | flag = drmr->ignore_note_off?1:0; 482 | stat = store(handle, 483 | drmr->uris.note_off_toggle, 484 | &flag, 485 | sizeof(uint32_t), 486 | drmr->uris.bool_urid, 487 | LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); 488 | if (stat) return stat; 489 | 490 | stat = store(handle, 491 | drmr->uris.zero_position, 492 | &drmr->zero_position, 493 | sizeof(int), 494 | drmr->uris.int_urid, 495 | LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); 496 | return stat; 497 | } 498 | 499 | static LV2_State_Status 500 | restore_state(LV2_Handle instance, 501 | LV2_State_Retrieve_Function retrieve, 502 | void* handle, 503 | uint32_t flags, 504 | const LV2_Feature *const * features) { 505 | DrMr* drmr = (DrMr*)instance; 506 | size_t size; 507 | uint32_t type; 508 | uint32_t fgs; 509 | 510 | LV2_State_Map_Path* map_path = NULL; 511 | while(*features) { 512 | if (!strcmp((*features)->URI, LV2_STATE__mapPath)) 513 | map_path = (LV2_State_Map_Path*)((*features)->data); 514 | features++; 515 | } 516 | 517 | if (map_path == NULL) { 518 | fprintf(stderr,"Host does not support map_path, cannot restore state\n"); 519 | return LV2_STATE_ERR_NO_FEATURE; 520 | } 521 | 522 | 523 | const char* abstract_path = 524 | retrieve(handle, drmr->uris.kit_path, &size, &type, &fgs); 525 | 526 | if (!abstract_path) { 527 | fprintf(stderr,"Found no path in state, not restoring\n"); 528 | return LV2_STATE_ERR_NO_PROPERTY; 529 | } 530 | 531 | char *kit_path = map_path->absolute_path(map_path->handle,abstract_path); 532 | 533 | if (kit_path) { // safe as we're in "Instantiation" threading class 534 | int reqPos = (drmr->curReq+1)%REQ_BUF_SIZE; 535 | char *tmp = NULL; 536 | if (reqPos >= 0 && drmr->request_buf[reqPos]) 537 | tmp = drmr->request_buf[reqPos]; 538 | drmr->request_buf[reqPos] = strdup(kit_path); 539 | drmr->curReq = reqPos; 540 | if (tmp) free(tmp); 541 | } 542 | 543 | const uint32_t* ignore_velocity = 544 | retrieve(handle, drmr->uris.velocity_toggle, &size, &type, &fgs); 545 | if (ignore_velocity) 546 | drmr->ignore_velocity = *ignore_velocity?true:false; 547 | 548 | const uint32_t* ignore_note_off = 549 | retrieve(handle, drmr->uris.note_off_toggle, &size, &type, &fgs); 550 | if (ignore_note_off) 551 | drmr->ignore_note_off = *ignore_note_off?true:false; 552 | 553 | const int* zero_position = 554 | retrieve(handle, drmr->uris.zero_position, &size, &type, &fgs); 555 | if (zero_position) 556 | drmr->zero_position = *zero_position; 557 | 558 | return LV2_STATE_SUCCESS; 559 | } 560 | 561 | 562 | static const void* extension_data(const char* uri) { 563 | static const LV2_State_Interface state_iface = { save_state, restore_state }; 564 | if (!strcmp(uri, LV2_STATE__interface)) return &state_iface; 565 | return NULL; 566 | } 567 | 568 | static const LV2_Descriptor descriptor = { 569 | DRMR_URI, 570 | instantiate, 571 | connect_port, 572 | NULL, // activate 573 | run, 574 | NULL, // deactivate 575 | cleanup, 576 | extension_data 577 | }; 578 | 579 | LV2_SYMBOL_EXPORT 580 | const LV2_Descriptor* 581 | lv2_descriptor(uint32_t index) 582 | { 583 | switch (index) { 584 | case 0: 585 | return &descriptor; 586 | default: 587 | return NULL; 588 | } 589 | } 590 | -------------------------------------------------------------------------------- /drmr.ttl: -------------------------------------------------------------------------------- 1 | @prefix lv2: . 2 | @prefix foaf: . 3 | @prefix doap: . 4 | @prefix rdf: . 5 | @prefix rdfs: . 6 | @prefix ui: . 7 | @prefix atom: . 8 | @prefix urid: . 9 | 10 | 11 | a lv2:InstrumentPlugin, lv2:Plugin; 12 | lv2:binary ; 13 | doap:name "DrMr Sampler"; 14 | doap:maintainer [ 15 | foaf:name "Nick Lanham" ; 16 | foaf:homepage ; 17 | foaf:mbox 18 | ] ; 19 | doap:license ; 20 | lv2:requiredFeature urid:map ; 21 | ui:ui ; 22 | lv2:extensionData ; 23 | lv2:port [ 24 | a lv2:InputPort , atom:AtomPort; 25 | atom:bufferType atom:Sequence ; 26 | atom:supports , 27 | ; 28 | lv2:index 0; 29 | lv2:symbol "control"; 30 | lv2:name "Control"; 31 | ], 32 | [ 33 | a lv2:OutputPort , atom:AtomPort ; 34 | atom:bufferType atom:Sequence ; 35 | atom:supports ; 36 | lv2:index 68 ; 37 | lv2:symbol "core_events" ; 38 | lv2:name "Core Events" 39 | ], 40 | [ 41 | a lv2:AudioPort, lv2:OutputPort; 42 | lv2:index 1; 43 | lv2:symbol "left"; 44 | lv2:name "Left"; 45 | ], 46 | 47 | [ 48 | a lv2:AudioPort, lv2:OutputPort; 49 | lv2:index 2; 50 | lv2:symbol "right"; 51 | lv2:name "Right"; 52 | ], 53 | 54 | [ 55 | a lv2:ControlPort, lv2:InputPort; 56 | lv2:index 3; 57 | lv2:symbol "base_note"; 58 | lv2:name "Midi Base Note"; 59 | lv2:minimum 21; 60 | lv2:maximum 107; 61 | lv2:default 36; 62 | lv2:portProperty lv2:integer; 63 | ], 64 | 65 | [ 66 | a lv2:ControlPort, lv2:InputPort; 67 | lv2:index 4; 68 | lv2:symbol "gain_one"; 69 | lv2:name "Sample One Gain"; 70 | lv2:minimum -60.0; 71 | lv2:maximum 6.0; 72 | lv2:default 0.0; 73 | lv2:scalePoint [ 74 | rdfs:label "-inf" ; 75 | rdf:value -60.0 76 | ] 77 | ], 78 | 79 | [ 80 | a lv2:ControlPort, lv2:InputPort; 81 | lv2:index 5; 82 | lv2:symbol "gain_two"; 83 | lv2:name "Sample Two Gain"; 84 | lv2:minimum -60.0; 85 | lv2:maximum 6.0; 86 | lv2:default 0.0; 87 | lv2:scalePoint [ 88 | rdfs:label "-inf" ; 89 | rdf:value -60.0 90 | ] 91 | ], 92 | 93 | [ 94 | a lv2:ControlPort, lv2:InputPort; 95 | lv2:index 6; 96 | lv2:symbol "gain_three"; 97 | lv2:name "Sample Three Gain"; 98 | lv2:minimum -60.0; 99 | lv2:maximum 6.0; 100 | lv2:default 0.0; 101 | lv2:scalePoint [ 102 | rdfs:label "-inf" ; 103 | rdf:value -60.0 104 | ] 105 | ], 106 | 107 | [ 108 | a lv2:ControlPort, lv2:InputPort; 109 | lv2:index 7; 110 | lv2:symbol "gain_four"; 111 | lv2:name "Sample Four Gain"; 112 | lv2:minimum -60.0; 113 | lv2:maximum 6.0; 114 | lv2:default 0.0; 115 | lv2:scalePoint [ 116 | rdfs:label "-inf" ; 117 | rdf:value -60.0 118 | ] 119 | ], 120 | 121 | [ 122 | a lv2:ControlPort, lv2:InputPort; 123 | lv2:index 8; 124 | lv2:symbol "gain_five"; 125 | lv2:name "Sample Five Gain"; 126 | lv2:minimum -60.0; 127 | lv2:maximum 6.0; 128 | lv2:default 0.0; 129 | lv2:scalePoint [ 130 | rdfs:label "-inf" ; 131 | rdf:value -60.0 132 | ] 133 | ], 134 | 135 | [ 136 | a lv2:ControlPort, lv2:InputPort; 137 | lv2:index 9; 138 | lv2:symbol "gain_six"; 139 | lv2:name "Sample Six Gain"; 140 | lv2:minimum -60.0; 141 | lv2:maximum 6.0; 142 | lv2:default 0.0; 143 | lv2:scalePoint [ 144 | rdfs:label "-inf" ; 145 | rdf:value -60.0 146 | ] 147 | ], 148 | 149 | [ 150 | a lv2:ControlPort, lv2:InputPort; 151 | lv2:index 10; 152 | lv2:symbol "gain_seven"; 153 | lv2:name "Sample Seven Gain"; 154 | lv2:minimum -60.0; 155 | lv2:maximum 6.0; 156 | lv2:default 0.0; 157 | lv2:scalePoint [ 158 | rdfs:label "-inf" ; 159 | rdf:value -60.0 160 | ] 161 | ], 162 | 163 | [ 164 | a lv2:ControlPort, lv2:InputPort; 165 | lv2:index 11; 166 | lv2:symbol "gain_eight"; 167 | lv2:name "Sample Eight Gain"; 168 | lv2:minimum -60.0; 169 | lv2:maximum 6.0; 170 | lv2:default 0.0; 171 | lv2:scalePoint [ 172 | rdfs:label "-inf" ; 173 | rdf:value -60.0 174 | ] 175 | ], 176 | 177 | [ 178 | a lv2:ControlPort, lv2:InputPort; 179 | lv2:index 12; 180 | lv2:symbol "gain_nine"; 181 | lv2:name "Sample Nine Gain"; 182 | lv2:minimum -60.0; 183 | lv2:maximum 6.0; 184 | lv2:default 0.0; 185 | lv2:scalePoint [ 186 | rdfs:label "-inf" ; 187 | rdf:value -60.0 188 | ] 189 | ], 190 | 191 | [ 192 | a lv2:ControlPort, lv2:InputPort; 193 | lv2:index 13; 194 | lv2:symbol "gain_ten"; 195 | lv2:name "Sample Ten Gain"; 196 | lv2:minimum -60.0; 197 | lv2:maximum 6.0; 198 | lv2:default 0.0; 199 | lv2:scalePoint [ 200 | rdfs:label "-inf" ; 201 | rdf:value -60.0 202 | ] 203 | ], 204 | 205 | [ 206 | a lv2:ControlPort, lv2:InputPort; 207 | lv2:index 14; 208 | lv2:symbol "gain_eleven"; 209 | lv2:name "Sample Eleven Gain"; 210 | lv2:minimum -60.0; 211 | lv2:maximum 6.0; 212 | lv2:default 0.0; 213 | lv2:scalePoint [ 214 | rdfs:label "-inf" ; 215 | rdf:value -60.0 216 | ] 217 | ], 218 | 219 | [ 220 | a lv2:ControlPort, lv2:InputPort; 221 | lv2:index 15; 222 | lv2:symbol "gain_twelve"; 223 | lv2:name "Sample Twelve Gain"; 224 | lv2:minimum -60.0; 225 | lv2:maximum 6.0; 226 | lv2:default 0.0; 227 | lv2:scalePoint [ 228 | rdfs:label "-inf" ; 229 | rdf:value -60.0 230 | ] 231 | ], 232 | 233 | [ 234 | a lv2:ControlPort, lv2:InputPort; 235 | lv2:index 16; 236 | lv2:symbol "gain_thirteen"; 237 | lv2:name "Sample Thirteen Gain"; 238 | lv2:minimum -60.0; 239 | lv2:maximum 6.0; 240 | lv2:default 0.0; 241 | lv2:scalePoint [ 242 | rdfs:label "-inf" ; 243 | rdf:value -60.0 244 | ] 245 | ], 246 | 247 | [ 248 | a lv2:ControlPort, lv2:InputPort; 249 | lv2:index 17; 250 | lv2:symbol "gain_fourteen"; 251 | lv2:name "Sample Fourteen Gain"; 252 | lv2:minimum -60.0; 253 | lv2:maximum 6.0; 254 | lv2:default 0.0; 255 | lv2:scalePoint [ 256 | rdfs:label "-inf" ; 257 | rdf:value -60.0 258 | ] 259 | ], 260 | 261 | [ 262 | a lv2:ControlPort, lv2:InputPort; 263 | lv2:index 18; 264 | lv2:symbol "gain_fifteen"; 265 | lv2:name "Sample Fifteen Gain"; 266 | lv2:minimum -60.0; 267 | lv2:maximum 6.0; 268 | lv2:default 0.0; 269 | lv2:scalePoint [ 270 | rdfs:label "-inf" ; 271 | rdf:value -60.0 272 | ] 273 | ], 274 | 275 | [ 276 | a lv2:ControlPort, lv2:InputPort; 277 | lv2:index 19; 278 | lv2:symbol "gain_sixteen"; 279 | lv2:name "Sample Sixteen Gain"; 280 | lv2:minimum -60.0; 281 | lv2:maximum 6.0; 282 | lv2:default 0.0; 283 | lv2:scalePoint [ 284 | rdfs:label "-inf" ; 285 | rdf:value -60.0 286 | ] 287 | ], 288 | 289 | [ 290 | a lv2:ControlPort, lv2:InputPort; 291 | lv2:index 20; 292 | lv2:symbol "gain_seventeen"; 293 | lv2:name "Sample Seventeen Gain"; 294 | lv2:minimum -60.0; 295 | lv2:maximum 6.0; 296 | lv2:default 0.0; 297 | lv2:scalePoint [ 298 | rdfs:label "-inf" ; 299 | rdf:value -60.0 300 | ] 301 | ], 302 | 303 | 304 | [ 305 | a lv2:ControlPort, lv2:InputPort; 306 | lv2:index 21; 307 | lv2:symbol "gain_eighteen"; 308 | lv2:name "Sample Eighteen Gain"; 309 | lv2:minimum -60.0; 310 | lv2:maximum 6.0; 311 | lv2:default 0.0; 312 | lv2:scalePoint [ 313 | rdfs:label "-inf" ; 314 | rdf:value -60.0 315 | ] 316 | ], 317 | 318 | [ 319 | a lv2:ControlPort, lv2:InputPort; 320 | lv2:index 22; 321 | lv2:symbol "gain_nineteen"; 322 | lv2:name "Sample Nineteen Gain"; 323 | lv2:minimum -60.0; 324 | lv2:maximum 6.0; 325 | lv2:default 0.0; 326 | lv2:scalePoint [ 327 | rdfs:label "-inf" ; 328 | rdf:value -60.0 329 | ] 330 | ], 331 | 332 | [ 333 | a lv2:ControlPort, lv2:InputPort; 334 | lv2:index 23; 335 | lv2:symbol "gain_twenty"; 336 | lv2:name "Sample Twenty Gain"; 337 | lv2:minimum -60.0; 338 | lv2:maximum 6.0; 339 | lv2:default 0.0; 340 | lv2:scalePoint [ 341 | rdfs:label "-inf" ; 342 | rdf:value -60.0 343 | ] 344 | ], 345 | 346 | [ 347 | a lv2:ControlPort, lv2:InputPort; 348 | lv2:index 24; 349 | lv2:symbol "gain_twentyone"; 350 | lv2:name "Sample Twenty One Gain"; 351 | lv2:minimum -60.0; 352 | lv2:maximum 6.0; 353 | lv2:default 0.0; 354 | lv2:scalePoint [ 355 | rdfs:label "-inf" ; 356 | rdf:value -60.0 357 | ] 358 | ], 359 | 360 | [ 361 | a lv2:ControlPort, lv2:InputPort; 362 | lv2:index 25; 363 | lv2:symbol "gain_twentytwo"; 364 | lv2:name "Sample Twenty Two Gain"; 365 | lv2:minimum -60.0; 366 | lv2:maximum 6.0; 367 | lv2:default 0.0; 368 | lv2:scalePoint [ 369 | rdfs:label "-inf" ; 370 | rdf:value -60.0 371 | ] 372 | ], 373 | 374 | [ 375 | a lv2:ControlPort, lv2:InputPort; 376 | lv2:index 26; 377 | lv2:symbol "gain_twentythree"; 378 | lv2:name "Sample Twenty Three Gain"; 379 | lv2:minimum -60.0; 380 | lv2:maximum 6.0; 381 | lv2:default 0.0; 382 | lv2:scalePoint [ 383 | rdfs:label "-inf" ; 384 | rdf:value -60.0 385 | ] 386 | ], 387 | 388 | [ 389 | a lv2:ControlPort, lv2:InputPort; 390 | lv2:index 27; 391 | lv2:symbol "gain_twentyfour"; 392 | lv2:name "Sample Twenty Four Gain"; 393 | lv2:minimum -60.0; 394 | lv2:maximum 6.0; 395 | lv2:default 0.0; 396 | lv2:scalePoint [ 397 | rdfs:label "-inf" ; 398 | rdf:value -60.0 399 | ] 400 | ], 401 | 402 | [ 403 | a lv2:ControlPort, lv2:InputPort; 404 | lv2:index 28; 405 | lv2:symbol "gain_twentyfive"; 406 | lv2:name "Sample Twenty Five Gain"; 407 | lv2:minimum -60.0; 408 | lv2:maximum 6.0; 409 | lv2:default 0.0; 410 | lv2:scalePoint [ 411 | rdfs:label "-inf" ; 412 | rdf:value -60.0 413 | ] 414 | ], 415 | 416 | [ 417 | a lv2:ControlPort, lv2:InputPort; 418 | lv2:index 29; 419 | lv2:symbol "gain_twentysix"; 420 | lv2:name "Sample Twenty Six Gain"; 421 | lv2:minimum -60.0; 422 | lv2:maximum 6.0; 423 | lv2:default 0.0; 424 | lv2:scalePoint [ 425 | rdfs:label "-inf" ; 426 | rdf:value -60.0 427 | ] 428 | ], 429 | 430 | [ 431 | a lv2:ControlPort, lv2:InputPort; 432 | lv2:index 30; 433 | lv2:symbol "gain_twentyseven"; 434 | lv2:name "Sample Twenty Seven Gain"; 435 | lv2:minimum -60.0; 436 | lv2:maximum 6.0; 437 | lv2:default 0.0; 438 | lv2:scalePoint [ 439 | rdfs:label "-inf" ; 440 | rdf:value -60.0 441 | ] 442 | ], 443 | 444 | [ 445 | a lv2:ControlPort, lv2:InputPort; 446 | lv2:index 31; 447 | lv2:symbol "gain_twentyeight"; 448 | lv2:name "Sample Twenty Eight Gain"; 449 | lv2:minimum -60.0; 450 | lv2:maximum 6.0; 451 | lv2:default 0.0; 452 | lv2:scalePoint [ 453 | rdfs:label "-inf" ; 454 | rdf:value -60.0 455 | ] 456 | ], 457 | 458 | [ 459 | a lv2:ControlPort, lv2:InputPort; 460 | lv2:index 32; 461 | lv2:symbol "gain_twentynine"; 462 | lv2:name "Sample Twenty Nine Gain"; 463 | lv2:minimum -60.0; 464 | lv2:maximum 6.0; 465 | lv2:default 0.0; 466 | lv2:scalePoint [ 467 | rdfs:label "-inf" ; 468 | rdf:value -60.0 469 | ] 470 | ], 471 | 472 | [ 473 | a lv2:ControlPort, lv2:InputPort; 474 | lv2:index 33; 475 | lv2:symbol "gain_thirty"; 476 | lv2:name "Sample Thirty Gain"; 477 | lv2:minimum -60.0; 478 | lv2:maximum 6.0; 479 | lv2:default 0.0; 480 | lv2:scalePoint [ 481 | rdfs:label "-inf" ; 482 | rdf:value -60.0 483 | ] 484 | ], 485 | 486 | [ 487 | a lv2:ControlPort, lv2:InputPort; 488 | lv2:index 34; 489 | lv2:symbol "gain_thirtyone"; 490 | lv2:name "Sample Thirty One Gain"; 491 | lv2:minimum -60.0; 492 | lv2:maximum 6.0; 493 | lv2:default 0.0; 494 | lv2:scalePoint [ 495 | rdfs:label "-inf" ; 496 | rdf:value -60.0 497 | ] 498 | ], 499 | 500 | [ 501 | a lv2:ControlPort, lv2:InputPort; 502 | lv2:index 35; 503 | lv2:symbol "gain_thirtytwo"; 504 | lv2:name "Sample Thirty Two Gain"; 505 | lv2:minimum -60.0; 506 | lv2:maximum 6.0; 507 | lv2:default 0.0; 508 | lv2:scalePoint [ 509 | rdfs:label "-inf" ; 510 | rdf:value -60.0 511 | ] 512 | ], 513 | 514 | [ 515 | a lv2:ControlPort, lv2:InputPort; 516 | lv2:index 36; 517 | lv2:symbol "pan_one"; 518 | lv2:name "Sample One Pan"; 519 | lv2:minimum -1.0; 520 | lv2:maximum 1.0; 521 | lv2:default 0.0; 522 | ], 523 | 524 | [ 525 | a lv2:ControlPort, lv2:InputPort; 526 | lv2:index 37; 527 | lv2:symbol "pan_two"; 528 | lv2:name "Sample Two Pan"; 529 | lv2:minimum -1.0; 530 | lv2:maximum 1.0; 531 | lv2:default 0.0; 532 | ], 533 | 534 | [ 535 | a lv2:ControlPort, lv2:InputPort; 536 | lv2:index 38; 537 | lv2:symbol "pan_three"; 538 | lv2:name "Sample Three Pan"; 539 | lv2:minimum -1.0; 540 | lv2:maximum 1.0; 541 | lv2:default 0.0; 542 | ], 543 | 544 | [ 545 | a lv2:ControlPort, lv2:InputPort; 546 | lv2:index 39; 547 | lv2:symbol "pan_four"; 548 | lv2:name "Sample Four Pan"; 549 | lv2:minimum -1.0; 550 | lv2:maximum 1.0; 551 | lv2:default 0.0; 552 | ], 553 | 554 | [ 555 | a lv2:ControlPort, lv2:InputPort; 556 | lv2:index 40; 557 | lv2:symbol "pan_five"; 558 | lv2:name "Sample Five Pan"; 559 | lv2:minimum -1.0; 560 | lv2:maximum 1.0; 561 | lv2:default 0.0; 562 | ], 563 | 564 | [ 565 | a lv2:ControlPort, lv2:InputPort; 566 | lv2:index 41; 567 | lv2:symbol "pan_six"; 568 | lv2:name "Sample Six Pan"; 569 | lv2:minimum -1.0; 570 | lv2:maximum 1.0; 571 | lv2:default 0.0; 572 | ], 573 | 574 | [ 575 | a lv2:ControlPort, lv2:InputPort; 576 | lv2:index 42; 577 | lv2:symbol "pan_seven"; 578 | lv2:name "Sample Seven Pan"; 579 | lv2:minimum -1.0; 580 | lv2:maximum 1.0; 581 | lv2:default 0.0; 582 | ], 583 | 584 | [ 585 | a lv2:ControlPort, lv2:InputPort; 586 | lv2:index 43; 587 | lv2:symbol "pan_eight"; 588 | lv2:name "Sample Eight Pan"; 589 | lv2:minimum -1.0; 590 | lv2:maximum 1.0; 591 | lv2:default 0.0; 592 | ], 593 | 594 | [ 595 | a lv2:ControlPort, lv2:InputPort; 596 | lv2:index 44; 597 | lv2:symbol "pan_nine"; 598 | lv2:name "Sample Nine Pan"; 599 | lv2:minimum -1.0; 600 | lv2:maximum 1.0; 601 | lv2:default 0.0; 602 | ], 603 | 604 | [ 605 | a lv2:ControlPort, lv2:InputPort; 606 | lv2:index 45; 607 | lv2:symbol "pan_ten"; 608 | lv2:name "Sample Ten Pan"; 609 | lv2:minimum -1.0; 610 | lv2:maximum 1.0; 611 | lv2:default 0.0; 612 | ], 613 | 614 | [ 615 | a lv2:ControlPort, lv2:InputPort; 616 | lv2:index 46; 617 | lv2:symbol "pan_eleven"; 618 | lv2:name "Sample Eleven Pan"; 619 | lv2:minimum -1.0; 620 | lv2:maximum 1.0; 621 | lv2:default 0.0; 622 | ], 623 | 624 | [ 625 | a lv2:ControlPort, lv2:InputPort; 626 | lv2:index 47; 627 | lv2:symbol "pan_twelve"; 628 | lv2:name "Sample Twelve Pan"; 629 | lv2:minimum -1.0; 630 | lv2:maximum 1.0; 631 | lv2:default 0.0; 632 | ], 633 | 634 | [ 635 | a lv2:ControlPort, lv2:InputPort; 636 | lv2:index 48; 637 | lv2:symbol "pan_thirteen"; 638 | lv2:name "Sample Thirteen Pan"; 639 | lv2:minimum -1.0; 640 | lv2:maximum 1.0; 641 | lv2:default 0.0; 642 | ], 643 | 644 | [ 645 | a lv2:ControlPort, lv2:InputPort; 646 | lv2:index 49; 647 | lv2:symbol "pan_fourteen"; 648 | lv2:name "Sample Fourteen Pan"; 649 | lv2:minimum -1.0; 650 | lv2:maximum 1.0; 651 | lv2:default 0.0; 652 | ], 653 | 654 | [ 655 | a lv2:ControlPort, lv2:InputPort; 656 | lv2:index 50; 657 | lv2:symbol "pan_fifteen"; 658 | lv2:name "Sample Fifteen Pan"; 659 | lv2:minimum -1.0; 660 | lv2:maximum 1.0; 661 | lv2:default 0.0; 662 | ], 663 | 664 | [ 665 | a lv2:ControlPort, lv2:InputPort; 666 | lv2:index 51; 667 | lv2:symbol "pan_sixteen"; 668 | lv2:name "Sample Sixteen Pan"; 669 | lv2:minimum -1.0; 670 | lv2:maximum 1.0; 671 | lv2:default 0.0; 672 | ], 673 | 674 | [ 675 | a lv2:ControlPort, lv2:InputPort; 676 | lv2:index 52; 677 | lv2:symbol "pan_seventeen"; 678 | lv2:name "Sample Seventeen Pan"; 679 | lv2:minimum -1.0; 680 | lv2:maximum 1.0; 681 | lv2:default 0.0; 682 | lv2:scalePoint [ 683 | rdfs:label "-inf" ; 684 | rdf:value -1.0 685 | ] 686 | ], 687 | 688 | 689 | [ 690 | a lv2:ControlPort, lv2:InputPort; 691 | lv2:index 53; 692 | lv2:symbol "pan_eighteen"; 693 | lv2:name "Sample Eighteen Pan"; 694 | lv2:minimum -1.0; 695 | lv2:maximum 1.0; 696 | lv2:default 0.0; 697 | lv2:scalePoint [ 698 | rdfs:label "-inf" ; 699 | rdf:value -1.0 700 | ] 701 | ], 702 | 703 | [ 704 | a lv2:ControlPort, lv2:InputPort; 705 | lv2:index 54; 706 | lv2:symbol "pan_nineteen"; 707 | lv2:name "Sample Nineteen Pan"; 708 | lv2:minimum -1.0; 709 | lv2:maximum 1.0; 710 | lv2:default 0.0; 711 | lv2:scalePoint [ 712 | rdfs:label "-inf" ; 713 | rdf:value -1.0 714 | ] 715 | ], 716 | 717 | [ 718 | a lv2:ControlPort, lv2:InputPort; 719 | lv2:index 55; 720 | lv2:symbol "pan_twenty"; 721 | lv2:name "Sample Twenty Pan"; 722 | lv2:minimum -1.0; 723 | lv2:maximum 1.0; 724 | lv2:default 0.0; 725 | lv2:scalePoint [ 726 | rdfs:label "-inf" ; 727 | rdf:value -1.0 728 | ] 729 | ], 730 | 731 | [ 732 | a lv2:ControlPort, lv2:InputPort; 733 | lv2:index 56; 734 | lv2:symbol "pan_twentyone"; 735 | lv2:name "Sample Twenty One Pan"; 736 | lv2:minimum -1.0; 737 | lv2:maximum 1.0; 738 | lv2:default 0.0; 739 | lv2:scalePoint [ 740 | rdfs:label "-inf" ; 741 | rdf:value -1.0 742 | ] 743 | ], 744 | 745 | [ 746 | a lv2:ControlPort, lv2:InputPort; 747 | lv2:index 57; 748 | lv2:symbol "pan_twentytwo"; 749 | lv2:name "Sample Twenty Two Pan"; 750 | lv2:minimum -1.0; 751 | lv2:maximum 1.0; 752 | lv2:default 0.0; 753 | lv2:scalePoint [ 754 | rdfs:label "-inf" ; 755 | rdf:value -1.0 756 | ] 757 | ], 758 | 759 | [ 760 | a lv2:ControlPort, lv2:InputPort; 761 | lv2:index 58; 762 | lv2:symbol "pan_twentythree"; 763 | lv2:name "Sample Twenty Three Pan"; 764 | lv2:minimum -1.0; 765 | lv2:maximum 1.0; 766 | lv2:default 0.0; 767 | lv2:scalePoint [ 768 | rdfs:label "-inf" ; 769 | rdf:value -1.0 770 | ] 771 | ], 772 | 773 | [ 774 | a lv2:ControlPort, lv2:InputPort; 775 | lv2:index 59; 776 | lv2:symbol "pan_twentyfour"; 777 | lv2:name "Sample Twenty Four Pan"; 778 | lv2:minimum -1.0; 779 | lv2:maximum 1.0; 780 | lv2:default 0.0; 781 | lv2:scalePoint [ 782 | rdfs:label "-inf" ; 783 | rdf:value -1.0 784 | ] 785 | ], 786 | 787 | [ 788 | a lv2:ControlPort, lv2:InputPort; 789 | lv2:index 60; 790 | lv2:symbol "pan_twentyfive"; 791 | lv2:name "Sample Twenty Five Pan"; 792 | lv2:minimum -1.0; 793 | lv2:maximum 1.0; 794 | lv2:default 0.0; 795 | lv2:scalePoint [ 796 | rdfs:label "-inf" ; 797 | rdf:value -1.0 798 | ] 799 | ], 800 | 801 | [ 802 | a lv2:ControlPort, lv2:InputPort; 803 | lv2:index 61; 804 | lv2:symbol "pan_twentysix"; 805 | lv2:name "Sample Twenty Six Pan"; 806 | lv2:minimum -1.0; 807 | lv2:maximum 1.0; 808 | lv2:default 0.0; 809 | lv2:scalePoint [ 810 | rdfs:label "-inf" ; 811 | rdf:value -1.0 812 | ] 813 | ], 814 | 815 | [ 816 | a lv2:ControlPort, lv2:InputPort; 817 | lv2:index 62; 818 | lv2:symbol "pan_twentyseven"; 819 | lv2:name "Sample Twenty Seven Pan"; 820 | lv2:minimum -1.0; 821 | lv2:maximum 1.0; 822 | lv2:default 0.0; 823 | lv2:scalePoint [ 824 | rdfs:label "-inf" ; 825 | rdf:value -1.0 826 | ] 827 | ], 828 | 829 | [ 830 | a lv2:ControlPort, lv2:InputPort; 831 | lv2:index 63; 832 | lv2:symbol "pan_twentyeight"; 833 | lv2:name "Sample Twenty Eight Pan"; 834 | lv2:minimum -1.0; 835 | lv2:maximum 1.0; 836 | lv2:default 0.0; 837 | lv2:scalePoint [ 838 | rdfs:label "-inf" ; 839 | rdf:value -1.0 840 | ] 841 | ], 842 | 843 | [ 844 | a lv2:ControlPort, lv2:InputPort; 845 | lv2:index 64; 846 | lv2:symbol "pan_twentynine"; 847 | lv2:name "Sample Twenty Nine Pan"; 848 | lv2:minimum -1.0; 849 | lv2:maximum 1.0; 850 | lv2:default 0.0; 851 | lv2:scalePoint [ 852 | rdfs:label "-inf" ; 853 | rdf:value -1.0 854 | ] 855 | ], 856 | 857 | [ 858 | a lv2:ControlPort, lv2:InputPort; 859 | lv2:index 65; 860 | lv2:symbol "pan_thirty"; 861 | lv2:name "Sample Thirty Pan"; 862 | lv2:minimum -1.0; 863 | lv2:maximum 1.0; 864 | lv2:default 0.0; 865 | lv2:scalePoint [ 866 | rdfs:label "-inf" ; 867 | rdf:value -1.0 868 | ] 869 | ], 870 | 871 | [ 872 | a lv2:ControlPort, lv2:InputPort; 873 | lv2:index 66; 874 | lv2:symbol "pan_thirtyone"; 875 | lv2:name "Sample Thirty One Pan"; 876 | lv2:minimum -1.0; 877 | lv2:maximum 1.0; 878 | lv2:default 0.0; 879 | lv2:scalePoint [ 880 | rdfs:label "-inf" ; 881 | rdf:value -1.0 882 | ] 883 | ], 884 | 885 | [ 886 | a lv2:ControlPort, lv2:InputPort; 887 | lv2:index 67; 888 | lv2:symbol "pan_thirtytwo"; 889 | lv2:name "Sample Thirty Two Pan"; 890 | lv2:minimum -1.0; 891 | lv2:maximum 1.0; 892 | lv2:default 0.0; 893 | ]. 894 | 895 | 896 | a ui:GtkUI ; 897 | ui:binary . -------------------------------------------------------------------------------- /drmr_ui.c: -------------------------------------------------------------------------------- 1 | /* drmr.c 2 | * LV2 DrMr plugin 3 | * Copyright 2012 Nick Lanham 4 | * 5 | * Public License v3. source code is available at 6 | * 7 | 8 | * THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include "drmr.h" 24 | #include "drmr_hydrogen.h" 25 | #include "nknob.h" 26 | 27 | #include "lv2/lv2plug.in/ns/ext/atom/atom.h" 28 | #include "lv2/lv2plug.in/ns/ext/atom/forge.h" 29 | #include "lv2/lv2plug.in/ns/ext/atom/util.h" 30 | #include "lv2/lv2plug.in/ns/ext/urid/urid.h" 31 | #include "lv2/lv2plug.in/ns/extensions/ui/ui.h" 32 | 33 | #define DRMR_UI_URI "http://github.com/nicklan/drmr#ui" 34 | #define NO_KIT_STRING "[No Current Kit]" 35 | 36 | typedef struct { 37 | LV2UI_Write_Function write; 38 | LV2UI_Controller controller; 39 | LV2_Atom_Forge forge; 40 | 41 | LV2_URID_Map *map; 42 | drmr_uris uris; 43 | 44 | GtkWidget *drmr_widget; 45 | GtkLabel *current_kit_label; 46 | GtkTable *sample_table; 47 | GtkComboBox *kit_combo; 48 | GtkWidget *no_kit_label; 49 | GtkSpinButton *base_spin; 50 | GtkLabel *base_label; 51 | GtkListStore *kit_store; 52 | GtkWidget** gain_sliders; 53 | GtkWidget** pan_sliders; 54 | float *gain_vals,*pan_vals; 55 | 56 | GtkWidget** notify_leds; 57 | GtkWidget *position_combo_box, *velocity_checkbox, *note_off_checkbox; 58 | 59 | gchar *bundle_path; 60 | 61 | int cols; 62 | int startSamp; 63 | 64 | gboolean forceUpdate; 65 | 66 | int samples; 67 | int baseNote; 68 | 69 | GQuark gain_quark, pan_quark, trigger_quark; 70 | 71 | int curKit; 72 | int kitReq; 73 | kits* kits; 74 | } DrMrUi; 75 | 76 | static GdkPixbuf *led_on_pixbuf=NULL,*led_off_pixbuf=NULL; 77 | 78 | static gboolean gain_callback(GtkRange* range, GtkScrollType type, gdouble value, gpointer data) { 79 | DrMrUi* ui = (DrMrUi*)data; 80 | int gidx = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(range),ui->gain_quark)); 81 | float gain = (float)value; 82 | ui->gain_vals[gidx] = gain; 83 | ui->write(ui->controller,gidx+DRMR_GAIN_ONE,4,0,&gain); 84 | return FALSE; 85 | } 86 | 87 | static gboolean pan_callback(GtkRange* range, GtkScrollType type, gdouble value, gpointer data) { 88 | DrMrUi* ui = (DrMrUi*)data; 89 | int pidx = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(range),ui->pan_quark)); 90 | float pan = (float)value; 91 | ui->pan_vals[pidx] = pan; 92 | ui->write(ui->controller,pidx+DRMR_PAN_ONE,4,0,&pan); 93 | return FALSE; 94 | } 95 | 96 | static void send_ui_msg(DrMrUi* ui, void (*add_data)(DrMrUi* ui, gpointer data), gpointer data) { 97 | LV2_Atom_Forge_Frame set_frame; 98 | uint8_t msg_buf[1024]; 99 | lv2_atom_forge_set_buffer(&ui->forge, msg_buf, 1024); 100 | LV2_Atom *msg = (LV2_Atom*)lv2_atom_forge_resource 101 | (&ui->forge, &set_frame, 1, ui->uris.ui_msg); 102 | (*add_data)(ui,data); 103 | lv2_atom_forge_pop(&ui->forge,&set_frame); 104 | ui->write(ui->controller,DRMR_CONTROL, 105 | lv2_atom_total_size(msg), 106 | ui->uris.atom_eventTransfer, 107 | msg); 108 | } 109 | 110 | static void led_data(DrMrUi *ui, gpointer data) { 111 | lv2_atom_forge_property_head(&ui->forge, ui->uris.sample_trigger,0); 112 | lv2_atom_forge_int(&ui->forge, GPOINTER_TO_INT(data)); 113 | } 114 | 115 | static void ignore_velocity_data(DrMrUi* ui, gpointer data) { 116 | lv2_atom_forge_property_head(&ui->forge, ui->uris.velocity_toggle,0); 117 | lv2_atom_forge_bool(&ui->forge, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data))); 118 | } 119 | 120 | static void ignore_note_off_data(DrMrUi* ui, gpointer data) { 121 | lv2_atom_forge_property_head(&ui->forge, ui->uris.note_off_toggle,0); 122 | lv2_atom_forge_bool(&ui->forge, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data))); 123 | } 124 | 125 | static gboolean trigger_led_clicked(GtkWidget *widget, GdkEvent *event, gpointer data) { 126 | DrMrUi* ui = (DrMrUi*)data; 127 | send_ui_msg(ui,&led_data,g_object_get_qdata(G_OBJECT(widget),ui->trigger_quark)); 128 | return FALSE; 129 | } 130 | 131 | static gboolean ignore_velocity_toggled(GtkToggleButton *button, gpointer data) { 132 | DrMrUi* ui = (DrMrUi*)data; 133 | send_ui_msg(ui,&ignore_velocity_data,button); 134 | return FALSE; 135 | } 136 | 137 | static gboolean ignore_note_off_toggled(GtkToggleButton *button, gpointer data) { 138 | DrMrUi* ui = (DrMrUi*)data; 139 | send_ui_msg(ui,&ignore_note_off_data,button); 140 | return FALSE; 141 | } 142 | 143 | static void fill_sample_table(DrMrUi* ui, int samples, char** names, GtkWidget** notify_leds, GtkWidget** gain_sliders, GtkWidget** pan_sliders) { 144 | int row = 0; 145 | int col = 0; 146 | int si; 147 | gchar buf[64]; 148 | int rows = (samples/ui->cols); 149 | if (samples % ui->cols != 0) rows++; 150 | gtk_table_resize(ui->sample_table,rows,ui->cols); 151 | 152 | switch (ui->startSamp) { 153 | case 1: // bottom left 154 | row = rows-1; 155 | break; 156 | case 2: // top right 157 | col = ui->cols-1; 158 | break; 159 | case 3: // bottom right 160 | row = rows-1; 161 | col = ui->cols-1; 162 | break; 163 | } 164 | 165 | for(si = 0;si%s (%i)",names[si],si); 175 | 176 | frame = gtk_frame_new(buf); 177 | gtk_label_set_use_markup(GTK_LABEL(gtk_frame_get_label_widget(GTK_FRAME(frame))),true); 178 | gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_OUT); 179 | 180 | vbox = gtk_vbox_new(false,5); 181 | hbox = gtk_hbox_new(false,0); 182 | 183 | #ifdef NO_NKNOB 184 | gain_slider = gtk_vscale_new_with_range(GAIN_MIN,6.0,1.0); 185 | gtk_scale_set_value_pos(GTK_SCALE(gain_slider),GTK_POS_BOTTOM); 186 | gtk_scale_set_digits(GTK_SCALE(gain_slider),1); 187 | gtk_scale_add_mark(GTK_SCALE(gain_slider),0.0,GTK_POS_RIGHT,"0 dB"); 188 | // Hrmm, -inf label is at top in ardour for some reason 189 | //gtk_scale_add_mark(GTK_SCALE(gain_slider),GAIN_MIN,GTK_POS_RIGHT,"-inf"); 190 | gtk_range_set_inverted(GTK_RANGE(gain_slider),true); 191 | slide_expand = true; 192 | #else 193 | gain_slider = n_knob_new_with_range(0.0,GAIN_MIN,6.0,1.0); 194 | n_knob_set_load_prefix(N_KNOB(gain_slider),ui->bundle_path); 195 | gtk_widget_set_has_tooltip(gain_slider,TRUE); 196 | slide_expand = false; 197 | #endif 198 | g_object_set_qdata (G_OBJECT(gain_slider),ui->gain_quark,GINT_TO_POINTER(si)); 199 | if (gain_sliders) gain_sliders[si] = gain_slider; 200 | if (si < 32) 201 | gtk_range_set_value(GTK_RANGE(gain_slider),ui->gain_vals[si]); 202 | else // things are gross if we have > 32 samples, what to do? 203 | gtk_range_set_value(GTK_RANGE(gain_slider),0.0); 204 | g_signal_connect(G_OBJECT(gain_slider),"change-value",G_CALLBACK(gain_callback),ui); 205 | gain_label = gtk_label_new("Gain"); 206 | gain_vbox = gtk_vbox_new(false,0); 207 | 208 | #ifdef NO_NKNOB 209 | pan_slider = gtk_hscale_new_with_range(-1.0,1.0,0.1); 210 | gtk_scale_add_mark(GTK_SCALE(pan_slider),0.0,GTK_POS_TOP,NULL); 211 | #else 212 | pan_slider = n_knob_new_with_range(0.0,-1.0,1.0,0.1); 213 | n_knob_set_load_prefix(N_KNOB(pan_slider),ui->bundle_path); 214 | gtk_widget_set_has_tooltip(pan_slider,TRUE); 215 | #endif 216 | if (pan_sliders) pan_sliders[si] = pan_slider; 217 | if (si < 32) 218 | gtk_range_set_value(GTK_RANGE(pan_slider),ui->pan_vals[si]); 219 | else 220 | gtk_range_set_value(GTK_RANGE(pan_slider),0); 221 | g_object_set_qdata (G_OBJECT(pan_slider),ui->pan_quark,GINT_TO_POINTER(si)); 222 | g_signal_connect(G_OBJECT(pan_slider),"change-value",G_CALLBACK(pan_callback),ui); 223 | pan_label = gtk_label_new("Pan"); 224 | pan_vbox = gtk_vbox_new(false,0); 225 | 226 | gtk_box_pack_start(GTK_BOX(gain_vbox),gain_slider,slide_expand,slide_expand,0); 227 | gtk_box_pack_start(GTK_BOX(gain_vbox),gain_label,false,false,0); 228 | 229 | gtk_box_pack_start(GTK_BOX(pan_vbox),pan_slider,slide_expand,slide_expand,0); 230 | gtk_box_pack_start(GTK_BOX(pan_vbox),pan_label,false,false,0); 231 | 232 | gtk_box_pack_start(GTK_BOX(hbox),gain_vbox,true,true,0); 233 | gtk_box_pack_start(GTK_BOX(hbox),pan_vbox,true,true,0); 234 | 235 | gtk_box_pack_start(GTK_BOX(vbox),hbox,true,true,0); 236 | 237 | button_box = gtk_hbox_new(false,2); 238 | 239 | led_event_box = gtk_event_box_new(); 240 | g_object_set_qdata(G_OBJECT(led_event_box),ui->trigger_quark,GINT_TO_POINTER(si)); 241 | g_signal_connect(G_OBJECT(led_event_box),"button-release-event", 242 | G_CALLBACK(trigger_led_clicked),ui); 243 | led = gtk_image_new_from_pixbuf(led_off_pixbuf); 244 | if (notify_leds) notify_leds[si] = led; 245 | gtk_container_add(GTK_CONTAINER(led_event_box),led); 246 | 247 | gtk_box_pack_start(GTK_BOX(button_box),led_event_box,false,false,0); 248 | gtk_box_pack_start(GTK_BOX(button_box),gtk_label_new(""),true,true,0); 249 | 250 | 251 | gtk_box_pack_start(GTK_BOX(hbox),button_box,false,false,0); 252 | g_object_set(vbox,"border-width",5,NULL); 253 | gtk_container_add(GTK_CONTAINER(frame),vbox); 254 | 255 | gtk_table_attach_defaults(ui->sample_table,frame,col,col+1,row,row+1); 256 | 257 | if (ui->startSamp > 1) { 258 | col--; 259 | if (col < 0) { 260 | if (ui->startSamp == 2) 261 | row++; 262 | else 263 | row--; 264 | col = ui->cols-1; 265 | } 266 | } 267 | else { 268 | col++; 269 | if (col >= ui->cols) { 270 | if (ui->startSamp == 0) 271 | row++; 272 | else 273 | row--; 274 | col = 0; 275 | } 276 | } 277 | } 278 | gtk_widget_queue_resize(GTK_WIDGET(ui->sample_table)); 279 | } 280 | 281 | static gboolean unset_bg(gpointer data) { 282 | if (GTK_IS_IMAGE(data)) 283 | gtk_image_set_from_pixbuf(GTK_IMAGE(data),led_off_pixbuf); 284 | return FALSE; 285 | } 286 | 287 | static void sample_triggered(DrMrUi *ui, int si) { 288 | if (ui->notify_leds && si < ui->samples) { 289 | gtk_image_set_from_pixbuf(GTK_IMAGE(ui->notify_leds[si]),led_on_pixbuf); 290 | g_timeout_add(200,unset_bg,ui->notify_leds[si]); 291 | } 292 | } 293 | 294 | static const char* nstrs = "C C#D D#E F F#G G#A A#B "; 295 | static char baseLabelBuf[32]; 296 | static void setBaseLabel(int noteIdx) { 297 | int oct = (noteIdx/12)-1; 298 | int nmt = (noteIdx%12)*2; 299 | snprintf(baseLabelBuf,32,"Midi Base Note (%c%c%i):", 300 | nstrs[nmt],nstrs[nmt+1],oct); 301 | } 302 | 303 | static void base_changed(GtkSpinButton *base_spin, gpointer data) { 304 | DrMrUi* ui = (DrMrUi*)data; 305 | float base = (float)gtk_spin_button_get_value(base_spin); 306 | 307 | if (base >= 21.0f && base <= 107.0f) { 308 | setBaseLabel((int)base); 309 | ui->write(ui->controller,DRMR_BASENOTE,4,0,&base); 310 | gtk_label_set_markup(ui->base_label,baseLabelBuf); 311 | ui->baseNote = (int)base; 312 | } 313 | else 314 | fprintf(stderr,"Base spin got out of range: %f\n",base); 315 | } 316 | 317 | static void fill_kit_combo(GtkComboBox* combo, kits* kits) { 318 | int i; 319 | GtkTreeIter iter; 320 | GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(combo)); 321 | for (i=0;inum_kits;i++) { 322 | gtk_list_store_append (store, &iter); 323 | gtk_list_store_set(store, &iter, 0, kits->kits[i].name, -1); 324 | } 325 | } 326 | 327 | static gboolean idle = FALSE; 328 | static gboolean kit_callback(gpointer data) { 329 | DrMrUi* ui = (DrMrUi*)data; 330 | if (ui->forceUpdate || (ui->kitReq != ui->curKit)) { 331 | ui->forceUpdate = false; 332 | int samples = (ui->kitReqkits->num_kits && ui->kitReq >= 0)? 333 | ui->kits->kits[ui->kitReq].samples: 334 | 0; 335 | GtkWidget** notify_leds; 336 | GtkWidget** gain_sliders; 337 | GtkWidget** pan_sliders; 338 | if (ui->sample_table) { 339 | notify_leds = ui->notify_leds; 340 | gain_sliders = ui->gain_sliders; 341 | pan_sliders = ui->pan_sliders; 342 | ui->samples = 0; 343 | ui->notify_leds = NULL; 344 | ui->gain_sliders = NULL; 345 | ui->pan_sliders = NULL; 346 | if (notify_leds) free(notify_leds); 347 | if (gain_sliders) free(gain_sliders); 348 | if (pan_sliders) free(pan_sliders); 349 | gtk_widget_destroy(GTK_WIDGET(ui->sample_table)); 350 | ui->sample_table = NULL; 351 | } 352 | if (samples > 0) { 353 | ui->sample_table = GTK_TABLE(gtk_table_new(1,1,true)); 354 | gtk_table_set_col_spacings(ui->sample_table,5); 355 | gtk_table_set_row_spacings(ui->sample_table,5); 356 | 357 | notify_leds = malloc(samples*sizeof(GtkWidget*)); 358 | gain_sliders = malloc(samples*sizeof(GtkWidget*)); 359 | pan_sliders = malloc(samples*sizeof(GtkWidget*)); 360 | fill_sample_table(ui,samples,ui->kits->kits[ui->kitReq].sample_names,notify_leds,gain_sliders,pan_sliders); 361 | gtk_box_pack_start(GTK_BOX(ui->drmr_widget),GTK_WIDGET(ui->sample_table), 362 | true,true,5); 363 | gtk_box_reorder_child(GTK_BOX(ui->drmr_widget),GTK_WIDGET(ui->sample_table),1); 364 | gtk_widget_show_all(GTK_WIDGET(ui->sample_table)); 365 | ui->samples = samples; 366 | ui->notify_leds = notify_leds; 367 | ui->gain_sliders = gain_sliders; 368 | ui->pan_sliders = pan_sliders; 369 | 370 | gtk_label_set_text(ui->current_kit_label,ui->kits->kits[ui->kitReq].name); 371 | 372 | ui->curKit = ui->kitReq; 373 | gtk_combo_box_set_active(ui->kit_combo,ui->curKit); 374 | gtk_widget_show(GTK_WIDGET(ui->kit_combo)); 375 | gtk_widget_hide(ui->no_kit_label); 376 | } else { 377 | gtk_widget_show(ui->no_kit_label); 378 | gtk_label_set_text(ui->current_kit_label,NO_KIT_STRING); 379 | gtk_widget_hide(GTK_WIDGET(ui->kit_combo)); 380 | } 381 | } 382 | idle = FALSE; 383 | return FALSE; // don't keep calling 384 | } 385 | 386 | static LV2_Atom* build_path_message(DrMrUi *ui, const char* path) { 387 | LV2_Atom_Forge_Frame set_frame; 388 | LV2_Atom* msg = (LV2_Atom*)lv2_atom_forge_resource 389 | (&ui->forge, &set_frame, 1, ui->uris.ui_msg); 390 | lv2_atom_forge_property_head(&ui->forge, ui->uris.kit_path,0); 391 | lv2_atom_forge_path(&ui->forge, path, strlen(path)); 392 | lv2_atom_forge_pop(&ui->forge,&set_frame); 393 | return msg; 394 | } 395 | 396 | static LV2_Atom* build_get_state_message(DrMrUi *ui) { 397 | LV2_Atom_Forge_Frame set_frame; 398 | LV2_Atom* msg = (LV2_Atom*)lv2_atom_forge_resource 399 | (&ui->forge, &set_frame, 1, ui->uris.get_state); 400 | lv2_atom_forge_pop(&ui->forge,&set_frame); 401 | return msg; 402 | } 403 | 404 | static void kit_combobox_changed(GtkComboBox* box, gpointer data) { 405 | DrMrUi* ui = (DrMrUi*)data; 406 | gint new_kit = gtk_combo_box_get_active (GTK_COMBO_BOX(box)); 407 | 408 | if (ui->curKit != new_kit) { 409 | uint8_t msg_buf[1024]; 410 | lv2_atom_forge_set_buffer(&ui->forge, msg_buf, 1024); 411 | LV2_Atom *msg = build_path_message(ui,ui->kits->kits[new_kit].path); 412 | 413 | ui->write(ui->controller,DRMR_CONTROL, 414 | lv2_atom_total_size(msg), 415 | ui->uris.atom_eventTransfer, 416 | msg); 417 | } 418 | } 419 | 420 | static void position_data(DrMrUi *ui, gpointer data) { 421 | lv2_atom_forge_property_head(&ui->forge, ui->uris.zero_position,0); 422 | lv2_atom_forge_int(&ui->forge, GPOINTER_TO_INT(data)); 423 | } 424 | static void position_combobox_changed(GtkComboBox* box, gpointer data) { 425 | DrMrUi* ui = (DrMrUi*)data; 426 | gint ss = gtk_combo_box_get_active (GTK_COMBO_BOX(box)); 427 | if (ss != ui->startSamp) { 428 | ui->startSamp = ss; 429 | ui->forceUpdate = true; 430 | kit_callback(ui); 431 | send_ui_msg(ui,&position_data,GINT_TO_POINTER(ss)); 432 | } 433 | } 434 | 435 | static GtkWidget *create_position_combo(void) 436 | { 437 | GtkWidget *combo; 438 | GtkListStore *list_store; 439 | GtkCellRenderer *cell; 440 | GtkTreeIter iter; 441 | 442 | list_store = gtk_list_store_new(1, G_TYPE_STRING); 443 | 444 | gtk_list_store_append(list_store, &iter); 445 | gtk_list_store_set (list_store, &iter, 0, "Top Left", -1); 446 | gtk_list_store_append(list_store, &iter); 447 | gtk_list_store_set (list_store, &iter, 0, "Bottom Left", -1); 448 | gtk_list_store_append(list_store, &iter); 449 | gtk_list_store_set (list_store, &iter, 0, "Top Right", -1); 450 | gtk_list_store_append(list_store, &iter); 451 | gtk_list_store_set (list_store, &iter, 0, "Bottom Right", -1); 452 | 453 | combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(list_store)); 454 | 455 | #ifdef DRMR_UI_ZERO_SAMP 456 | gtk_combo_box_set_active(GTK_COMBO_BOX(combo),DRMR_UI_ZERO_SAMP); 457 | #else 458 | gtk_combo_box_set_active(GTK_COMBO_BOX(combo),0); 459 | #endif 460 | 461 | 462 | g_object_unref(list_store); 463 | 464 | cell = gtk_cell_renderer_text_new(); 465 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE); 466 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", 0, NULL); 467 | 468 | return combo; 469 | } 470 | 471 | static gulong expose_id; 472 | static gboolean expose_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) { 473 | DrMrUi* ui = (DrMrUi*)data; 474 | uint8_t msg_buf[1024]; 475 | lv2_atom_forge_set_buffer(&ui->forge, msg_buf, 1024); 476 | LV2_Atom *msg = build_get_state_message(ui); 477 | ui->write(ui->controller,DRMR_CONTROL, 478 | lv2_atom_total_size(msg), 479 | ui->uris.atom_eventTransfer, 480 | msg); 481 | g_signal_handler_disconnect(widget,expose_id); 482 | return FALSE; 483 | } 484 | 485 | static void load_led_pixbufs(DrMrUi* ui) { 486 | GError *error = NULL; 487 | gchar *pixbuf_path; 488 | 489 | pixbuf_path = g_build_path(G_DIR_SEPARATOR_S,ui->bundle_path,"led_on.png",NULL); 490 | if (pixbuf_path) { 491 | led_on_pixbuf = gdk_pixbuf_new_from_file(pixbuf_path,&error); 492 | if (!led_on_pixbuf) 493 | fprintf(stderr,"Could not load led_on pixbuf: %s\n",error->message); 494 | g_free(pixbuf_path); 495 | } else 496 | fprintf(stderr,"Could not build path to load led_on pixbuf"); 497 | 498 | 499 | pixbuf_path = g_build_path(G_DIR_SEPARATOR_S,ui->bundle_path,"led_off.png",NULL); 500 | if (pixbuf_path) { 501 | led_off_pixbuf = gdk_pixbuf_new_from_file(pixbuf_path,&error); 502 | if (!led_off_pixbuf) 503 | fprintf(stderr,"Could not load led_off pixbuf: %s\n",error->message); 504 | g_free(pixbuf_path); 505 | } else 506 | fprintf(stderr,"Could not build path to load led_off pixbuf"); 507 | } 508 | 509 | static void build_drmr_ui(DrMrUi* ui) { 510 | GtkWidget *drmr_ui_widget; 511 | GtkWidget *opts_hbox1, *opts_hbox2, 512 | *kit_combo_box, *kit_label, *no_kit_label, 513 | *base_label, *base_spin, *position_label; 514 | GtkCellRenderer *cell_rend; 515 | GtkAdjustment *base_adj; 516 | 517 | PangoAttrList *attr_lst; 518 | PangoAttribute *attr; 519 | 520 | drmr_ui_widget = gtk_vbox_new(false,0); 521 | expose_id = g_signal_connect (drmr_ui_widget, "expose-event", G_CALLBACK (expose_callback), ui); 522 | g_object_set(drmr_ui_widget,"border-width",6,NULL); 523 | 524 | ui->kit_store = gtk_list_store_new(1,G_TYPE_STRING); 525 | 526 | ui->current_kit_label = GTK_LABEL(gtk_label_new(NO_KIT_STRING)); 527 | attr = pango_attr_weight_new(PANGO_WEIGHT_HEAVY); 528 | attr_lst = pango_attr_list_new(); 529 | pango_attr_list_insert(attr_lst, attr); 530 | gtk_label_set_attributes(ui->current_kit_label, attr_lst); 531 | pango_attr_list_unref(attr_lst); 532 | 533 | opts_hbox1 = gtk_hbox_new(false,0); 534 | opts_hbox2 = gtk_hbox_new(false,0); 535 | kit_combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ui->kit_store)); 536 | kit_label = gtk_label_new("Kit:"); 537 | 538 | no_kit_label = gtk_label_new("No/Invalid Kit Selected"); 539 | gtk_label_set_use_markup(GTK_LABEL(no_kit_label),true); 540 | 541 | cell_rend = gtk_cell_renderer_text_new(); 542 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(kit_combo_box), cell_rend, true); 543 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(kit_combo_box), cell_rend,"text",0,NULL); 544 | 545 | base_label = gtk_label_new("Midi Base Note (C 2):"); 546 | gtk_label_set_use_markup(GTK_LABEL(base_label),true); 547 | base_adj = GTK_ADJUSTMENT 548 | (gtk_adjustment_new(36.0, // val 549 | 21.0,107.0, // min/max 550 | 1.0, // step 551 | 5.0,0.0)); // page adj/size 552 | base_spin = gtk_spin_button_new(base_adj, 1.0, 0); 553 | 554 | position_label = gtk_label_new("Sample Zero Position: "); 555 | ui->position_combo_box = create_position_combo(); 556 | 557 | ui->velocity_checkbox = gtk_check_button_new_with_label("Ignore Velocity"); 558 | ui->note_off_checkbox = gtk_check_button_new_with_label("Ignore Note Off"); 559 | 560 | gtk_box_pack_start(GTK_BOX(opts_hbox1),kit_label, 561 | false,false,15); 562 | gtk_box_pack_start(GTK_BOX(opts_hbox1),no_kit_label, 563 | true,true,0); 564 | gtk_box_pack_start(GTK_BOX(opts_hbox1),kit_combo_box, 565 | true,true,0); 566 | gtk_box_pack_start(GTK_BOX(opts_hbox1),base_label, 567 | false,false,15); 568 | gtk_box_pack_start(GTK_BOX(opts_hbox1),base_spin, 569 | true,true,0); 570 | 571 | gtk_box_pack_start(GTK_BOX(opts_hbox2),position_label, 572 | false,false,15); 573 | gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->position_combo_box, 574 | false,false,0); 575 | gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->velocity_checkbox, 576 | true,true,15); 577 | gtk_box_pack_start(GTK_BOX(opts_hbox2),ui->note_off_checkbox, 578 | true,true,15); 579 | 580 | gtk_box_pack_start(GTK_BOX(drmr_ui_widget),GTK_WIDGET(ui->current_kit_label), 581 | false,false,5); 582 | gtk_box_pack_start(GTK_BOX(drmr_ui_widget),gtk_hseparator_new(), 583 | false,false,5); 584 | gtk_box_pack_start(GTK_BOX(drmr_ui_widget),opts_hbox1, 585 | false,false,5); 586 | gtk_box_pack_start(GTK_BOX(drmr_ui_widget),opts_hbox2, 587 | false,false,5); 588 | 589 | 590 | 591 | ui->drmr_widget = drmr_ui_widget; 592 | ui->sample_table = NULL; 593 | ui->kit_combo = GTK_COMBO_BOX(kit_combo_box); 594 | ui->base_label = GTK_LABEL(base_label); 595 | ui->base_spin = GTK_SPIN_BUTTON(base_spin); 596 | ui->no_kit_label = no_kit_label; 597 | 598 | g_signal_connect(G_OBJECT(kit_combo_box),"changed",G_CALLBACK(kit_combobox_changed),ui); 599 | g_signal_connect(G_OBJECT(base_spin),"value-changed",G_CALLBACK(base_changed),ui); 600 | g_signal_connect(G_OBJECT(ui->position_combo_box),"changed",G_CALLBACK(position_combobox_changed),ui); 601 | g_signal_connect(G_OBJECT(ui->velocity_checkbox),"toggled",G_CALLBACK(ignore_velocity_toggled),ui); 602 | g_signal_connect(G_OBJECT(ui->note_off_checkbox),"toggled",G_CALLBACK(ignore_note_off_toggled),ui); 603 | 604 | gtk_widget_show_all(drmr_ui_widget); 605 | gtk_widget_hide(no_kit_label); 606 | } 607 | 608 | static LV2UI_Handle 609 | instantiate(const LV2UI_Descriptor* descriptor, 610 | const char* plugin_uri, 611 | const char* bundle_path, 612 | LV2UI_Write_Function write_function, 613 | LV2UI_Controller controller, 614 | LV2UI_Widget* widget, 615 | const LV2_Feature* const* features) { 616 | DrMrUi *ui = (DrMrUi*)malloc(sizeof(DrMrUi)); 617 | 618 | ui->write = write_function; 619 | ui->controller = controller; 620 | ui->drmr_widget = NULL; 621 | ui->map = NULL; 622 | ui->curKit = -1; 623 | ui->samples = 0; 624 | *widget = NULL; 625 | 626 | while(*features) { 627 | if (!strcmp((*features)->URI, LV2_URID_URI "#map")) 628 | ui->map = (LV2_URID_Map *)((*features)->data); 629 | features++; 630 | } 631 | if (!ui->map) { 632 | fprintf(stderr, "LV2 host does not support urid#map.\n"); 633 | free(ui); 634 | return 0; 635 | } 636 | map_drmr_uris(ui->map,&(ui->uris)); 637 | 638 | ui->bundle_path = g_strdup(bundle_path); 639 | 640 | load_led_pixbufs(ui); 641 | 642 | 643 | lv2_atom_forge_init(&ui->forge,ui->map); 644 | 645 | build_drmr_ui(ui); 646 | 647 | ui->kits = scan_kits(); 648 | ui->gain_quark = g_quark_from_string("drmr_gain_quark"); 649 | ui->pan_quark = g_quark_from_string("drmr_pan_quark"); 650 | ui->trigger_quark = g_quark_from_string("drmr_trigger_quark"); 651 | ui->gain_sliders = NULL; 652 | ui->pan_sliders = NULL; 653 | ui->notify_leds = NULL; 654 | 655 | // store previous gain/pan vals to re-apply to sliders when we 656 | // change kits 657 | ui->gain_vals = malloc(32*sizeof(float)); 658 | memset(ui->gain_vals,0,32*sizeof(float)); 659 | ui->pan_vals = malloc(32*sizeof(float)); 660 | memset(ui->pan_vals,0,32*sizeof(float)); 661 | ui->cols = 4; 662 | ui->forceUpdate = false; 663 | fill_kit_combo(ui->kit_combo, ui->kits); 664 | 665 | #ifdef DRMR_UI_ZERO_SAMP 666 | ui->startSamp = DRMR_UI_ZERO_SAMP; 667 | #else 668 | ui->startSamp = 0; 669 | #endif 670 | 671 | *widget = ui->drmr_widget; 672 | 673 | return ui; 674 | } 675 | 676 | 677 | static void cleanup(LV2UI_Handle handle) { 678 | DrMrUi* ui = (DrMrUi*)handle; 679 | // seems qtractor likes to destory us 680 | // before calling, avoid double-destroy 681 | if (GTK_IS_WIDGET(ui->drmr_widget)) 682 | gtk_widget_destroy(ui->drmr_widget); 683 | if (ui->notify_leds) free(ui->notify_leds); 684 | if (ui->gain_sliders) free(ui->gain_sliders); 685 | if (ui->pan_sliders) free(ui->pan_sliders); 686 | g_free(ui->bundle_path); 687 | if (led_on_pixbuf) g_object_unref(led_on_pixbuf); 688 | if (led_off_pixbuf) g_object_unref(led_off_pixbuf); 689 | free_kits(ui->kits); 690 | free(ui); 691 | } 692 | 693 | struct slider_callback_data { 694 | GtkRange* range; 695 | float val; 696 | }; 697 | static gboolean slider_callback(gpointer data) { 698 | struct slider_callback_data *cbd = (struct slider_callback_data*)data; 699 | if (GTK_IS_RANGE(cbd->range)) 700 | gtk_range_set_value(cbd->range,cbd->val); 701 | free(cbd); 702 | return FALSE; // don't keep calling 703 | } 704 | 705 | static void 706 | port_event(LV2UI_Handle handle, 707 | uint32_t port_index, 708 | uint32_t buffer_size, 709 | uint32_t format, 710 | const void* buffer) { 711 | DrMrPortIndex index = (DrMrPortIndex)port_index; 712 | DrMrUi* ui = (DrMrUi*)handle; 713 | 714 | if (index == DRMR_CORE_EVENT) { 715 | if (format == ui->uris.atom_eventTransfer) { 716 | LV2_Atom* atom = (LV2_Atom*)buffer; 717 | if (atom->type == ui->uris.atom_resource) { 718 | LV2_Atom_Object* obj = (LV2_Atom_Object*)atom; 719 | if (obj->body.otype == ui->uris.get_state || 720 | obj->body.otype == ui->uris.ui_msg) { 721 | // both state and ui_msg are the same at the moment 722 | const LV2_Atom* path = NULL; 723 | lv2_atom_object_get(obj, ui->uris.kit_path, &path, 0); 724 | if (path) { 725 | char *kitpath = LV2_ATOM_BODY(path); 726 | if (!strncmp(kitpath, "file://", 7)) 727 | kitpath += 7; 728 | char *realp = realpath(kitpath,NULL); 729 | if (!realp) { 730 | fprintf(stderr,"Passed a path I can't resolve, bailing out\n"); 731 | return; 732 | } 733 | int i; 734 | for(i = 0;i < ui->kits->num_kits;i++) 735 | if (!strcmp(ui->kits->kits[i].path,realp)) 736 | break; 737 | if (i < ui->kits->num_kits) { 738 | ui->kitReq = i; 739 | g_idle_add(kit_callback,ui); 740 | } else 741 | fprintf(stderr,"Couldn't find kit %s\n",realp); 742 | free(realp); 743 | } 744 | if (obj->body.otype == ui->uris.get_state) { // read out extra state info 745 | const LV2_Atom* ignvel = NULL; 746 | const LV2_Atom* ignno = NULL; 747 | const LV2_Atom* zerop = NULL; 748 | lv2_atom_object_get(obj, 749 | ui->uris.velocity_toggle, &ignvel, 750 | ui->uris.note_off_toggle, &ignno, 751 | ui->uris.zero_position, &zerop, 752 | 0); 753 | if (ignvel) 754 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->velocity_checkbox), 755 | ((const LV2_Atom_Bool*)ignvel)->body); 756 | if (ignno) 757 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->note_off_checkbox), 758 | ((const LV2_Atom_Bool*)ignno)->body); 759 | if (zerop) 760 | gtk_combo_box_set_active(GTK_COMBO_BOX(ui->position_combo_box), 761 | ((const LV2_Atom_Int*)zerop)->body); 762 | } 763 | } 764 | else if (obj->body.otype == ui->uris.midi_info) { 765 | const LV2_Atom *midi_atom = NULL; 766 | lv2_atom_object_get(obj, ui->uris.midi_event, &midi_atom, 0); 767 | if(!midi_atom) { 768 | fprintf(stderr,"Midi info with no midi data\n"); 769 | return; 770 | } 771 | const uint8_t *data = (const uint8_t*)midi_atom; 772 | uint8_t nn = data[1] - ui->baseNote; 773 | sample_triggered(ui,nn); 774 | } 775 | else 776 | fprintf(stderr, "Unknown resource type passed to ui.\n"); 777 | } else 778 | fprintf(stderr, "Non resource message passed to ui.\n"); 779 | } else 780 | fprintf(stderr, "Unknown format.\n"); 781 | } 782 | else if (index == DRMR_BASENOTE) { 783 | int base = (int)(*((float*)buffer)); 784 | if (base >= 21 && base <= 107) { 785 | setBaseLabel((int)base); 786 | gtk_spin_button_set_value(ui->base_spin,base); 787 | gtk_label_set_markup(ui->base_label,baseLabelBuf); 788 | ui->baseNote = base; 789 | } 790 | } 791 | else if (index >= DRMR_GAIN_ONE && 792 | index <= DRMR_GAIN_THIRTYTWO) { 793 | float gain = *(float*)buffer; 794 | int idx = index-DRMR_GAIN_ONE; 795 | ui->gain_vals[idx] = gain; 796 | if (idx < ui->samples && ui->gain_sliders) { 797 | struct slider_callback_data* data = malloc(sizeof(struct slider_callback_data)); 798 | data->range = GTK_RANGE(ui->gain_sliders[idx]); 799 | data->val = gain; 800 | g_idle_add(slider_callback,data); 801 | //GtkRange* range = GTK_RANGE(ui->gain_sliders[idx]); 802 | //gtk_range_set_value(range,gain); 803 | } 804 | } 805 | else if (index >= DRMR_PAN_ONE && 806 | index <= DRMR_PAN_THIRTYTWO) { 807 | float pan = *(float*)buffer; 808 | int idx = index-DRMR_PAN_ONE; 809 | ui->pan_vals[idx] = pan; 810 | if (idx < ui->samples && ui->pan_sliders) { 811 | struct slider_callback_data* data = malloc(sizeof(struct slider_callback_data)); 812 | data->range = GTK_RANGE(ui->pan_sliders[idx]); 813 | data->val = pan; 814 | g_idle_add(slider_callback,data); 815 | } 816 | } 817 | } 818 | 819 | static const void* 820 | extension_data(const char* uri) { 821 | return NULL; 822 | } 823 | 824 | static const LV2UI_Descriptor descriptor = { 825 | DRMR_UI_URI, 826 | instantiate, 827 | cleanup, 828 | port_event, 829 | extension_data 830 | }; 831 | 832 | LV2_SYMBOL_EXPORT 833 | const LV2UI_Descriptor* 834 | lv2ui_descriptor(uint32_t index) { 835 | switch (index) { 836 | case 0: 837 | return &descriptor; 838 | default: 839 | return NULL; 840 | } 841 | } 842 | 843 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------