From 1245ab151b5a8c70acd3b3e609adf84b0032a75c Mon Sep 17 00:00:00 2001 From: Olivier Jolly Date: Tue, 2 Feb 2016 11:06:23 +0100 Subject: [PATCH] Add xrni comment command line utility --- rnsutils/instrument.py | 5 ++- rnsutils/xrnicomment.py | 85 +++++++++++++++++++++++++++++++++++++++++ setup.py | 1 + 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 rnsutils/xrnicomment.py diff --git a/rnsutils/instrument.py b/rnsutils/instrument.py index 30d69a7..14b4299 100644 --- a/rnsutils/instrument.py +++ b/rnsutils/instrument.py @@ -173,7 +173,10 @@ class RenoiseInstrument(object): @property def comment(self): - return "\n".join(self.root.GlobalProperties.Comments.Comment) + try: + return "\n".join([comment.pyval for comment in self.root.GlobalProperties.Comments.Comment]) + except AttributeError: + return None @comment.setter def comment(self, value): diff --git a/rnsutils/xrnicomment.py b/rnsutils/xrnicomment.py new file mode 100644 index 0000000..e3534e8 --- /dev/null +++ b/rnsutils/xrnicomment.py @@ -0,0 +1,85 @@ +# xrnicomment. manipulate XRNI comments +# Copyright (C) 2016 Olivier Jolly +# +# 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 3 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, see . + +from __future__ import print_function + +import argparse +import logging +import sys + +import os + +from rnsutils.instrument import RenoiseInstrument + +__date__ = '2016-02-02' +__updated__ = '2016-02-02' +__author__ = 'olivier@pcedev.com' + +ACTION_VIEW = 0 +ACTION_EDIT = 1 +ACTION_DELETE = 2 + + +def main(argv=None): + program_name = os.path.basename(sys.argv[0]) + program_version = "v0.8" + program_build_date = "%s" % __updated__ + + program_version_string = '%%prog %s (%s)' % (program_version, program_build_date) + program_longdesc = '''Display or change XRNI comments''' + program_license = "GPL v3+ 2016 Olivier Jolly" + + if argv is None: + argv = sys.argv[1:] + + try: + parser = argparse.ArgumentParser(epilog=program_longdesc, + description=program_license) + parser.add_argument("-d", "--debug", dest="debug", action="store_true", + default=False, + help="debug parsing [default: %(default)s]") + parser.add_argument("-e", "--edit", dest="action", action="store_const", default=ACTION_VIEW, const=ACTION_EDIT, + help="edit comment with standard input content") + parser.add_argument("-r", "--remove", dest="action", action="store_const", const=ACTION_DELETE, + help="remove comment") + parser.add_argument("-v", "--view", dest="action", action="store_const", const=ACTION_VIEW, + help="view comment [default action]") + + parser.add_argument("xrni_filename", help="input file in XRNI format", nargs="+") + + # process options + opts = parser.parse_args(argv) + + except Exception as e: + indent = len(program_name) * " " + sys.stderr.write(program_name + ": " + repr(e) + "\n") + sys.stderr.write(indent + " for help use --help") + return 2 + + if opts.debug: + logging.root.setLevel(logging.DEBUG) + else: + logging.root.setLevel(logging.INFO) + + for xrni_filename in opts.xrni_filename: + renoise_instrument = RenoiseInstrument(xrni_filename) + print(renoise_instrument.comment) + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/setup.py b/setup.py index 9cc1202..9444963 100644 --- a/setup.py +++ b/setup.py @@ -119,6 +119,7 @@ setup( 'sf2toxrni=rnsutils.sf2toxrni:main', 'sfztoxrni=rnsutils.sfztoxrni:main', 'xrnireencode=rnsutils.xrnireencode:main', + 'xrnicomment=rnsutils.xrnicomment:main', ], },