pax_global_header00006660000000000000000000000064135422441440014515gustar00rootroot0000000000000052 comment=de37569c926c5886768f892c019e3f0468615038 a2jmidid-9/000077500000000000000000000000001354224414400127125ustar00rootroot00000000000000a2jmidid-9/.gitignore000066400000000000000000000000151354224414400146760ustar00rootroot00000000000000/TAGS /build a2jmidid-9/AUTHORS.rst000066400000000000000000000005071354224414400145730ustar00rootroot00000000000000======= Authors ======= * David Runge * Dmitry S. Baikov * Juuso Alasuutari has copyright ownership on some D-Bus related code, taken from other projects (lash, jackdbus). * Nedko Arnaudov * Paul Davis * Torben Hohn a2jmidid-9/CHANGELOG.rst000066400000000000000000000063051354224414400147370ustar00rootroot00000000000000========= Changelog ========= Version 9 on 2019-09-24 ----------------------- * architecture fixes for aarch64 and powerpc64 * porting a2j_control to python3 * replace waf with meson as build system * control unique port names over D-Bus * man page spelling fixes * fix linking against libpthread Version 8 "Sophronius of Vratsa" on 2012-07-05 ---------------------------------------------- * -u commandline option * D-Bus method for checking whether hw export is enabled. Kudos to Danni Coy * Fix for resource leak. Kudos to Dan A. Muresan * Improved error message for snd_seq_connect_to() failures * --mandir= option in waf. Kudos to Dan Church Version 7 "Paisius of Hilendar" on 2011-01-16 --------------------------------------------- * MIDI processing improvements * Use the JACK limit for max port name size (sr #2526) * Adopt to shared library policy changes in some distros (sr #2547) * dbus support can now be disabled at configure stage * fix build on not so common platforms (LP: #556351) * man pages (from Debian) * reopen log file when it is deleted or replaced Version 6 "Indzhe Voyvoda" on 2009-12-29 ---------------------------------------- * MIDI processing improvements * Handle large number of ports * a2j script (non-dbus-like behaviour for dbus environment) * Allow tweaking through dbus of the hardware port export option * Fix a use of invalid memory * Fix port miss that can occur if port appears during bridge startup Version 5 "Athos" on 2009-06-13 ------------------------------- * Fix thight loop on D-Bus disconnect * D-Bus signals for bridge start and stop * Fixed alsamidi "disappearing output" bug. (backport from jack1) * MIDI note-off normalization fix from Dave Robillard (Backport from jack1) * Removed wrong assert from alsa_seqmidi.c reported by Ken Ellinwood (Backport from jack1) * Mark anything that looks like a hardware port as physical&terminal (Backport from jack1/jack2) * Fix potential crash when D-Bus is not used * Support for multiple ALSA clients with same name * Merge midibridge changeset by Paul Davis that is expected to fix midi event timing problems that some people have reported. Version 4 "Devsirme" on 2008-08-03 ---------------------------------- * Fix typos in docs * Disable use of C++ demangling in sigsegv. Fix for sr #2074 * Fix a2j_control help text (thanks kfoltman!) * Request fixed JACK client name. Fix for bug #12139 * Handle missing svnversion executable nicely. Fixes bug #12138 Version 3 "Bodrum" on 2008-08-03 -------------------------------- * Improved port naming, support for bidirectional ports * Allow exporting of hardware ports (disabled by default) * Switch from autotools to waf * Remove support for old JACK MIDI API variants * Remove usage of posix semaphores that could cause sleep in realtime context, in rare circumstances * D-Bus background service mode. The old manual mode is still working. * Log file when running in background service mode. * Improved documentation * Import, with slight modifications, static bridges created by Sean Bolton and Lars Luthman. Version 2 on 2007-10-27 ----------------------- * Improved build system (autotools) and support for older JACK variants Version 1 on 2007-08-26 ----------------------- * Initial release a2jmidid-9/INSTALLATION.rst000066400000000000000000000021641354224414400153500ustar00rootroot00000000000000============ Installation ============ *a2jmidid* uses the |meson| build system. Configure and build ------------------- To configure the project, |meson|'s |meson_universal_options| (e.g. *prefix*) can be used to prepare a build directory:: meson --prefix=/usr build One additional - project specific - option enables for building without |dbus| support:: meson --prefix=/usr -Ddisable-dbus=true build To build the application |ninja| is required:: ninja -C build Install ------- |meson| is able to install the project components to the system directories (when run as root), while honoring the *DESTDIR* environment variable:: DESTDIR="/some/other/location" meson install -C build .. |meson| raw:: html Meson .. |meson_universal_options| raw:: html universal options .. |dbus| raw:: html D-Bus .. |ninja| raw:: html Ninja a2jmidid-9/LICENSE000066400000000000000000000431031354224414400137200ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 Lesser General Public License instead of this License. a2jmidid-9/README.rst000066400000000000000000000075531354224414400144130ustar00rootroot00000000000000======== a2jmidid ======== This project aims to ease the usage of legacy, non |jack| enabled applications, in a |jack| MIDI enabled system, when using |jack2| There are two ways to use legacy |alsa| sequencer applications in a |jack| MIDI system: **Automatic bridging**: For every |alsa| sequencer port you get one |jack| MIDI port. If an |alsa| sequencer port is both an input and an output, you get two |jack| MIDI ports, one input and output. (*This approach works almost always except when the legacy ALSA sequencer application does not create ports and/or wants to use an existing port to capture from or playback to. Such programs are using a feature of the |alsa| sequencer framework that allows sending and receiving MIDI events to/from a port, without creating a connection to it.*) **Static bridges**: You start an application that creates one |alsa| sequencer port and one |jack| MIDI port. Such a bridge is unidirectional. For details on how to build and install this project, look at `INSTALLATION.rst `_. a2jmidid -------- a2jmidid is a daemon that implements **automatic bridging**. It has two modes of operation: Running a bridge manually or as a backgrounded |dbus| service. Start daemon ____________ To start *a2jmidid* in manual mode, just run the executable. *a2jmidid* will start bridging, and you will get output on stdout and stderr. You can stop the bridge using *ctrl-c*. Usually you want to bridge software ports and not bridge hardware ports (they are handled by |jack| itself). In case you want to force *a2jmidid* to bridge hardware ports nonetheless, you can use the according flags:: a2jmidid -e or:: a2jmidid --export-hw Start D-Bus service ___________________ In D-Bus service mode, a2jmidid works in the background. When service access is requested by some application (such as *a2j_control*), the |dbus| session bus daemon activates the object by executing the service executable. The object has methods for starting and stopping the bridging. You can use *a2j_control* to do this:: a2j_control --start a2j_control --stop You can deactivate (that may cause later reactivation) the service like this:: a2j_control --exit You can query the bridge status using this command:: a2j_control --status There also methods (and corresponding a2j_control commands) that can be used to query mapping information:: a2j_control --help The *a2jmidid* implementation is based on *jack-alsamidi-0.5*, which is (almost) identical to the jackd |alsa| *seq* MIDI backend), both created by Dmitry Baikov. a2jmidi_bridge -------------- *a2jmidi_bridge* creates a **static bridge** between one |alsa| sequencer playback port and one |jack| MIDI capture port. MIDI events sent to the |alsa| sequencer playback port can be read from the |jack| MIDI capture port. *a2jmidi_bridge* has an optional argument that allows overriding the name used for the |jack| and |alsa| client:: a2jmidi_bridge "my precious bridge" The *a2jmidi_bridge* implementation is based on *alsaseq2jackmidi* by Sean Bolton. j2amidi_bridge -------------- *j2amidi_bridge* creates a **static bridge** between one |jack| MIDI playback port and one |alsa| sequencer capture port. MIDI events sent to |jack| MIDI playback port can be read from the |alsa| sequencer capture port. *j2amidi_bridge* has an optional argument that allows overriding the name used for the |jack| and |alsa| client:: j2amidi_bridge "my precious bridge" The *j2amidi_bridge* implementation is based on jackmidi2alsaseq by Lars Luthman. .. |jack| raw:: html JACK .. |jack2| raw:: html jack2 .. |dbus| raw:: html D-Bus .. |alsa| raw:: html ALSA a2jmidid-9/a2j000077500000000000000000000004361354224414400133170ustar00rootroot00000000000000#!/bin/sh # # This script accesses a2jmidid over dbus # and behaves as a2jmidid in non-dbus mode # if test $# -eq 1 -a x$1 = x-e then echo "hardware ports export" a2j_control ehw else a2j_control dhw fi a2j_control start trap "a2j_control stop; exit" INT TERM read unused a2jmidid-9/a2j_control000077500000000000000000000156141354224414400150630ustar00rootroot00000000000000#!/usr/bin/env python3 from argparse import ArgumentParser import dbus class A2JControl: """ Class holding all data and relevant functions to interact with the a2j dbus controller interface. """ service_name = 'org.gna.home.a2jmidid' control_interface_name = service_name + '.control' controller_interface = None parser = None args = None def add_arg_parser(self): self.parser = ArgumentParser( description='Bridge ALSA MIDI to JACK MIDI') self.parser.add_argument( '--start', action='store_true', default=False, help='Start bridging') self.parser.add_argument( '--stop', action='store_true', default=False, help='Stop bridging') self.parser.add_argument( '--exit', action='store_true', default=False, help='Exit a2j bridge dbus service') self.parser.add_argument( '--status', action='store_true', default=False, help='Display bridging status') self.parser.add_argument( '--gjcn', '--jack-client-name', action='store_true', default=False, help='Get JACK client name') self.parser.add_argument( '--ma2jp', default=None, nargs=2, help='Map ALSA input port to JACK output port' + ' (requires ALSA client ID and JACK port ID arguments)') self.parser.add_argument( '--ma2jc', default=None, nargs=2, help='Map ALSA output port to JACK input port ' + '(requires ALSA client ID and JACK port ID arguments)') self.parser.add_argument( '--mj2a', default=None, nargs=1, help='Map JACK port to ALSA port (requires JACK port name)') self.parser.add_argument( '--ehw', action='store_true', default=False, help='Enable export of ALSA hardware ports') self.parser.add_argument( '--dhw', action='store_true', default=False, help='Disable export of ALSA hardware ports') self.parser.add_argument( '--aup', action='store_true', default=False, help='Allow unique port names') self.parser.add_argument( '--dup', action='store_true', default=False, help='Disallow unique port names') self.args = self.parser.parse_args() def initialize_dbus_controller_interface(self): controller = dbus.SessionBus().get_object(self.service_name, "/") self.controller_interface = dbus.Interface( controller, self.control_interface_name) def controller_start(self): print('--- start') self.controller_interface.start() def controller_stop(self): print('--- stop') self.controller_interface.stop() def controller_exit(self): print('--- exit') self.controller_interface.exit() def controller_status(self): print('--- status') if self.controller_interface.is_started(): print('Bridging enabled') else: print('Bridging disabled') if self.controller_interface.get_hw_export(): print('Hardware exported') else: print('Hardware not exported') if self.controller_interface.get_disable_port_uniqueness(): print('Avoiding unique port names') else: print('Allowing unique port names') def controller_map_alsa_in_to_jack_playback( self, alsa_client_id, jack_port): print('--- map ALSA to JACK playback port') print('{}'.format(self.controller_interface.map_alsa_to_jack_port( alsa_client_id, jack_port, True))) def controller_map_alsa_out_to_jack_capture( self, alsa_client_id, jack_port): print('--- map ALSA to JACK capture port') print('{}'.format(self.controller_interface.map_alsa_to_jack_port( alsa_client_id, jack_port, False))) def controller_map_jack_port_to_alsa(self, jack_port): print('--- map JACK to ALSA port') out = self.controller_interface.map_jack_port_to_alsa(jack_port) print('{}:{} ({}:{})'.format(out[0], out[1], out[2], out[3])) def controller_get_jack_client_name(self): print('--- get jack client name') print(self.controller_interface.get_jack_client_name()) def controller_export_hardware_ports(self, state): if state: print('--- enable export of hardware ports') self.controller_interface.set_hw_export(True) else: print('--- disable export of hardware ports') self.controller_interface.set_hw_export(False) def controller_set_port_name_uniqueness(self, state): if state: print('--- allow unique port names') self.controller_interface.set_disable_port_uniqueness(False) else: print('--- disallow unique port names') self.controller_interface.set_disable_port_uniqueness(True) def call_controller_function(self): if self.args.start: self.controller_start() elif self.args.stop: self.controller_stop() elif self.args.exit: self.controller_exit() elif self.args.status: self.controller_status() elif self.args.gjcn: self.controller_get_jack_client_name() elif self.args.ma2jp: self.controller_map_alsa_in_to_jack_playback( self.args.ma2jp[0], self.args.ma2jp[1]) elif self.args.ma2jc: self.controller_map_alsa_in_to_jack_playback( self.args.ma2jc[0], self.args.ma2jc[1]) elif self.args.mj2a: self.controller_map_jack_port_to_alsa(self.args.mj2a[0]) elif self.args.ehw: self.controller_export_hardware_ports(True) elif self.args.dhw: self.controller_export_hardware_ports(False) elif self.args.dup: self.controller_set_port_name_uniqueness(False) elif self.args.aup: self.controller_set_port_name_uniqueness(True) else: self.parser.print_help() def __init__(self): self.initialize_dbus_controller_interface() self.add_arg_parser() self.call_controller_function() if __name__ == '__main__': A2JControl() a2jmidid-9/a2jmidi_bridge.c000066400000000000000000000146261354224414400157220ustar00rootroot00000000000000/* alsaseq2jackmidi.c * * copies MIDI events from an ALSA sequencer client to a JACK MIDI client * * Copyright (c)2005 Sean Bolton. * Copyright (c) 2008,2009 Nedko Arnaudov * * 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. */ /* compile with: gcc -Wall -o alsaseq2jackmidi alsaseq2jackmidi.c -ljack -lasound */ /* gcc -Wall -I/tmp/jackmidi/include -o alsaseq2jackmidi alsaseq2jackmidi.c -L/tmp/jackmidi/lib -ljack -lasound */ #include #include #include #include #include #include #include #include #include snd_seq_t *seq_handle; snd_midi_event_t *alsa_decoder; jack_ringbuffer_t *jack_ringbuffer; jack_client_t *jack_client; jack_port_t *jack_midi_port; int jack_write_overflows = 0, old_jack_write_overflows = 0, events_copied = 0, old_events_copied = 0; bool g_keep_walking; void midi_action(snd_seq_t *seq_handle) { snd_seq_event_t *ev; static unsigned char buffer[16]; long count; do { snd_seq_event_input(seq_handle, &ev); count = snd_midi_event_decode(alsa_decoder, buffer + 1, 16, ev); if (count > 0 && count < 16) { buffer[0] = (unsigned char)count; count++; if (jack_ringbuffer_write(jack_ringbuffer, (char *)buffer, count) != count) { fprintf(stderr, "ringbuffer overflow!\n"); } } snd_seq_free_event(ev); } while (snd_seq_event_input_pending(seq_handle, 0) > 0); } int jack_callback(jack_nframes_t nframes, void *arg) { static unsigned char buffer[16]; size_t count; unsigned char *p; void* port_buf = jack_port_get_buffer(jack_midi_port, nframes); jack_midi_clear_buffer(port_buf); while (jack_ringbuffer_read_space(jack_ringbuffer)) { count = jack_ringbuffer_peek(jack_ringbuffer, (char*)buffer, 1); if (count) { count = (size_t)buffer[0]; if (jack_ringbuffer_read(jack_ringbuffer, (char*)buffer, count + 1) != count + 1) { fprintf(stderr, "???? short read from ringbuffer!\n"); /* shouldn't happen */ } else { /* -FIX- this should have the frame time of the event, instead of '0': */ p = jack_midi_event_reserve(port_buf, 0, count); if (p) { memcpy(p, buffer + 1, count); events_copied++; } else jack_write_overflows++; } } } return 0; } static void jack_shutdown( void * arg) { fprintf(stderr, "JACK shutdown notification received.\n"); g_keep_walking = false; } static void sigint_handler( int i) { g_keep_walking = false; } int main(int argc, char *argv[]) { int portid; int npfd; struct pollfd *pfd; const char * client_name; jack_status_t status; if (argc == 2) { client_name = argv[1]; } else { client_name = "a2j_bridge"; } /* Create ALSA sequencer client */ if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_INPUT, 0) < 0) { fprintf(stderr, "Error opening ALSA sequencer.\n"); exit(1); } snd_seq_set_client_name(seq_handle, client_name); if ((portid = snd_seq_create_simple_port(seq_handle, "playback", SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_HARDWARE)) < 0) { fprintf(stderr, "Error creating sequencer port.\n"); exit(1); } npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN); pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd)); snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN); /* Create ALSA snd_seq_event_t decoder */ if (snd_midi_event_new(16, &alsa_decoder)) { fprintf(stderr, "Error initializing ALSA MIDI decoder!\n"); exit(1); } snd_midi_event_reset_decode(alsa_decoder); snd_midi_event_no_status(alsa_decoder, 1); /* Create interthread ringbuffer */ jack_ringbuffer = jack_ringbuffer_create(2048); if (!jack_ringbuffer) { fprintf(stderr, "Failed to create ringbuffer!\n"); exit(1); } jack_ringbuffer_reset(jack_ringbuffer); /* Create JACK MIDI client */ jack_client = jack_client_open(client_name, 0, &status); if (jack_client == 0) { fprintf(stderr, "Failed to connect to JACK server!\n"); exit(1); } jack_midi_port = jack_port_register (jack_client, "capture", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); if (!jack_midi_port) { fprintf(stderr, "Failed to create JACK MIDI port!\n"); exit(1); } jack_set_process_callback(jack_client, jack_callback, 0); g_keep_walking = true; jack_on_shutdown(jack_client, jack_shutdown, NULL); signal(SIGINT, &sigint_handler); signal(SIGTERM, &sigint_handler); if (jack_activate(jack_client)) { fprintf(stderr, "Failed to activate JACK client!\n"); exit(1); } while (g_keep_walking) { if (poll(pfd, npfd, 1000) > 0) { midi_action(seq_handle); } if (jack_write_overflows != old_jack_write_overflows) { old_jack_write_overflows = jack_write_overflows; fprintf(stderr, "JACK port write overflow count now %d\n", jack_write_overflows); } // if (events_copied != old_events_copied) { // old_events_copied = events_copied; // fprintf(stderr, "%d events copied\n", events_copied); // } } /* -FIX- provide a way to cleanly exit, and clean up! */ jack_client_close(jack_client); jack_ringbuffer_free(jack_ringbuffer); snd_seq_close(seq_handle); return 0; } a2jmidid-9/a2jmidid.c000066400000000000000000000301331354224414400145410ustar00rootroot00000000000000/* * ALSA SEQ < - > JACK MIDI bridge * * Copyright (c) 2006,2007 Dmitry S. Baikov * Copyright (c) 2007,2008,2009,2011 Nedko Arnaudov * * 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; version 2 of the License. * * 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 */ #include "config.h" #include #include #include #include #include #include #include #include #include #if HAVE_DBUS_1 # include #endif #include #include "list.h" #include "structs.h" #include "port.h" #include "port_thread.h" #include "port_hash.h" #include "log.h" #if HAVE_DBUS_1 # include "dbus.h" #endif #include "a2jmidid.h" #include "paths.h" #include "conf.h" #include "jack.h" #include "sigsegv.h" #include "dbus_iface_control.h" #define MAIN_LOOP_SLEEP_INTERVAL 50 // in milliseconds bool g_keep_walking = true; bool g_keep_alsa_walking = false; bool g_stop_request = false; static bool g_started = false; struct a2j * g_a2j = NULL; size_t g_max_jack_port_name_size; bool g_disable_port_uniqueness = false; bool g_a2j_export_hw_ports = false; char * g_a2j_jack_server_name = "default"; static void a2j_sigint_handler( int i) { g_keep_walking = false; } static bool a2j_stream_init( struct a2j * self, int dir) { struct a2j_stream *str = &self->stream[dir]; str->new_ports = jack_ringbuffer_create(MAX_PORTS * sizeof(struct a2j_port *)); if (str->new_ports == NULL) { return false; } snd_midi_event_new(MAX_EVENT_SIZE, &str->codec); INIT_LIST_HEAD(&str->list); return true; } static void a2j_stream_attach( struct a2j_stream * stream_ptr) { } static void a2j_stream_detach( struct a2j_stream * stream_ptr) { struct a2j_port * port_ptr; struct list_head * node_ptr; while (!list_empty(&stream_ptr->list)) { node_ptr = stream_ptr->list.next; list_del(node_ptr); port_ptr = list_entry(node_ptr, struct a2j_port, siblings); a2j_info("port deleted: %s", port_ptr->name); a2j_port_free(port_ptr); } } static void a2j_stream_close( struct a2j * self, int dir) { struct a2j_stream *str = &self->stream[dir]; if (str->codec) snd_midi_event_free(str->codec); if (str->new_ports) jack_ringbuffer_free(str->new_ports); } struct a2j * a2j_new(void) { int error; void * thread_status; struct a2j *self = calloc(1, sizeof(struct a2j)); a2j_debug("midi: new"); if (!self) { a2j_error("calloc() failed to allocate a2j struct"); goto fail; } self->port_add = jack_ringbuffer_create(2 * MAX_PORTS * sizeof(snd_seq_addr_t)); if (self->port_add == NULL) { goto free_self; } self->port_del = jack_ringbuffer_create(2 * MAX_PORTS * sizeof(struct a2j_port *)); if (self->port_del == NULL) { goto free_ringbuffer_add; } self->outbound_events = jack_ringbuffer_create(MAX_EVENT_SIZE * 16 * sizeof(struct a2j_delivery_event)); if (self->outbound_events == NULL) { goto free_ringbuffer_del; } if (!a2j_stream_init(self, A2J_PORT_CAPTURE)) { goto free_ringbuffer_outbound; } if (!a2j_stream_init(self, A2J_PORT_PLAYBACK)) { goto close_capture_stream; } error = snd_seq_open(&self->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0); if (error < 0) { a2j_error("failed to open alsa seq"); goto close_playback_stream; } error = snd_seq_set_client_name(self->seq, "a2jmidid"); if (error < 0) { a2j_error("snd_seq_set_client_name() failed"); goto close_seq_client; } self->port_id = snd_seq_create_simple_port( self->seq, "port", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE #ifndef DEBUG |SND_SEQ_PORT_CAP_NO_EXPORT #endif ,SND_SEQ_PORT_TYPE_APPLICATION); if (self->port_id < 0) { a2j_error("snd_seq_create_simple_port() failed"); goto close_seq_client; } self->client_id = snd_seq_client_id(self->seq); if (self->client_id < 0) { a2j_error("snd_seq_client_id() failed"); goto close_seq_client; } self->queue = snd_seq_alloc_queue(self->seq); if (self->queue < 0) { a2j_error("snd_seq_alloc_queue() failed"); goto close_seq_client; } snd_seq_start_queue(self->seq, self->queue, 0); a2j_stream_attach(self->stream + A2J_PORT_CAPTURE); a2j_stream_attach(self->stream + A2J_PORT_PLAYBACK); error = snd_seq_nonblock(self->seq, 1); if (error < 0) { a2j_error("snd_seq_nonblock() failed"); goto close_seq_client; } snd_seq_drop_input(self->seq); a2j_add_ports(&self->stream[A2J_PORT_CAPTURE]); a2j_add_ports(&self->stream[A2J_PORT_PLAYBACK]); self->jack_client = a2j_jack_client_create(self, A2J_JACK_CLIENT_NAME, g_a2j_jack_server_name); if (self->jack_client == NULL) { goto free_self; } if (sem_init(&self->io_semaphore, 0, 0) < 0) { a2j_error("can't create IO semaphore"); goto close_jack_client; } if (jack_activate(self->jack_client)) { a2j_error("can't activate jack client"); goto sem_destroy; } g_keep_alsa_walking = true; if (pthread_create(&self->alsa_input_thread, NULL, a2j_alsa_input_thread, self) < 0) { a2j_error("cannot start ALSA input thread"); goto sem_destroy; } /* wake the poll loop in the alsa input thread so initial ports are fetched */ error = snd_seq_connect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE); if (error < 0) { a2j_error("snd_seq_connect_from() failed"); goto join_input_thread; } if (pthread_create(&self->alsa_output_thread, NULL, a2j_alsa_output_thread, self) < 0) { a2j_error("cannot start ALSA output thread"); goto disconnect; } return self; disconnect: g_keep_alsa_walking = false; /* tell alsa threads to stop */ snd_seq_disconnect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE); join_input_thread: pthread_join(self->alsa_input_thread, &thread_status); sem_destroy: sem_destroy(&self->io_semaphore); close_jack_client: error = jack_client_close(self->jack_client); if (error != 0) { a2j_error("Cannot close jack client"); } close_seq_client: snd_seq_close(self->seq); close_playback_stream: a2j_stream_close(self, A2J_PORT_PLAYBACK); close_capture_stream: a2j_stream_close(self, A2J_PORT_CAPTURE); free_ringbuffer_outbound: jack_ringbuffer_free(self->outbound_events); free_ringbuffer_del: jack_ringbuffer_free(self->port_del); free_ringbuffer_add: jack_ringbuffer_free(self->port_add); free_self: free(self); fail: return NULL; } static void a2j_destroy(struct a2j * self) { int error; void * thread_status; a2j_debug("midi: delete"); g_keep_alsa_walking = false; /* tell alsa threads to stop */ /* do something that we need to do anyway and will wake the input thread, then join */ snd_seq_disconnect_from(self->seq, self->port_id, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_ANNOUNCE); pthread_join(self->alsa_input_thread, &thread_status); /* wake output thread and join, then destroy the semaphore */ sem_post(&self->io_semaphore); pthread_join(self->alsa_output_thread, &thread_status); sem_destroy(&self->io_semaphore); jack_ringbuffer_reset(self->port_add); jack_deactivate(self->jack_client); a2j_stream_detach(self->stream + A2J_PORT_CAPTURE); a2j_stream_detach(self->stream + A2J_PORT_PLAYBACK); error = jack_client_close(self->jack_client); if (error != 0) { a2j_error("Cannot close jack client (%d)", error); } snd_seq_close(self->seq); self->seq = NULL; a2j_stream_close(self, A2J_PORT_PLAYBACK); a2j_stream_close(self, A2J_PORT_CAPTURE); jack_ringbuffer_free(self->outbound_events); jack_ringbuffer_free(self->port_add); jack_ringbuffer_free(self->port_del); free(self); } bool a2j_start(void) { if (g_started) { a2j_error("Bridge already started"); return false; } a2j_info("Bridge starting..."); a2j_info("Using JACK server '%s'", g_a2j_jack_server_name); a2j_info("Hardware ports %s be exported.", g_a2j_export_hw_ports ? "will": "will not"); g_a2j = a2j_new(); if (g_a2j == NULL) { a2j_error("a2j_new() failed."); return false; } a2j_info("Bridge started"); #if HAVE_DBUS_1 if (a2j_dbus_is_available()) { a2j_dbus_signal_emit_bridge_started(); } #endif g_started = true; return true; } bool a2j_stop(void) { if (!g_started) { a2j_error("Bridge already stopped"); return false; } a2j_info("Bridge stopping..."); a2j_destroy(g_a2j); g_a2j = NULL; a2j_info("Bridge stopped"); g_started = false; #if HAVE_DBUS_1 if (a2j_dbus_is_available()) { a2j_dbus_signal_emit_bridge_stopped(); } #endif return true; } bool a2j_is_started() { return g_started; } static void a2j_help( const char * self) { a2j_info("Usage: %s [-j jack-server] [-e | --export-hw] [-u]", self); a2j_info("Defaults:"); a2j_info("-j default"); } int main( int argc, char *argv[]) { bool dbus; struct stat st; char timestamp_str[26]; //test_list_sort(); st.st_mtime = 0; stat(argv[0], &st); ctime_r(&st.st_mtime, timestamp_str); timestamp_str[24] = 0; g_max_jack_port_name_size = jack_port_name_size(); if (!a2j_paths_init()) { goto fail; } #if HAVE_DBUS_1 dbus = argc == 2 && strcmp(argv[1], "dbus") == 0; #else dbus = false; #endif if (!a2j_log_init(dbus)) { goto fail_paths_uninit; } if (!dbus) { struct option long_opts[] = { { "export-hw", 0, 0, 'e' }, { 0, 0, 0, 0 } }; int option_index = 0; int c; while ((c = getopt_long(argc, argv, "j:eu", long_opts, &option_index)) != -1) { switch (c) { case 'j': g_a2j_jack_server_name = strdup(optarg); break; case 'e': g_a2j_export_hw_ports = true; break; case 'u': g_disable_port_uniqueness = true; break; default: a2j_help(argv[0]); return 1; } } } else { //a2j_conf_load(); } if (dbus) { a2j_info("----------------------------"); } a2j_info("JACK MIDI <-> ALSA sequencer MIDI bridge, version " A2J_VERSION " built on %s", timestamp_str); a2j_info("Copyright 2006,2007 Dmitry S. Baikov"); a2j_info("Copyright 2007,2008,2009,2011,2012 Nedko Arnaudov"); if (dbus) { a2j_info("----------------------------"); a2j_info("Activated."); } else { a2j_info(""); } /* setup our SIGSEGV magic that prints nice stack in our logfile */ if (dbus) { setup_sigsegv(); } signal(SIGINT, &a2j_sigint_handler); signal(SIGTERM, &a2j_sigint_handler); if (dbus) { #if HAVE_DBUS_1 if (!a2j_dbus_init()) { a2j_error("a2j_dbus_init() failed."); goto fail_uninit_log; } #endif } else { if (!a2j_start()) { goto fail_uninit_log; } a2j_info("Press ctrl-c to stop the bridge"); } while (g_keep_walking) { if (dbus) { #if HAVE_DBUS_1 if (!a2j_dbus_run(MAIN_LOOP_SLEEP_INTERVAL)) { a2j_warning("Disconnect message was received from D-Bus."); break; } #endif } else { usleep(MAIN_LOOP_SLEEP_INTERVAL * 1000); } if (g_stop_request) { g_stop_request = false; a2j_stop(); if (!dbus) { break; } } if (g_started) { a2j_free_ports(g_a2j->port_del); a2j_update_ports(g_a2j); } } if (g_started) { a2j_stop(); } #if HAVE_DBUS_1 if (dbus) { a2j_dbus_uninit(); a2j_info("Deactivated."); a2j_info("----------------------------"); } #endif fail_uninit_log: a2j_log_uninit(); fail_paths_uninit: a2j_paths_uninit(); fail: return 0; } a2jmidid-9/a2jmidid.h000066400000000000000000000024561354224414400145550ustar00rootroot00000000000000/* -*- Mode: C ; c-basic-offset: 2 -*- */ /* * ALSA SEQ < - > JACK MIDI bridge * * Copyright (c) 2008,2009 Nedko Arnaudov * * 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; version 2 of the License. * * 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 */ #ifndef A2JMIDID_H__A9B1D7AF_8702_48D4_899B_86B25FA4F54C__INCLUDED #define A2JMIDID_H__A9B1D7AF_8702_48D4_899B_86B25FA4F54C__INCLUDED bool a2j_start(void); bool a2j_stop(void); bool a2j_is_started(void); void * a2j_alsa_input_thread(void * arg); void * a2j_alsa_output_thread(void * arg); extern bool g_keep_walking; extern bool g_keep_alsa_walking; extern bool g_stop_request; #define A2J_JACK_CLIENT_NAME "a2j" #endif /* #ifndef A2JMIDID_H__A9B1D7AF_8702_48D4_899B_86B25FA4F54C__INCLUDED */ a2jmidid-9/conf.c000066400000000000000000000217201354224414400140050ustar00rootroot00000000000000/* -*- Mode: C ; c-basic-offset: 2 -*- */ /* * ALSA SEQ < - > JACK MIDI bridge * * Copyright (c) 2008,2009 Nedko Arnaudov * * 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; version 2 of the License. * * 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 */ #include #include #include #include #include #include #include #include #include "conf.h" #include "log.h" #include "paths.h" #define A2J_CONF_HEADER_TEXT \ "a2jmidid settings.\n" \ "You probably don't want to edit this because\n" \ "it will be overwritten next time a2jmidid saves.\n" bool a2j_settings_write_string(int fd, const char * string) { size_t len; len = strlen(string); if (write(fd, string, len) != len) { a2j_error("write() failed to write config file."); return false; } return true; } bool a2j_settings_write_option( int fd, const char * name, const char * content) { if (!a2j_settings_write_string(fd, " ")) { return false; } if (!a2j_settings_write_string(fd, "\n")) { return false; } return true; } void a2j_conf_save() { int fd; bool ret; time_t timestamp; char timestamp_str[26]; time(×tamp); ctime_r(×tamp, timestamp_str); timestamp_str[24] = 0; a2j_info("Saving settings to \"%s\" ...", g_a2j_conf_path); fd = open(g_a2j_conf_path, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd == -1) { a2j_error("open() failed to open conf filename. error is %d (%s)", errno, strerror(errno)); goto exit; } if (!a2j_settings_write_string(fd, "\n")) { goto exit_close; } if (!a2j_settings_write_string(fd, "\n")) { goto exit_close; } if (!a2j_settings_write_string(fd, "\n")) { goto exit_close; } if (!a2j_settings_write_string(fd, "\n")) { goto exit_close; } if (!a2j_settings_write_option(fd, "jack_server_name", g_a2j_jack_server_name)) { goto exit_close; } if (!a2j_settings_write_option(fd, "export_hw_ports", g_a2j_export_hw_ports ? "true" : "false")) { goto exit_close; } if (!a2j_settings_write_string(fd, "\n")) { goto exit_close; } ret = true; exit_close: close(fd); exit: return; } #define PARSE_CONTEXT_ROOT 0 #define PARSE_CONTEXT_A2J 1 #define PARSE_CONTEXT_OPTION 2 #define MAX_STACK_DEPTH 10 #define MAX_OPTION_LENGTH 100 struct parse_context { XML_Bool error; unsigned int element[MAX_STACK_DEPTH]; signed int depth; char option[MAX_OPTION_LENGTH+1]; int option_used; char * name; }; void a2j_conf_set_bool_option( const char * value_str, bool * value_ptr) { if (strcmp(value_str, "true") == 0) { *value_ptr = true; } else if (strcmp(value_str, "false") == 0) { *value_ptr = false; } else { a2j_error("ignoring unknown bool value \"%s\"", value_str); } } void a2j_conf_set_string_option( const char * input, char ** value) { char * dup; dup = strdup(input); if (dup == NULL) { a2j_error("Out of memory"); return; } *value = dup; } void a2j_conf_set_option( const char * option_name, const char * option_value) { a2j_info("setting option \"%s\" to value \"%s\"", option_name, option_value); if (strcmp(option_name, "jack_server_name") == 0) { a2j_conf_set_string_option(option_value, &g_a2j_jack_server_name); } else if (strcmp(option_name, "export_hw_ports") == 0) { a2j_conf_set_bool_option(option_value, &g_a2j_export_hw_ports); } else { a2j_error( "Unknown parameter \"%s\"", option_name); return; } } #define context_ptr ((struct parse_context *)data) void a2j_conf_settings_callback_chrdata(void *data, const XML_Char *s, int len) { if (context_ptr->error) { return; } if (context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_OPTION) { if (context_ptr->option_used + len >= MAX_OPTION_LENGTH) { a2j_error("xml parse max char data length reached"); context_ptr->error = XML_TRUE; return; } memcpy(context_ptr->option + context_ptr->option_used, s, len); context_ptr->option_used += len; } } void a2j_conf_settings_callback_elstart(void *data, const char *el, const char **attr) { if (context_ptr->error) { return; } if (context_ptr->depth + 1 >= MAX_STACK_DEPTH) { a2j_error("xml parse max stack depth reached"); context_ptr->error = XML_TRUE; return; } if (strcmp(el, "a2jmidid") == 0) { //a2j_info(""); context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_A2J; return; } if (strcmp(el, "option") == 0) { //a2j_info("