pax_global_header00006660000000000000000000000064137632536050014524gustar00rootroot0000000000000052 comment=affb069cec94743fceedd2dff1fe432387210e41 ocaml-dssi-0.1.3/000077500000000000000000000000001376325360500135605ustar00rootroot00000000000000ocaml-dssi-0.1.3/.github/000077500000000000000000000000001376325360500151205ustar00rootroot00000000000000ocaml-dssi-0.1.3/.github/workflows/000077500000000000000000000000001376325360500171555ustar00rootroot00000000000000ocaml-dssi-0.1.3/.github/workflows/main.yml000066400000000000000000000006601376325360500206260ustar00rootroot00000000000000name: Build on: [push] jobs: build: runs-on: ${{ matrix.operating-system }} strategy: matrix: operating-system: [ubuntu-latest, macos-latest] ocaml-version: ['4.09.0'] steps: - uses: actions/checkout@v1 - uses: avsm/setup-ocaml@master with: ocaml-version: ${{ matrix.ocaml-version }} - run: opam pin add -n . - run: opam depext -yt dssi - run: opam install -t . ocaml-dssi-0.1.3/.gitignore000066400000000000000000000000631376325360500155470ustar00rootroot00000000000000*~ _build *.byte *.native _tests .merlin *.install ocaml-dssi-0.1.3/.gitmodules000066400000000000000000000001031376325360500157270ustar00rootroot00000000000000[submodule "m4"] path = m4 url = git://github.com/savonet/m4.git ocaml-dssi-0.1.3/.travis.yml000066400000000000000000000005621376325360500156740ustar00rootroot00000000000000language: c sudo: true addons: apt: packages: - ocaml-nox - ocaml-findlib - dssi-dev before_install: - git clone https://github.com/savonet/ocaml-ladspa - cd ocaml-ladspa && git submodule init && git submodule update && ./bootstrap && ./configure && make && sudo make install script: - ./bootstrap - ./configure - make - make -C examples ocaml-dssi-0.1.3/CHANGES000066400000000000000000000004451376325360500145560ustar00rootroot000000000000000.1.3 (06-12-2020) ===== * Adapt to ocaml-ladspa 0.1.6. * Switch to dune! 0.1.2 (03-08-2015) ===== * Fixed CFLAGS when checking for ocaml_ladspa.h 0.1.1 (17-02-2013) ===== * Add mli. * Link with ladspa in META. * Fix configure test for ladspa.h. 0.1.0 (04-07-2011) ===== * Initial release. ocaml-dssi-0.1.3/COPYING000066400000000000000000000431311376325360500146150ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ocaml-dssi-0.1.3/dssi.opam000066400000000000000000000013671376325360500154070ustar00rootroot00000000000000# This file is generated by dune, edit dune-project instead opam-version: "2.0" version: "0.1.3" synopsis: "Bindings for the DSSI API which provides audio synthesizers" maintainer: ["The Savonet Team "] authors: ["The Savonet Team "] license: "LGPL-2.1" homepage: "https://github.com/savonet/ocaml-dssi" bug-reports: "https://github.com/savonet/ocaml-dssi/issues" depends: [ "dune" {>= "2.0"} "dune-configurator" "ladspa" {>= "0.2.0"} "conf-dssi" ] build: [ ["dune" "subst"] {pinned} [ "dune" "build" "-p" name "-j" jobs "@install" "@runtest" {with-test} "@doc" {with-doc} ] ] dev-repo: "git+https://github.com/savonet/ocaml-dssi.git" ocaml-dssi-0.1.3/dune-project000066400000000000000000000007001376325360500160770ustar00rootroot00000000000000(lang dune 2.0) (version 0.1.3) (name dssi) (source (github savonet/ocaml-dssi)) (license LGPL-2.1) (authors "The Savonet Team ") (maintainers "The Savonet Team ") (generate_opam_files true) (package (name dssi) (synopsis "Bindings for the DSSI API which provides audio synthesizers") (depends (dune (>= 2.0)) dune-configurator (ladspa (>= 0.2.0)) conf-dssi) ) ocaml-dssi-0.1.3/examples/000077500000000000000000000000001376325360500153765ustar00rootroot00000000000000ocaml-dssi-0.1.3/examples/dune000066400000000000000000000000541376325360500162530ustar00rootroot00000000000000(executable (name test) (libraries dssi)) ocaml-dssi-0.1.3/examples/test.ml000066400000000000000000000006751376325360500167170ustar00rootroot00000000000000let () = Dssi.init (); let p = Dssi.Plugin.load "/usr/lib/dssi/trivial_synth.so" in let d = Dssi.Descriptor.descriptor p 0 in Printf.printf "API version: %d\n%!" (Dssi.Descriptor.api_version d); let ladspa = Dssi.Descriptor.ladspa d in let inst = Ladspa.Descriptor.instantiate ladspa 44100 in let p_bank, p_program, p_name = Dssi.Descriptor.get_program d inst 0 in Printf.printf "Program %d,%d: %s\n%!" p_bank p_program p_name ocaml-dssi-0.1.3/src/000077500000000000000000000000001376325360500143475ustar00rootroot00000000000000ocaml-dssi-0.1.3/src/config/000077500000000000000000000000001376325360500156145ustar00rootroot00000000000000ocaml-dssi-0.1.3/src/config/discover.ml000066400000000000000000000010251376325360500177620ustar00rootroot00000000000000module C = Configurator.V1 let () = C.main ~name:"dssi-header" (fun c -> let has_dssi = try let defined = C.C_define.import c ~includes:["dssi.h"] [("DSSI_VERSION", C.C_define.Type.String)] in match defined with | [("DSSI_VERSION", C.C_define.Value.String _)] -> true | _ -> false with _ -> false in C.C_define.gen_header_file c ~fname:"ocaml_dssi_config.h" [("HAS_DSSI", C.C_define.Value.Switch has_dssi)]) ocaml-dssi-0.1.3/src/config/dune000066400000000000000000000000751376325360500164740ustar00rootroot00000000000000(executable (name discover) (libraries dune.configurator)) ocaml-dssi-0.1.3/src/dssi.h000066400000000000000000000433171376325360500154720ustar00rootroot00000000000000/* -*- c-basic-offset: 4 -*- */ /* dssi.h DSSI version 1.0 Copyright (c) 2004, 2009 Chris Cannam, Steve Harris and Sean Bolton This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef DSSI_INCLUDED #define DSSI_INCLUDED #include #if __APPLE__ #include #else #include #endif #define DSSI_VERSION "1.0" #define DSSI_VERSION_MAJOR 1 #define DSSI_VERSION_MINOR 0 #ifdef __cplusplus extern "C" { #endif /* There is a need for an API that supports hosted MIDI soft synths with GUIs in Linux audio applications. In time the GMPI initiative should comprehensively address this need, but the requirement for Linux applications to be able to support simple hosted synths is here now, and GMPI is not. This proposal (the "DSSI Soft Synth Interface" or DSSI, pronounced "dizzy") aims to provide a simple solution in a way that we hope will prove complete and compelling enough to support now, yet not so compelling as to supplant GMPI or any other comprehensive future proposal. For simplicity and familiarity, this API is based as far as possible on existing work -- the LADSPA plugin API for control values and audio processing, and the ALSA sequencer event types for MIDI event communication. The GUI part of the proposal is quite new, but may also be applicable retroactively to LADSPA plugins that do not otherwise support this synth interface. */ typedef struct _DSSI_Program_Descriptor { /** Bank number for this program. Note that DSSI does not support MIDI-style separation of bank LSB and MSB values. There is no restriction on the set of available banks: the numbers do not need to be contiguous, there does not need to be a bank 0, etc. */ unsigned long Bank; /** Program number (unique within its bank) for this program. There is no restriction on the set of available programs: the numbers do not need to be contiguous, there does not need to be a program 0, etc. */ unsigned long Program; /** Name of the program. */ const char *Name; } DSSI_Program_Descriptor; typedef struct _DSSI_Descriptor { /** * DSSI_API_Version * * This member indicates the DSSI API level used by this plugin. * If we're lucky, this will never be needed. For now all plugins * must set it to 1. */ int DSSI_API_Version; /** * LADSPA_Plugin * * A DSSI synth plugin consists of a LADSPA plugin plus an * additional framework for controlling program settings and * transmitting MIDI events. A plugin must fully implement the * LADSPA descriptor fields as well as the required LADSPA * functions including instantiate() and (de)activate(). It * should also implement run(), with the same behaviour as if * run_synth() (below) were called with no synth events. * * In order to instantiate a synth the host calls the LADSPA * instantiate function, passing in this LADSPA_Descriptor * pointer. The returned LADSPA_Handle is used as the argument * for the DSSI functions below as well as for the LADSPA ones. */ const LADSPA_Descriptor *LADSPA_Plugin; /** * configure() * * This member is a function pointer that sends a piece of * configuration data to the plugin. The key argument specifies * some aspect of the synth's configuration that is to be changed, * and the value argument specifies a new value for it. A plugin * that does not require this facility at all may set this member * to NULL. * * This call is intended to set some session-scoped aspect of a * plugin's behaviour, for example to tell the plugin to load * sample data from a particular file. The plugin should act * immediately on the request. The call should return NULL on * success, or an error string that may be shown to the user. The * host will free the returned value after use if it is non-NULL. * * Calls to configure() are not automated as timed events. * Instead, a host should remember the last value associated with * each key passed to configure() during a given session for a * given plugin instance, and should call configure() with the * correct value for each key the next time it instantiates the * "same" plugin instance, for example on reloading a project in * which the plugin was used before. Plugins should note that a * host may typically instantiate a plugin multiple times with the * same configuration values, and should share data between * instances where practical. * * Calling configure() completely invalidates the program and bank * information last obtained from the plugin. * * Reserved and special key prefixes * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * The DSSI: prefix * ---------------- * Configure keys starting with DSSI: are reserved for particular * purposes documented in the DSSI specification. At the moment, * there is one such key: DSSI:PROJECT_DIRECTORY. A host may call * configure() passing this key and a directory path value. This * indicates to the plugin and its UI that a directory at that * path exists and may be used for project-local data. Plugins * may wish to use the project directory as a fallback location * when looking for other file data, or as a base for relative * paths in other configuration values. * * The GLOBAL: prefix * ------------------ * Configure keys starting with GLOBAL: may be used by the plugin * and its UI for any purpose, but are treated specially by the * host. When one of these keys is used in a configure OSC call * from the plugin UI, the host makes the corresponding configure * call (preserving the GLOBAL: prefix) not only to the target * plugin but also to all other plugins in the same instance * group, as well as their UIs. Note that if any instance * returns non-NULL from configure to indicate error, the host * may stop there (and the set of plugins on which configure has * been called will thus depend on the host implementation). * See also the configure OSC call documentation in RFC.txt. */ char *(*configure)(LADSPA_Handle Instance, const char *Key, const char *Value); #define DSSI_RESERVED_CONFIGURE_PREFIX "DSSI:" #define DSSI_GLOBAL_CONFIGURE_PREFIX "GLOBAL:" #define DSSI_PROJECT_DIRECTORY_KEY \ DSSI_RESERVED_CONFIGURE_PREFIX "PROJECT_DIRECTORY" /** * get_program() * * This member is a function pointer that provides a description * of a program (named preset sound) available on this synth. A * plugin that does not support programs at all should set this * member to NULL. * * The Index argument is an index into the plugin's list of * programs, not a program number as represented by the Program * field of the DSSI_Program_Descriptor. (This distinction is * needed to support synths that use non-contiguous program or * bank numbers.) * * This function returns a DSSI_Program_Descriptor pointer that is * guaranteed to be valid only until the next call to get_program, * deactivate, or configure, on the same plugin instance. This * function must return NULL if passed an Index argument out of * range, so that the host can use it to query the number of * programs as well as their properties. */ const DSSI_Program_Descriptor *(*get_program)(LADSPA_Handle Instance, unsigned long Index); /** * select_program() * * This member is a function pointer that selects a new program * for this synth. The program change should take effect * immediately at the start of the next run_synth() call. (This * means that a host providing the capability of changing programs * between any two notes on a track must vary the block size so as * to place the program change at the right place. A host that * wanted to avoid this would probably just instantiate a plugin * for each program.) * * A plugin that does not support programs at all should set this * member NULL. Plugins should ignore a select_program() call * with an invalid bank or program. * * A plugin is not required to select any particular default * program on activate(): it's the host's duty to set a program * explicitly. The current program is invalidated by any call to * configure(). * * A plugin is permitted to re-write the values of its input * control ports when select_program is called. The host should * re-read the input control port values and update its own * records appropriately. (This is the only circumstance in * which a DSSI plugin is allowed to modify its own input ports.) */ void (*select_program)(LADSPA_Handle Instance, unsigned long Bank, unsigned long Program); /** * get_midi_controller_for_port() * * This member is a function pointer that returns the MIDI * controller number or NRPN that should be mapped to the given * input control port. If the given port should not have any MIDI * controller mapped to it, the function should return DSSI_NONE. * The behaviour of this function is undefined if the given port * number does not correspond to an input control port. A plugin * that does not want MIDI controllers mapped to ports at all may * set this member NULL. * * Correct values can be got using the macros DSSI_CC(num) and * DSSI_NRPN(num) as appropriate, and values can be combined using * bitwise OR: e.g. DSSI_CC(23) | DSSI_NRPN(1069) means the port * should respond to CC #23 and NRPN #1069. * * The host is responsible for doing proper scaling from MIDI * controller and NRPN value ranges to port ranges according to * the plugin's LADSPA port hints. Hosts should not deliver * through run_synth any MIDI controller events that have already * been mapped to control port values. * * A plugin should not attempt to request mappings from * controllers 0 or 32 (MIDI Bank Select MSB and LSB). */ int (*get_midi_controller_for_port)(LADSPA_Handle Instance, unsigned long Port); /** * run_synth() * * This member is a function pointer that runs a synth for a * block. This is identical in function to the LADSPA run() * function, except that it also supplies events to the synth. * * A plugin may provide this function, run_multiple_synths() (see * below), both, or neither (if it is not in fact a synth). A * plugin that does not provide this function must set this member * to NULL. Authors of synth plugins are encouraged to provide * this function if at all possible. * * The Events pointer points to a block of EventCount ALSA * sequencer events, which is used to communicate MIDI and related * events to the synth. Each event is timestamped relative to the * start of the block, (mis)using the ALSA "tick time" field as a * frame count. The host is responsible for ensuring that events * with differing timestamps are already ordered by time. * * See also the notes on activation, port connection etc in * ladpsa.h, in the context of the LADSPA run() function. * * Note Events * ~~~~~~~~~~~ * There are two minor requirements aimed at making the plugin * writer's life as simple as possible: * * 1. A host must never send events of type SND_SEQ_EVENT_NOTE. * Notes should always be sent as separate SND_SEQ_EVENT_NOTE_ON * and NOTE_OFF events. A plugin should discard any one-point * NOTE events it sees. * * 2. A host must not attempt to switch notes off by sending * zero-velocity NOTE_ON events. It should always send true * NOTE_OFFs. It is the host's responsibility to remap events in * cases where an external MIDI source has sent it zero-velocity * NOTE_ONs. * * Bank and Program Events * ~~~~~~~~~~~~~~~~~~~~~~~ * Hosts must map MIDI Bank Select MSB and LSB (0 and 32) * controllers and MIDI Program Change events onto the banks and * programs specified by the plugin, using the DSSI select_program * call. No host should ever deliver a program change or bank * select controller to a plugin via run_synth. */ void (*run_synth)(LADSPA_Handle Instance, unsigned long SampleCount, snd_seq_event_t *Events, unsigned long EventCount); /** * run_synth_adding() * * This member is a function pointer that runs an instance of a * synth for a block, adding its outputs to the values already * present at the output ports. This is provided for symmetry * with LADSPA run_adding(), and is equally optional. A plugin * that does not provide it must set this member to NULL. */ void (*run_synth_adding)(LADSPA_Handle Instance, unsigned long SampleCount, snd_seq_event_t *Events, unsigned long EventCount); /** * run_multiple_synths() * * This member is a function pointer that runs multiple synth * instances for a block. This is very similar to run_synth(), * except that Instances, Events, and EventCounts each point to * arrays that hold the LADSPA handles, event buffers, and * event counts for each of InstanceCount instances. That is, * Instances points to an array of InstanceCount pointers to * DSSI plugin instantiations, Events points to an array of * pointers to each instantiation's respective event list, and * EventCounts points to an array containing each instantiation's * respective event count. * * A host using this function must guarantee that ALL active * instances of the plugin are represented in each call to the * function -- that is, a host may not call run_multiple_synths() * for some instances of a given plugin and then call run_synth() * as well for others. 'All .. instances of the plugin' means * every instance sharing the same LADSPA label and shared object * (*.so) file (rather than every instance sharing the same *.so). * 'Active' means any instance for which activate() has been called * but deactivate() has not. * * A plugin may provide this function, run_synths() (see above), * both, or neither (if it not in fact a synth). A plugin that * does not provide this function must set this member to NULL. * Plugin authors implementing run_multiple_synths are strongly * encouraged to implement run_synth as well if at all possible, * to aid simplistic hosts, even where it would be less efficient * to use it. */ void (*run_multiple_synths)(unsigned long InstanceCount, LADSPA_Handle *Instances, unsigned long SampleCount, snd_seq_event_t **Events, unsigned long *EventCounts); /** * run_multiple_synths_adding() * * This member is a function pointer that runs multiple synth * instances for a block, adding each synth's outputs to the * values already present at the output ports. This is provided * for symmetry with both the DSSI run_multiple_synths() and LADSPA * run_adding() functions, and is equally optional. A plugin * that does not provide it must set this member to NULL. */ void (*run_multiple_synths_adding)(unsigned long InstanceCount, LADSPA_Handle *Instances, unsigned long SampleCount, snd_seq_event_t **Events, unsigned long *EventCounts); } DSSI_Descriptor; /** * DSSI supports a plugin discovery method similar to that of LADSPA: * * - DSSI hosts may wish to locate DSSI plugin shared object files by * searching the paths contained in the DSSI_PATH and LADSPA_PATH * environment variables, if they are present. Both are expected * to be colon-separated lists of directories to be searched (in * order), and DSSI_PATH should be searched first if both variables * are set. * * - Each shared object file containing DSSI plugins must include a * function dssi_descriptor(), with the following function prototype * and C-style linkage. Hosts may enumerate the plugin types * available in the shared object file by repeatedly calling * this function with successive Index values (beginning from 0), * until a return value of NULL indicates no more plugin types are * available. Each non-NULL return is the DSSI_Descriptor * of a distinct plugin type. */ const DSSI_Descriptor *dssi_descriptor(unsigned long Index); typedef const DSSI_Descriptor *(*DSSI_Descriptor_Function)(unsigned long Index); /* * Macros to specify particular MIDI controllers in return values from * get_midi_controller_for_port() */ #define DSSI_CC_BITS 0x20000000 #define DSSI_NRPN_BITS 0x40000000 #define DSSI_NONE -1 #define DSSI_CONTROLLER_IS_SET(n) (DSSI_NONE != (n)) #define DSSI_CC(n) (DSSI_CC_BITS | (n)) #define DSSI_IS_CC(n) (DSSI_CC_BITS & (n)) #define DSSI_CC_NUMBER(n) ((n)&0x7f) #define DSSI_NRPN(n) (DSSI_NRPN_BITS | ((n) << 7)) #define DSSI_IS_NRPN(n) (DSSI_NRPN_BITS & (n)) #define DSSI_NRPN_NUMBER(n) (((n) >> 7) & 0x3fff) #ifdef __cplusplus } #endif #endif /* DSSI_INCLUDED */ ocaml-dssi-0.1.3/src/dssi.ml000066400000000000000000000070021376325360500156420ustar00rootroot00000000000000(* * Copyright 2003-2011 Savonet team * * This file is part of ocaml-dssi. * * Ocaml-mad is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Ocaml-mad is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Ocaml-mad; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *) type event = | Event_system of int * int | Event_result of int * int (* Event_note is forbidden by DSSI specification. *) | Event_note_on of int * int * int | Event_note_off of int * int * int module Plugin = struct type t exception Not_a_plugin external load : string -> t = "ocaml_dssi_open" external unload : t -> unit = "ocaml_dssi_close" end module Descriptor = struct type t exception Not_implemented external descriptor : Plugin.t -> int -> t = "ocaml_dssi_descriptor" let rec descriptors p n = try let d = descriptor p n in let dd = descriptors p (n+1) in d::dd with | Not_found -> [] let descriptors p = Array.of_list (descriptors p 0) external api_version : t -> int = "ocaml_dssi_api_version" external ladspa : t -> Ladspa.Descriptor.t = "ocaml_dssi_ladspa" external configure : t -> Ladspa.Descriptor.instance -> string -> string -> string = "ocaml_dssi_configure" external get_program : t -> Ladspa.Descriptor.instance -> int -> int * int * string = "ocaml_dssi_get_program" external select_program : t -> Ladspa.Descriptor.instance -> int -> int -> unit = "ocaml_dssi_select_program" external get_midi_controller : t -> Ladspa.Descriptor.instance -> int -> int = "ocaml_dssi_get_midi_controller_for_port" external can_run_synth : t -> bool = "ocaml_dssi_can_run_synth" external can_run_synth_adding : t -> bool = "ocaml_dssi_can_run_synth_adding" external run_synth : t -> bool -> Ladspa.Descriptor.instance -> int -> (int * event) array -> unit = "ocaml_dssi_run_synth" external can_run_multiple_synths : t -> bool = "ocaml_dssi_can_run_multiple_synths" external can_run_multiple_synths_adding : t -> bool = "ocaml_dssi_can_run_multiple_synths_adding" external run_multiple_synths : t -> bool -> Ladspa.Descriptor.instance array -> int -> (int * event) array array -> unit = "ocaml_dssi_run_multiple_synths" let run_multiple_synths d ?(adding=false) i n e = if adding then ( try run_multiple_synths d true i n e with Not_implemented -> run_multiple_synths d false i n e ) else run_multiple_synths d false i n e let run_synth d ?(adding=false) i n e = try ( try run_synth d adding i n e with | Not_implemented -> if adding then run_synth d false i n e else raise Not_implemented ) with | Not_implemented -> run_multiple_synths d ~adding [|i|] n [|e|] end let init () = Callback.register_exception "ocaml_dssi_exn_not_found" Not_found; Callback.register_exception "ocaml_dssi_exn_not_a_plugin" Plugin.Not_a_plugin; Callback.register_exception "ocaml_dssi_exn_not_implemented" Descriptor.Not_implemented let () = init () ocaml-dssi-0.1.3/src/dssi.mli000066400000000000000000000030171376325360500160150ustar00rootroot00000000000000(** Binding to DSSI SDK. @author Samuel Mimram *) (** Initialize the library. This should be called before any other function. *) val init : unit -> unit type event = | Event_system of int * int | Event_result of int * int | Event_note_on of int * int * int | Event_note_off of int * int * int (** Operations on plugins. *) module Plugin : sig (** A plugin. *) type t (** Error while loading a plugin. *) exception Not_a_plugin (** Load a plugin. *) val load : string -> t (** Unload a plugin. *) val unload : t -> unit end (** Operations on descriptors. *) module Descriptor : sig (** A descriptor. *) type t exception Not_implemented val descriptor : Plugin.t -> int -> t val descriptors : Plugin.t -> t array val api_version : t -> int val ladspa : t -> Ladspa.Descriptor.t val configure : t -> Ladspa.Descriptor.instance -> string -> string -> string val get_program : t -> Ladspa.Descriptor.instance -> int -> int * int * string val select_program : t -> Ladspa.Descriptor.instance -> int -> int -> unit val get_midi_controller : t -> Ladspa.Descriptor.instance -> int -> int val can_run_synth : t -> bool val can_run_synth_adding : t -> bool val can_run_multiple_synths : t -> bool val can_run_multiple_synths_adding : t -> bool val run_multiple_synths : t -> ?adding:bool -> Ladspa.Descriptor.instance array -> int -> (int * event) array array -> unit val run_synth : t -> ?adding:bool -> Ladspa.Descriptor.instance -> int -> (int * event) array -> unit end ocaml-dssi-0.1.3/src/dssi_stubs.c000066400000000000000000000176011376325360500167020ustar00rootroot00000000000000/* * OCaml bindings for DSSI * * Copyright 2003-2011 Savonet team * * This file is part of Ocaml-mad. * The libmad's stubs are based on madlld (see README for details). * * Ocaml-mad is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Ocaml-mad is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Ocaml-mad; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include "ocaml_dssi_config.h" #ifdef HAS_DSSI #include #else #include "dssi.h" #endif #define Descr_val(v) ((DSSI_Descriptor *)v) #define Val_descr(d) ((value)d) CAMLprim value ocaml_dssi_open(value fname) { void *handle = dlopen(String_val(fname), RTLD_LAZY); DSSI_Descriptor_Function dssi_descriptor; if (!handle) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_a_plugin")); dssi_descriptor = (DSSI_Descriptor_Function)dlsym((void *)handle, "dssi_descriptor"); if (dlerror() != NULL || !dssi_descriptor) { dlclose(handle); caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_a_plugin")); } return (value)handle; } CAMLprim value ocaml_dssi_close(value handle) { dlclose((void *)handle); return Val_unit; } CAMLprim value ocaml_dssi_descriptor(value handle, value n) { DSSI_Descriptor_Function dssi_descriptor = (DSSI_Descriptor_Function)dlsym((void *)handle, "dssi_descriptor"); const DSSI_Descriptor *d = dssi_descriptor(Int_val(n)); if (!d) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_found")); return Val_descr(d); } CAMLprim value ocaml_dssi_api_version(value d) { return Val_int(Descr_val(d)->DSSI_API_Version); } CAMLprim value ocaml_dssi_ladspa(value d) { return Val_LADSPA_descr(Descr_val(d)->LADSPA_Plugin); } CAMLprim value ocaml_dssi_configure(value d, value i, value key, value v) { char *ans; if (!Descr_val(d)->configure) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_implemented")); ans = Descr_val(d)->configure(Instance_val(i)->handle, String_val(key), String_val(v)); /* TODO */ assert(ans); value ret = caml_copy_string(ans); free(ans); return ret; } CAMLprim value ocaml_dssi_get_program(value d, value i, value n) { CAMLparam1(d); CAMLlocal1(ret); const DSSI_Program_Descriptor *ans; if (!Descr_val(d)->get_program) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_implemented")); ans = Descr_val(d)->get_program(Instance_val(i)->handle, Int_val(n)); if (!ans) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_found")); ret = caml_alloc_tuple(3); Store_field(ret, 0, Val_int(ans->Bank)); Store_field(ret, 1, Val_int(ans->Program)); Store_field(ret, 2, caml_copy_string(ans->Name)); CAMLreturn(ret); } CAMLprim value ocaml_dssi_select_program(value d, value i, value bank, value program) { if (!Descr_val(d)->select_program) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_implemented")); Descr_val(d)->select_program(Instance_val(i)->handle, Int_val(bank), Int_val(program)); return Val_unit; } CAMLprim value ocaml_dssi_get_midi_controller_for_port(value d, value i, value port) { int ans; if (!Descr_val(d)->get_midi_controller_for_port) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_implemented")); ans = Descr_val(d)->get_midi_controller_for_port(Instance_val(i)->handle, Int_val(port)); return Val_int(ans); } static snd_seq_event_t *events_of_array(value ev) { int event_count = Wosize_val(ev); snd_seq_event_t *events = malloc(event_count * sizeof(snd_seq_event_t)); int i; value e; for (i = 0; i < event_count; i++) { events[i].time.tick = Int_val(Field(Field(ev, i), 0)); e = Field(Field(ev, i), 1); if (Is_block(e)) { switch (Tag_val(e)) { case 2: events[i].type = SND_SEQ_EVENT_NOTEON; events[i].data.note.channel = Int_val(Field(e, 0)); events[i].data.note.note = Int_val(Field(e, 1)); events[i].data.note.velocity = Int_val(Field(e, 2)); break; case 3: events[i].type = SND_SEQ_EVENT_NOTEOFF; events[i].data.note.channel = Int_val(Field(e, 0)); events[i].data.note.note = Int_val(Field(e, 1)); events[i].data.note.velocity = Int_val(Field(e, 2)); break; } } } return events; } CAMLprim value ocaml_dssi_can_run_synth(value d) { return Val_bool(Descr_val(d)->run_synth); } CAMLprim value ocaml_dssi_can_run_synth_adding(value d) { return Val_bool(Descr_val(d)->run_synth_adding); } CAMLprim value ocaml_dssi_run_synth(value d, value vadd, value i, value sc, value ev) { DSSI_Descriptor *descr = Descr_val(d); LADSPA_Handle h = Instance_val(i)->handle; int sample_count = Int_val(sc); unsigned long event_count = Wosize_val(ev); snd_seq_event_t *events; int add = Bool_val(vadd); if ((!add && !Descr_val(d)->run_synth) || (add && !Descr_val(d)->run_synth_adding)) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_implemented")); events = events_of_array(ev); caml_enter_blocking_section(); if (add) descr->run_synth_adding(h, sample_count, events, event_count); else descr->run_synth(h, sample_count, events, event_count); caml_leave_blocking_section(); free(events); return Val_unit; } CAMLprim value ocaml_dssi_can_run_multiple_synths(value d) { return Val_bool(Descr_val(d)->run_multiple_synths); } CAMLprim value ocaml_dssi_can_run_multiple_synths_adding(value d) { return Val_bool(Descr_val(d)->run_multiple_synths_adding); } CAMLprim value ocaml_dssi_run_multiple_synths(value d, value vadd, value inst, value sc, value ev) { DSSI_Descriptor *descr = Descr_val(d); int sample_count = Int_val(sc); int instance_count = Wosize_val(inst); LADSPA_Handle *h; unsigned long *event_count; snd_seq_event_t **events; int i; int add = Bool_val(vadd); if ((!add && !Descr_val(d)->run_multiple_synths) || (add && !Descr_val(d)->run_multiple_synths_adding)) caml_raise_constant(*caml_named_value("ocaml_dssi_exn_not_implemented")); if (Wosize_val(ev) != instance_count) caml_invalid_argument( "the number of events should be the same as the number of instances"); h = malloc(instance_count * sizeof(LADSPA_Handle)); event_count = malloc(instance_count * sizeof(unsigned long)); events = malloc(instance_count * sizeof(snd_seq_event_t *)); for (i = 0; i < instance_count; i++) { h[i] = Instance_val(Field(inst, i))->handle; event_count[i] = Wosize_val(Field(ev, i)); events[i] = events_of_array(Field(ev, i)); } caml_enter_blocking_section(); if (add) descr->run_multiple_synths_adding(instance_count, h, sample_count, events, event_count); else descr->run_multiple_synths(instance_count, h, sample_count, events, event_count); caml_leave_blocking_section(); for (i = 0; i < instance_count; i++) free(events[i]); free(events); free(event_count); free(h); return Val_unit; } ocaml-dssi-0.1.3/src/dune000066400000000000000000000005241376325360500152260ustar00rootroot00000000000000(library (name dssi) (public_name dssi) (synopsis "OCaml bindings for dssi") (libraries ladspa) (enabled_if (or (= %{system} "linux") (= %{system} "macosx"))) (foreign_stubs (language c) (names dssi_stubs) (extra_deps ocaml_dssi_config.h))) (rule (targets ocaml_dssi_config.h) (action (run ./config/discover.exe)))