Add xrni tag CLI

master
Olivier Jolly 2016-02-02 12:22:03 +01:00
rodzic c1926d90bc
commit 4874809331
3 zmienionych plików z 143 dodań i 0 usunięć

Wyświetl plik

@ -191,6 +191,39 @@ class RenoiseInstrument(object):
def comment(self):
del self.root.GlobalProperties.Comments
@property
def tags(self):
try:
return self.root.GlobalProperties.Tags.Tag
except AttributeError:
return None
@tags.setter
def tags(self, value):
E = objectify.E
if 'Tags' not in self.root.GlobalProperties.getchildren():
self.root.GlobalProperties.Tags = E.Tags()
self.root.GlobalProperties.Tags.Tag = [E.Tag(tag) for tag in value]
@tags.deleter
def tags(self):
del self.root.GlobalProperties.Tags
def append_tag(self, tag):
tags = self.tags
if tags is None:
self.tags = [tag]
else:
self.root.GlobalProperties.Tags.append(objectify.E.Tag(tag))
def remove_tag(self, tag_to_remove):
for tag_idx in range(len(self.root.GlobalProperties.Tags.getchildren())):
tag = self.root.GlobalProperties.Tags.Tag[tag_idx]
if tag.text == tag_to_remove:
del self.root.GlobalProperties.Tags.Tag[tag_idx]
def cleanup(self):
# ensure that key mapping remains in the limits of what renoise supports
for sample in self.root.SampleGenerator.Samples.Sample:

109
rnsutils/xrnitag.py 100644
Wyświetl plik

@ -0,0 +1,109 @@
# xrnitag. manipulate XRNI tags
# 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 <http://www.gnu.org/licenses/>.
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
ACTION_APPEND = 3
ACTION_CLEAR = 4
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 tags'''
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("-a", "--add", dest="action", action="store_const", const=ACTION_APPEND,
help="add a tag")
parser.add_argument("-c", "--clear", dest="action", action="store_const", const=ACTION_CLEAR,
help="clear all tags")
parser.add_argument("-r", "--remove", dest="action", action="store_const", const=ACTION_DELETE,
help="remove a tag")
parser.add_argument("-v", "--view", dest="action", action="store_const", const=ACTION_VIEW,
help="view all tags [default action]")
parser.add_argument("-t", "--tag", dest="tag",
help="tag name [default reads from standard input]")
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)
if opts.action in (ACTION_DELETE, ACTION_APPEND) and opts.tag is None:
opts.tag = sys.stdin.read()
for xrni_filename in opts.xrni_filename:
renoise_instrument = RenoiseInstrument(xrni_filename)
if opts.action == ACTION_DELETE:
renoise_instrument.remove_tag(opts.tag)
renoise_instrument.save(xrni_filename, overwrite=True)
elif opts.action == ACTION_CLEAR:
del renoise_instrument.tags
renoise_instrument.save(xrni_filename, overwrite=True)
elif opts.action == ACTION_APPEND:
renoise_instrument.append_tag(opts.tag)
renoise_instrument.save(xrni_filename, overwrite=True)
else:
tags = renoise_instrument.tags
if tags:
print("\n".join([str(tag) for tag in tags]))
else:
print("<no tag found>")
return 0
if __name__ == "__main__":
sys.exit(main())

Wyświetl plik

@ -120,6 +120,7 @@ setup(
'sfztoxrni=rnsutils.sfztoxrni:main',
'xrnireencode=rnsutils.xrnireencode:main',
'xrnicomment=rnsutils.xrnicomment:main',
'xrnitag=rnsutils.xrnitag:main',
],
},