Exemplo n.º 1
0
    def convert(self):
        self.status['text'] = '......'
        
        infile = self.infile.get()
        if not infile:
           message = 'No input file(s) selected'
           tkinter.messagebox.showerror("DXconvert-{}".format(PROGRAMVERSION), message)
           self.status['text'] = 'Select file(s) for conversion'
           return
       
        # Workaround for tkFileDialog.askopenfilesnames bug
        # Hopefully one day this will not be needed anymore
        if type(infile) == str:
            master = tkinter.Tk()
            master.withdraw()
            infile = master.tk.splitlist(infile)

        outfile = self.outfile.get()
        if not outfile:
            message = 'No output files selected'
            tkinter.messagebox.showerror("DXconvert-{}".format(PROGRAMVERSION), message)
            self.status['text'] = 'Select file(s) for conversion'
            return
        else:
            outfile_ext = os.path.splitext(outfile)[1]
            outfile_dir = os.path.split(outfile)[0]

        self.status['text'] = 'Reading ...'
        self.update()
        dx7data = []
        dx72data = []
        tx7data = []
        channel=0
        if self.offset.get():
            offset = self.offset.get()
        else:
            offset = '0'

        for inp in infile:
            inp = os.path.normpath(inp)
            if os.path.isfile(inp):

                dx7dat, dx72dat, tx7dat, channel=DXC.read(inp, offset, self.check.get(), self.mid_in, self.mid_out)
                dx7data += dx7dat
                dx72data += dx72dat
                tx7data += tx7dat
                self.status['text'] = 'Read {}'.format(inp)
                self.update()

        if self.channel.get():
            channel = min(15, max(0, int(self.channel.get())-1))

        if self.select.get():
            dx7dat, dx72dat, tx7dat = [], [], []
            for i in dxcommon.range2list(self.select.get()):
                dx7dat += dx7data[128*(i-1):128*i]
                dx72dat += dx72data[35*(i-1):35*i]
                tx7dat += dx7data[64*(i-1):64*i]
            dx7data, dx72data, tx7data = dx7dat, dx72dat, tx7dat

        if self.dxfind.get():
            self.status['text'] = 'Searching names ...'
            self.update()
            dx7data, dx72data, tx7data = DXC.dxfind(dx7data, dx72data, tx7data, self.dxfind.get())

        if self.dxbrightness.get():
            self.status['text'] = 'Adjusting brightness ...'
            self.update()
            dx7data = DXC.dxbrightness(dx7data, int(self.dxbrightness.get()))

        if self.random.get():
            self.status['text'] = "Randomizing voices ..."
            self.update()
            dx7data = dxcommon.dxrandom(dx7data)

        if self.nodupes2.get() == True:
            nodupes2 = True
        else:
            nodupes2 = False

        if (self.nodupes.get() == True) or (self.nodupes2.get() == True):
            self.status['text'] = "Removing duplicates ..."
            self.update()
            dx7data, dx72data, tx7data = DXC.dxnodupes(dx7data, dx72data, tx7data, self.dx72.get(), self.TX7.get(), nodupes2)

        if self.nosilence.get() == True:
            self.status['text'] = "Removing patches with no sound"
            self.updat()
            dx7data, dx72data, txcdata = DXC.nosilence(dx7data, dx72data, tx7data)

        if self.sort.get() == True:
            self.status['text'] = "Sorting voices by name ..."
            self.update()
            dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data, self.dx72.get(), self.TX7.get())
        elif self.sort2.get() == True:
            self.status['text'] = "Sorting voices by name ..."
            self.update()
            dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data, self.dx72.get(), self.TX7.get(), True)
        
        for i in range(len(dx7data)//128):
            if self.bc2at.get() == True:
                dx72data[20+35*i:24+35*i] = dx72data[16+35*i:20+35*i]
            if self.fc1.get() == False:
                dx72data[12+35*i:16+35*i] = [0, 0, 0, 0]
            if self.fc2.get() == False:
                dx72data[26+35*i:30+35*i] = [0, 0, 0, 0]
            if self.bc.get() == False:
                dx72data[16+35*i:20+35*i] = [0, 0, 0, 50]

        if self.split.get() and (len(dx7data)//128 > 1):
            count = 0
            for i in range(len(dx7data)//128):
                outfile_name = dxcommon.list2string(dx7data[128*i+118:128*i+128])
                outfile_name = dxcommon.validfname(outfile_name)
                Outfile = os.path.join(outfile_dir, outfile_name + outfile_ext)
            
                count = 0
                while os.path.exists(Outfile):
                    count += 1
                    if count>1:
                        Outfile = os.path.join(outfile_dir, outfile_name + "(" + str(count) + ")" + outfile_ext)

                DXC.write(outfile_name, dx7data[128*i:128*(i+1)], dx72data[35*i:35*(i+1)], tx7data[64*i:64*(i+1)], self.dx72.get(), self.TX7.get(), channel, self.nosplit.get(), self.mid_out)
            message = "Ready. {} Patches written.".format(len(dx7data)//128)
        else:
            message = DXC.write(outfile, dx7data, dx72data, tx7data, self.dx72.get(), self.TX7.get(), channel, self.nosplit.get(), self.mid_out)

        self.status['text'] = 'Converting ...'
        self.update()

        tkinter.messagebox.showinfo("DXconvert-{}".format(PROGRAMVERSION), message)
        self.status['text'] = 'Select file(s) for conversion'
        self.update()
        return
Exemplo n.º 2
0
    def convert(self):
        self.status['text'] = '......'

        infile = self.infile.get()
        if not infile:
            message = 'No input file(s) selected'
            tkinter.messagebox.showerror("TXconvert-{}".format(PROGRAMVERSION),
                                         message)
            self.status['text'] = 'Select file(s) to import'
            return

        #Workaround for tkFileDialog.askopenfilesnames bug
        #Hopefully one day this will not be needed anymore
        if type(infile) == str:
            master = tkinter.Tk()
            master.withdraw()
            infile = master.tk.splitlist(infile)

        outfile = self.outfile.get()
        if not outfile:
            message = 'No output files selected'
            tkinter.messagebox.showerror("TXconvert-{}".format(PROGRAMVERSION),
                                         message)
            self.status['text'] = 'Select file(s) for conversion'
            return
        else:
            outfile_ext = os.path.splitext(outfile)[1]
            outfile_dir = os.path.split(outfile)[0]

        self.status['text'] = 'Reading ...'
        self.update()
        txdata = []
        channel = 0
        if self.offset.get():
            offset = offset.get()
        else:
            offset = '0'

        FB01 = False
        REFACE = False
        if self.yamaha.get():
            yamaha = self.yamaha.get().lower()
        if yamaha in ('dx100', 'dx27', 'dx27s'):
            split = 24
        elif yamaha in ('ds55', 'ys100', 'ys200', 'tq5', 'b200', 'v50'):
            split = 25
        elif yamaha == 'fb01':
            split = 48
            FB01 = True
        elif yamaha == 'vopm':
            split = 128
            FB01 = True
        elif yamaha == 'refacedx':
            REFACE = True
            split = 1
        else:
            split = 32
        if self.split.get():
            split = 1
        if self.nosplit.get() or (outfile == "MIDI"):
            split = sys.maxsize

        for inp in infile:
            inp = os.path.normpath(inp)
            if os.path.isfile(inp):
                txdat, channel = TXC.read(inp, offset, self.check.get(),
                                          yamaha, self.mid_in, self.mid_out)
                txdata += txdat
                self.status['text'] = 'Read {}'.format(inp)
                self.update()

        if self.channel.get():
            channel = min(15, max(0, int(self.channel.get()) - 1))

        if self.nodupes2.get() == True:
            nodupes2 = True
        else:
            nodupes2 = False

        if self.select.get():
            txdat = []
            for i in dxcommon.range2list(self.select.get()):
                if FB01:
                    txdat += txdata[64 * (i - 1):64 * i]
                elif REFACE:
                    txdat += txdata[150 * (i - 1):150 * i]
                else:
                    txdat += txdata[128 * (i - 1):128 * i]
            txdata = txdat

        if self.txfind.get():
            self.status['text'] = 'Searching names ...'
            self.update()
            if FB01:
                txdata = TXC.fbfind(txdata, self.txfind.get())
            elif REFACE:
                txdata = TXC.rdxfind(txdata, self.txfind.get())
            else:
                txdata = TXC.txfind(txdata, self.txfind.get())

        if self.exclude.get():
            self.status['text'] = 'Excluding names ...'
            self.update()
            if FB01:
                txdata = TXC.exclude(txdata, self.exclude.get())
            elif REFACE:
                txdata = TXC.exclude(txdata, self.exclude.get())
            else:
                txdata = TXC.exclude(txdata, self.exclude.get())

        if self.txbrightness.get():
            self.status['text'] = 'Adjusting brightness ...'
            self.update()
            if FB01:
                txdata = TXC.fbbrightness(txdata, int(self.txbrightness.get()))
            elif REFACE:
                txdata = TXC.rdxbrightness(txdata,
                                           int(self.txbrightness.get()))
            else:
                txdata = TXC.txbrightness(txdata, int(self.txbrightness.get()))

        if self.random.get():
            self.status['text'] = 'Randomizing voices ...'
            self.update()
            if FB01:
                txdata = dxcommon.dxrandom(txdata, 64)
            elif REFACE:
                txdata = dxcommon.dxrandom(txdata, 150)
            else:
                txdata = dxcommon.dxrandom(txdata, 128)

        if self.bc2at.get():
            if (FB01 == False) and (REFACE == False):
                for i in range(len(txdata) // 128):
                    txdata[128 * i + 84:128 * i + 88] = txdata[128 * i +
                                                               53:128 * i + 57]
                    if txdata[128 * i + 86] > 50:
                        txdata[128 * i + 86] -= 51
                    else:
                        txdata[128 * i + 86] += 50

        if self.bc.get() == False:
            if (FB01 == False) and (REFACE == False):
                for i in range(len(txdata) // 128):
                    txdata[128 * i + 53:128 * i + 57] = [0, 0, 50, 0]

        if (self.nodupes.get() == True) or (self.nodupes2.get() == True):
            self.status['text'] = "Removing duplicates ..."
            self.update()
            if FB01:
                txdata = TXC.fbnodupes(txdata, nodupes2)
            elif REFACE:
                txdata = TXC.rdxnodupes(txdata, nodupes2)
            else:
                txdata = TXC.txnodupes(txdata, nodupes2)

        if self.nosilence.get() == True:
            if FB01:
                txdata = TXC.fbnosilence(txdata)
            if REFACE:
                txdata = TXC.rdxnosilence(txdata)
            else:
                txdata = TXC.txnosilence(txdata)

        if self.sort.get() == True:
            self.status['text'] = "Sorting voices by name ..."
            self.update()
            if FB01:
                txdata = TXC.fbsort(txdata)
            elif REFACE:
                txdata = TXC.rdxsort(txdata)
            else:
                txdata = TXC.txsort(txdata)

        elif self.sort2.get() == True:
            self.status['text'] = "Sorting voices by name ..."
            self.update()
            if FB01:
                txdata = TXC.fbsort(txdata, True)
            elif REFACE:
                txdata = TXC.rdxsort(txdata, True)
            else:
                txdata = TXC.txsort(txdata, True)
        if FB01:
            n = len(txdata) // 64
        elif REFACE:
            n = len(txdata) // 150
        else:
            n = len(txdata) // 128
        if (split == 1) and (n > 1):
            if FB01:
                for i in range(len(txdata) // 64):
                    outfile_name = dxcommon.list2string(txdata[64 * i:64 * i +
                                                               7])
                    outfile_name = dxcommon.validfname(outfile_name)
                    Outfile = os.path.join(outfile_dir,
                                           outfile_name + outfile_ext)

                    count = 0
                    while os.path.exists(Outfile):
                        count += 1
                        if count > 1:
                            Outfile = os.path.join(
                                outfile_dir, outfile_name + "(" + str(count) +
                                ")" + outfile_ext)

                    TXC.write(Outfile, txdata[64 * i:64 * (i + 1)], channel,
                              self.nosplit.get(), 1, yamaha, self.mid_out)
                message = "Ready. {} Patches written.".format(
                    len(txdata) // 64)
            elif REFACE:
                for i in range(len(txdata) // 150):
                    outfile_name = dxcommon.list2string(txdata[150 *
                                                               i:150 * i + 10])
                    outfile_name = dxcommon.validfname(outfile_name)
                    Outfile = os.path.join(outfile_dir,
                                           outfile_name + outfile_ext)

                    count = 0
                    while os.path.exists(Outfile):
                        count += 1
                        if count > 1:
                            Outfile = os.path.join(
                                outfile_dir, outfile_name + "(" + str(count) +
                                ")" + outfile_ext)

                    TXC.write(Outfile, txdata[150 * i:150 * (i + 1)], channel,
                              self.nosplit.get(), 1, yamaha, self.mid_out)
                message = "Ready. {} Patches written.".format(
                    len(txdata) // 150)

            else:
                for i in range(len(txdata) // 128):
                    outfile_name = dxcommon.list2string(
                        txdata[128 * i + 57:128 * i + 67])
                    outfile_name = dxcommon.validfname(outfile_name)
                    Outfile = os.path.join(outfile_dir,
                                           outfile_name + outfile_ext)

                    count = 0
                    while os.path.exists(Outfile):
                        count += 1
                        if count > 1:
                            Outfile = os.path.join(
                                outfile_dir, outfile_name + "(" + str(count) +
                                ")" + outfile_ext)

                    TXC.write(Outfile, txdata[128 * i:128 * (i + 1)], channel,
                              self.nosplit.get(), 1, yamaha, self.mid_out)
                message = "Ready. {} Patches written.".format(
                    len(txdata) // 128)
        else:
            message = TXC.write(outfile, txdata, channel, self.nosplit.get(),
                                split, yamaha, self.mid_out)

        self.status['text'] = 'Converting ...'
        self.update()

        tkinter.messagebox.showinfo("TXconvert-{}".format(PROGRAMVERSION),
                                    message)
        self.status['text'] = 'Select file(s) for conversion'
        self.update()
        return
Exemplo n.º 3
0
def cli_main(argv=sys.argv):
    progname = os.path.basename(argv[0])

    parser = ArgumentParser(description='{}\nVersion: {} ({})'.format(
        PROGRAMNAME, PROGRAMVERSION, PROGRAMDATE), )
    parser.add_argument('-b',
                        '--brightness',
                        default=0,
                        type=int,
                        help='Adjust global brightness (+/-)')
    parser.add_argument('-bc',
                        '--breathcontrol',
                        action='store_false',
                        default=True,
                        help='Do NOT use BreathControl')
    parser.add_argument('-bc2at',
                        '--bc2at',
                        action='store_true',
                        default=False,
                        help='Copy BreathControl data to Aftertouch')
    parser.add_argument('-c',
                        '--channel',
                        default=0,
                        type=int,
                        help='Midi channel (1~16)in SysEx header')
    parser.add_argument('-C',
                        '--check',
                        action='store_true',
                        default=False,
                        help='Check SysEx checksum before import')
    parser.add_argument('-f',
                        '--find',
                        metavar='STRING',
                        help='Search for STRING in patchnames')
    if ENABLE_MIDI:
        parser.add_argument(
            '-mi',
            '--mid_in',
            help=
            'select midiport MID_IN to receive data FROM synth when selecting a .req file'
        )
        parser.add_argument(
            '-mo',
            '--mid_out',
            help=
            'select midiport MID_OUT to send data TO synth when choosing "MIDI" as outfile'
        )
        parser.add_argument(
            '-m',
            '--mid',
            help=
            'use this option as a shortcut for "--mid_in MID_IN --mid_out MID_OUT", if MID_IN and MID_OUT have the same name MID'
        )
    parser.add_argument('-n',
                        '--nosplit',
                        action='store_true',
                        default=False,
                        help="Don't split: save data in one file")
    parser.add_argument('-nd',
                        '--nodupes',
                        action='store_true',
                        default=False,
                        help='Remove duplicates')
    parser.add_argument('-nd2',
                        '--nodupes2',
                        action='store_true',
                        default=False,
                        help='Remove duplicates, also with different names')
    parser.add_argument('-ns',
                        '--nosilence',
                        action='store_true',
                        default=False,
                        help='Remove patches that produce no sound')
    parser.add_argument(
        '-o',
        '--offset',
        default='0',
        help="Ignore first/last (+/-) OFFSET bytes in input file(s)")
    parser.add_argument('-r',
                        '--random',
                        action='store_true',
                        default=False,
                        help="easy randomizer")
    parser.add_argument('-sp',
                        '--split',
                        action='store_true',
                        default=False,
                        help="Save each patch in a separate file")
    parser.add_argument('-s',
                        '--select',
                        metavar='RANGE',
                        help='Select patch RANGE to save')
    parser.add_argument('-S',
                        '--sort',
                        action='store_true',
                        default=False,
                        help='Sort patches by name, not case-sensitive')
    parser.add_argument('-S2',
                        '--sort2',
                        action='store_true',
                        default=False,
                        help='Sort patches by name, case-sensitive')
    parser.add_argument('--copy',
                        nargs=2,
                        metavar=('X', 'Y'),
                        help='Copy patch nr X to nr Y')
    parser.add_argument('--swap',
                        nargs=2,
                        metavar=('X', 'Y'),
                        help='Swap patch nr X and nr Y')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='{} ({})'.format(PROGRAMVERSION, PROGRAMDATE))
    parser.add_argument('-x',
                        '--exclude',
                        metavar='STRING',
                        help='Exclude if STRING is found in patchname')
    parser.add_argument('-y',
                        '--yamaha',
                        metavar='MODEL',
                        default='tx81z',
                        help='Specify Yamaha synth MODEL for outfile')
    parser.add_argument('infile', nargs='+', help='Selects input file(s)')
    parser.add_argument('outfile', help='Select output file')

    args = parser.parse_args()
    infilez = args.infile
    infiles = []
    for i in infilez:
        infiles += glob(i)

    outfile = args.outfile
    outfile_ext = os.path.splitext(outfile)[1]
    outfile_dir = os.path.split(outfile)[0]

    mid_in = ""
    mid_out = ""
    if ENABLE_MIDI:
        mid_in = dxcommon.MID_IN
        mid_out = dxcommon.MID_OUT
        CFG = dxcommon.CFG
        if os.getenv('MID_IN'):
            mid_in = os.getenv('MID_IN')
        mid_out = os.getenv('MID_OUT')
        if os.path.exists(CFG):
            with open(CFG, 'r') as f:
                for line in f.readlines():
                    l = line.split('=')
                    if l[0].strip() == 'MID_IN':
                        mid_in = l[1].strip()
                    if l[0].strip() == 'MID_OUT':
                        mid_out = l[1].strip()

        if args.mid:
            mid_in = args.mid
            mid_out = args.mid
        if args.mid_in:
            mid_in = args.mid_in
        if args.mid_out:
            mid_out = args.mid_out
        if args.mid_in or args.mid_out:
            with open(CFG, 'w') as f:
                if mid_in: f.write('MID_IN = {}\n'.format(mid_in))
                if mid_out: f.write('MID_OUT = {}\n'.format(mid_out))

    bc = args.breathcontrol
    bc2at = args.bc2at
    brightness = args.brightness
    nosplit = args.nosplit
    ch = args.channel
    check = args.check
    select = args.select
    sort = args.sort
    sort2 = args.sort2
    swap = args.swap
    copy = args.copy
    nodupes = args.nodupes
    nodupes2 = args.nodupes2
    nosilence = args.nosilence
    offset = args.offset
    Random = args.random
    find = args.find
    exclude = args.exclude
    yamaha = args.yamaha.lower().strip()

    FB01 = False
    REFACE = False
    if yamaha in ('ys100', 'ys200', 'tq5', 'b200', 'ds55', 'v50'):
        split = 25
    elif yamaha in ('dx27', 'dx27s', 'dx100'):
        split = 24
    elif yamaha == 'fb01' or outfile_ext.lower() == '.fb1':
        yamaha = 'fb01'
        FB01 = True
        split = 48
    elif yamaha in ('opm', 'vopm') or outfile_ext.lower() == '.opm':
        yamaha = 'vopm'
        FB01 = True
        split = 128
    elif yamaha in ('reface', 'dxreface', 'refacedx'):
        yamaha = 'refacedx'
        REFACE = True
        split = 1
    else:
        split = 32

    if args.split:
        split = 1

    if nosplit or (outfile == "MIDI") or (outfile == os.devnull):
        split = sys.maxsize
        nosplit = True

    txdata = []
    for infile in infiles:
        print("Reading {}".format(infile))
        if not os.path.exists(infile):
            print("{} not found".format(infile))
            return 1
        if infile == outfile:
            print("Must have different input and output files")
            return 1

        if os.path.isfile(infile):
            txdat, channel = TXC.read(infile, offset, check, yamaha, mid_in,
                                      mid_out)
            txdata += txdat

    if ch != None:
        channel = ch - 1
        channel = max(0, channel)
        channel = min(15, channel)

    if nodupes2:
        nodupes = True

    if nodupes or nodupes2:
        if FB01:
            txdata = TXC.fbnodupes(txdata, nodupes2)
        elif REFACE:
            txdata = TXC.rdxnodupes(txdata, nodupes2)
        else:
            txdata = TXC.txnodupes(txdata, nodupes2)

    if nosilence:
        if FB01:
            txdata = TXC.fbnosilence(txdata)
        elif REFACE:
            txdata = TXC.rdxnosilence(txdata)
        else:
            txdata = TXC.txnosilence(txdata)

    if select != None:
        txdat = []
        for i in dxcommon.range2list(select):
            if FB01:
                txdat += txdata[64 * (i - 1):64 * i]
            elif REFACE:
                txdat += txdata[150 * (i - 1):150 * i]
            else:
                txdat += txdata[128 * (i - 1):128 * i]
        txdata = txdat

    if args.find != None:
        if FB01:
            txdata = TXC.fbfind(txdata, find)
        elif REFACE:
            txdata = TXC.rdxfind(txdata, find)
        else:
            txdata = TXC.txfind(txdata, find)

    if args.exclude:
        if FB01:
            txdata = TXC.fbexclude(txdata, exclude)
        elif REFACE:
            txdata = TXC.rdxexclude(txdata, exclude)
        else:
            txdata = TXC.txexclude(txdata, exclude)

    if brightness:
        if FB01:
            txdata = TXC.fbbrightness(txdata, brightness)
        elif REFACE:
            txdata = TXC.rdxbrightness(txdata, brightness)
        else:
            txdata = TXC.txbrightness(txdata, brightness)

    if bc2at:
        if (FB01 == False) and (REFACE == False):
            for i in range(len(txdata) // 128):
                txdata[128 * i + 84:128 * i + 88] = txdata[128 * i +
                                                           53:128 * i + 57]
                if txdata[128 * i + 86] > 50:
                    txdata[128 * i + 86] -= 51
                else:
                    txdata[128 * i + 86] += 50

    if bc == False:
        if (FB01 == False) and (REFACE == False):
            for i in range(len(txdata) // 128):
                txdata[128 * i + 53:128 * i + 57] = [0, 0, 50, 0]

    if Random:
        if FB01:
            txdata = dxcommon.dxrandom(txdata, 64)
        elif REFACE:
            txdata = dxcommon.dxrandom(txdata, 150)
        else:
            txdata = dxcommon.dxrandom(txdata, 128)

    if sort:
        if FB01:
            txdata = TXC.fbsort(txdata, False)
        elif REFACE:
            txdata = TXC.rdxsort(txdata, False)
        else:
            txdata = TXC.txsort(txdata, False)

    if sort2:
        if FB01:
            txdata = TXC.fbsort(txdata, True)
        elif REFACE:
            txdata = TXC.rdxsort(txdata, True)
        else:
            txdata = TXC.txsort(txdata, False)

    if copy:
        if FB01:
            txdata = TXC.txcopy(dxcommon.range2list(copy[0]), int(copy[1]),
                                txdata, 64)
        elif REFACE:
            txdata = TXC.txcopy(dxcommon.range2list(copy[0]), int(copy[1]),
                                txdata, 150)
        else:
            txdata = TXC.txcopy(dxcommon.range2list(copy[0]), int(copy[1]),
                                txdata, 128)

    if swap:
        if FB01:
            txdata = TXC.txswap(int(swap[0]), int(swap[1]), txdata, 64)
        elif REFACE:
            txdata = TXC.txswap(int(swap[0]), int(swap[1]), txdata, 150)
        else:
            txdata = TXC.txswap(int(swap[0]), int(swap[1]), txdata, 128)

    if FB01:
        n = len(txdata) // 64
    elif REFACE:
        n = len(txdata) // 150
    else:
        n = len(txdata) // 128

    if (split == 1) and (n > 1):
        if FB01:
            for i in range(n):
                outfile_name = dxcommon.list2string(txdata[64 * i:64 * i + 7])
                outfile_name = dxcommon.validfname(outfile_name)
                Outfile = os.path.join(outfile_dir, outfile_name + outfile_ext)

                count = 0
                while os.path.exists(Outfile):
                    count += 1
                    if count > 1:
                        Outfile = os.path.join(
                            outfile_dir, outfile_name + "(" + str(count) +
                            ")" + outfile_ext)

                print(
                    TXC.write(Outfile, txdata[64 * i:64 * (i + 1)], channel,
                              nosplit, 1, yamaha, mid_out))
        elif REFACE:
            for i in range(n):
                outfile_name = dxcommon.list2string(txdata[150 * i:150 * i +
                                                           10])
                outfile_name = dxcommon.validfname(outfile_name)
                Outfile = os.path.join(outfile_dir, outfile_name + outfile_ext)

                count = 0
                while os.path.exists(Outfile):
                    count += 1
                    if count > 1:
                        Outfile = os.path.join(
                            outfile_dir, outfile_name + "(" + str(count) +
                            ")" + outfile_ext)

                print(
                    TXC.write(Outfile, txdata[150 * i:150 * (i + 1)], channel,
                              nosplit, 1, yamaha, mid_out))
        else:
            for i in range(n):
                outfile_name = dxcommon.list2string(txdata[128 * i +
                                                           57:128 * i + 67])
                outfile_name = dxcommon.validfname(outfile_name)
                Outfile = os.path.join(outfile_dir, outfile_name + outfile_ext)

                count = 0
                while os.path.exists(Outfile):
                    count += 1
                    if count > 1:
                        Outfile = os.path.join(
                            outfile_dir, outfile_name + "(" + str(count) +
                            ")" + outfile_ext)

                print(
                    TXC.write(Outfile, txdata[128 * i:128 * (i + 1)], channel,
                              nosplit, 1, yamaha, mid_out))
    else:
        print(
            TXC.write(outfile, txdata, channel, nosplit, split, yamaha,
                      mid_out))

    return 0
Exemplo n.º 4
0
    def convert(self):
        self.status['text'] = '......'

        inpath = self.inpath.get()
        if not inpath:
            message = 'No input file(s) selected'
            tkinter.messagebox.showerror("DXconvert-{}".format(PROGRAMVERSION),
                                         message)
            self.status['text'] = 'Select file(s) for conversion'
            return

        # Workaround for tkFileDialog.askopenfilesnames bug
        # Hopefully one day this will not be needed anymore
        if type(inpath) == str:
            master = tkinter.Tk()
            master.withdraw()
            inpath = master.tk.splitlist(inpath)

        outpath = self.outpath.get()
        if not outpath:
            message = 'No output files selected'
            tkinter.messagebox.showerror("DXconvert-{}".format(PROGRAMVERSION),
                                         message)
            self.status['text'] = 'Select file(s) for conversion'
            return

        self.status['text'] = 'Reading ...'
        self.update()
        dx7data = []
        dx72data = []
        tx7data = []
        offset = 0
        channel = 0
        if self.offset.get():
            offset = max(0, int(self.offset.get()))

        for inp in inpath:
            inp = os.path.normpath(inp)
            if os.path.isfile(inp):

                if os.path.getsize(inp) > MAXFILESIZE:
                    if MAXFILESIZE != 0:
                        self.status[
                            'text'] = "Warning: only {} bytes will be read".format(
                                MAXFILESIZE)

                dx7dat, dx72dat, tx7dat, channel = DXC.read(
                    inp, offset, self.check.get, self.mid_in, self.mid_out)
                dx7data += dx7dat
                dx72data += dx72dat
                tx7data += tx7dat
                self.status['text'] = 'Read {}'.format(inp)
                self.update()

        if self.channel.get():
            channel = min(15, max(0, int(self.channel.get()) - 1))

        if self.select.get():
            dx7dat, dx72dat, tx7dat = [], [], []
            for i in dxcommon.range2list(self.select.get()):
                dx7dat += dx7data[128 * (i - 1):128 * i]
                dx72dat += dx72data[35 * (i - 1):35 * i]
                tx7dat += dx7data[64 * (i - 1):64 * i]
            dx7data, dx72data, tx7data = dx7dat, dx72dat, tx7dat

        if self.dxfind.get():
            self.status['text'] = 'Searching names ...'
            self.update()
            dx7data, dx72data, tx7data = DXC.dxfind(dx7data, dx72data, tx7data,
                                                    self.dxfind.get())

        if self.random.get():
            self.status['text'] = "Randomizing voices ..."
            self.update()
            deviation = max(0, min(300, int(self.random.get())))
            dx7data = DXC.dxrandom(dx7data, deviation)

        if self.nodupes2.get() == True:
            nodupes2 = True
        else:
            nodupes2 = False

        if (self.nodupes.get() == True) or (self.nodupes2.get() == True):
            self.status['text'] = "Removing duplicates ..."
            self.update()
            dx7data, dx72data, tx7data = DXC.dxnodupes(dx7data,
                                                       dx72data, tx7data,
                                                       self.dx72.get(),
                                                       self.TX7.get(),
                                                       nodupes2)

        if self.sort.get() == True:
            self.status['text'] = "Sorting voices by name ..."
            self.update()
            dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data,
                                                    self.dx72.get(),
                                                    self.TX7.get())

        for i in range(len(dx7data) // 128):
            if self.bc2at.get() == True:
                dx72data[20 + 35 * i:24 + 35 * i] = dx72data[16 + 35 * i:20 +
                                                             35 * i]
            if self.fc1.get() == False:
                dx72data[12 + 35 * i:16 + 35 * i] = [0, 0, 0, 0]
            if self.fc2.get() == False:
                dx72data[26 + 35 * i:30 + 35 * i] = [0, 0, 0, 0]
            if self.bc.get() == False:
                dx72data[16 + 35 * i:20 + 35 * i] = [0, 0, 0, 50]

        if self.split.get() == True:
            count = 0
            for i in range(len(dx7data) // 128):
                outfile_name = dxcommon.list2string(dx7data[128 * i +
                                                            118:128 * i + 128])
                for j in range(len(outfile_name)):
                    if not outfile_name[j] in ALLOWED_CHARACTERS:
                        outfile_name = outfile_name[:j] + "_" + outfile_name[
                            j + 1:]
                Outfile_Name = outfile_name
                while os.path.exists(Outfile_Name + outpath):
                    count += 1
                    if count > 1:
                        Outfile_Name = outfile_name + "(" + str(count) + ")"

                outfile_name = os.path.join(
                    os.path.split(outpath)[0],
                    Outfile_Name + os.path.split(outpath)[1])

                DXC.write(outfile_name, dx7data[128 * i:128 * (i + 1)],
                          dx72data[35 * i:35 * (i + 1)],
                          tx7data[64 * i:64 * (i + 1)], self.dx72.get(),
                          self.TX7.get(), channel, self.nosplit.get(),
                          self.mid_out)
            message = "Ready. {} Patches written.".format(len(dx7data) // 128)
        else:
            message = DXC.write(outpath, dx7data, dx72data, tx7data,
                                self.dx72.get(), self.TX7.get(), channel,
                                self.nosplit.get(), self.mid_out)

        self.status['text'] = 'Converting ...'
        self.update()

        tkinter.messagebox.showinfo("DXconvert-{}".format(PROGRAMVERSION),
                                    message)
        self.status['text'] = 'Select file(s) for conversion'
        self.update()
        return
Exemplo n.º 5
0
def cli_main(argv=sys.argv):
    progname = os.path.basename(argv[0])

    parser = ArgumentParser(description='{}\nVersion: {} ({})'.format(
        PROGRAMNAME, PROGRAMVERSION, PROGRAMDATE))
    parser.add_argument('-bc2at',
                        '--bc2at',
                        action='store_true',
                        default=False,
                        help='Copy BreathControl data to AfterTouch')
    parser.add_argument('-bc',
                        '--nobreathcontrol',
                        action="store_false",
                        default=True,
                        help='Do NOT use BreathControl data')
    parser.add_argument('-b',
                        '--brightness',
                        default=0,
                        type=int,
                        help='Adjust global brightness (+/-)')
    parser.add_argument('-c',
                        '--channel',
                        default=0,
                        type=int,
                        help='Midi channel (1~16) in SysEx header')
    parser.add_argument('-C',
                        '--check',
                        action='store_true',
                        default=False,
                        help='Check SysEx checksum before import')
    parser.add_argument('-d',
                        '--dx72',
                        action='store_true',
                        default=False,
                        help='Save with AMEM/ACED (DX7II) data')
    parser.add_argument('-f',
                        '--find',
                        metavar='STRING',
                        help='Search for STRING in patchnames')
    parser.add_argument('-fc1',
                        '--fc1',
                        action='store_false',
                        default=True,
                        help='Do NOT use FC1 foot controller data')
    parser.add_argument('-fc2',
                        '--fc2',
                        action='store_false',
                        default=True,
                        help='Do NOT use FC2 foot controller data')
    if ENABLE_MIDI:
        parser.add_argument(
            '-mi',
            '--mid_in',
            help=
            'select midiport MID_IN to receive data FROM synth when selecting a .req file'
        )
        parser.add_argument(
            '-mo',
            '--mid_out',
            help=
            'select midiport MID_OUT to send data TO synth when choosing "MIDI" as outfile'
        )
        parser.add_argument(
            '-m',
            '--mid',
            help=
            'use this option as a shortcut for "--mid_in MID_IN --mid_out MID_OUT", if MID_IN and MID_OUT have the same name MID'
        )
    parser.add_argument('-n',
                        '--nosplit',
                        action='store_true',
                        default=False,
                        help="Don't split: save data in one file")
    parser.add_argument('-nd',
                        '--nodupes',
                        action='store_true',
                        default=False,
                        help='Remove duplicates')
    parser.add_argument('-nd2',
                        '--nodupes2',
                        action='store_true',
                        default=False,
                        help='Remove duplicates, also with different names')
    parser.add_argument('-ns',
                        '--nosilence',
                        action='store_true',
                        default=False,
                        help='Remove patches that produce no sound')
    parser.add_argument(
        '-o',
        '--offset',
        default='0',
        help="Ignore first/last (+/-) OFFSET bytes in input file(s)")
    parser.add_argument('-r',
                        '--random',
                        action='store_true',
                        default=False,
                        help="Renata's Randomizer")
    parser.add_argument('-sp',
                        '--split',
                        action='store_true',
                        help="save each single patch as a separate file")
    parser.add_argument('-s',
                        '--select',
                        metavar='RANGE',
                        help='Select RANGE to save')
    parser.add_argument('-S',
                        '--sort',
                        action='store_true',
                        default=False,
                        help='Sort patches by name, not case-sensitive')
    parser.add_argument('-S2',
                        '--sort2',
                        action='store_true',
                        default=False,
                        help='Sort patches by name, case-sensitive')
    parser.add_argument('--copy',
                        nargs=2,
                        metavar=('X', 'Y'),
                        help='Copy patch nr X to nr Y')
    parser.add_argument('--swap',
                        nargs=2,
                        metavar=('X', 'Y'),
                        help='Swap patch nr X and nr Y')
    parser.add_argument('--view',
                        action='store_true',
                        default=False,
                        help='Print patchnames to stdout')
    parser.add_argument('-t',
                        '--tx7',
                        action='store_true',
                        default=False,
                        help='Save with TX7 Performance data')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='{} ({})'.format(PROGRAMVERSION, PROGRAMDATE))
    parser.add_argument('-x',
                        '--exclude',
                        metavar='STRING',
                        help='Exclude if STRING is found in patchname')
    parser.add_argument('infile', nargs='+', help='Selects input file(s)')
    parser.add_argument('outfile', help='Select output file')

    args = parser.parse_args()
    infilez = args.infile
    infiles = []
    for i in infilez:
        infiles += glob(i)

    outfile = args.outfile
    outfile_ext = os.path.splitext(outfile)[1]
    outfile_dir = os.path.split(outfile)[0]

    mid_in = ""
    mid_out = ""
    if ENABLE_MIDI:
        mid_in = dxcommon.MID_IN
        mid_out = dxcommon.MID_OUT
        CFG = dxcommon.CFG
        if os.getenv('MID_IN'):
            mid_in = os.getenv('MID_IN')
        mid_out = os.getenv('MID_OUT')
        if os.path.exists(CFG):
            with open(CFG, 'r') as f:
                for line in f.readlines():
                    l = line.split('=')
                    if l[0].strip() == 'MID_IN':
                        mid_in = l[1].strip()
                    if l[0].strip() == 'MID_OUT':
                        mid_out = l[1].strip()
        if args.mid:
            mid_in = args.mid
            mid_out = args.mid
        if args.mid_in:
            mid_in = args.mid_in
        if args.mid_out:
            mid_out = args.mid_out
        if args.mid_in or args.mid_out:
            with open(CFG, 'w') as f:
                if mid_in:
                    f.write('MID_IN = {}\n'.format(mid_in))
                if mid_out:
                    f.write('MID_OUT = {}\n'.format(mid_out))

    brightness = args.brightness
    dx72 = args.dx72
    TX7 = args.tx7
    nosplit = args.nosplit
    ch = args.channel
    check = args.check
    select = args.select
    sort = args.sort
    sort2 = args.sort2
    split = args.split
    swap = args.swap
    copy = args.copy
    nodupes = args.nodupes
    nodupes2 = args.nodupes2
    nosilence = args.nosilence
    offset = args.offset
    bc2at = args.bc2at
    bc = args.nobreathcontrol
    fc1 = args.fc1
    fc2 = args.fc2
    Random = args.random
    find = args.find
    exclude = args.exclude
    view = args.view

    dx7data, tx7data, dx72data = [], [], []
    for infile in infiles:
        print("Reading {}".format(infile))
        if not os.path.exists(infile):
            print("{} not found".format(infile))
            return 1
        if infile == outfile:
            print("Must have different input and output files")
            return 1

        if os.path.isfile(infile):
            dx7dat, dx72dat, tx7dat, channel = DXC.read(
                infile, offset, check, mid_in, mid_out)
            dx7data += dx7dat
            dx72data += dx72dat
            tx7data += tx7dat

    if ch != None:
        channel = ch - 1
        channel = max(0, channel)
        channel = min(15, channel)

    if select != None:
        dx7dat, dx72dat, tx7dat = [], [], []
        for i in dxcommon.range2list(select):
            dx7dat += dx7data[128 * (i - 1):128 * i]
            dx72dat += dx72data[35 * (i - 1):35 * i]
            tx7dat += tx7data[64 * (i - 1):64 * i]
        dx7data, dx72data, tx7data = dx7dat, dx72dat, tx7dat

    if args.find != None:
        dx7data, dx72data, tx7data = DXC.dxfind(dx7data, dx72data, tx7data,
                                                find)

    if args.exclude:
        dx7data, dx72data, tx7data = DXC.dxexclude(dx7data, dx72data, tx7data,
                                                   exclude)

    if brightness:
        dx7data = DXC.dxbrightness(dx7data, brightness)

    if Random:
        dx7data = dxcommon.dxrandom(dx7data)

    if nodupes2:
        nodupes = True

    if nodupes or nodupes2:
        dx7data, dx72data, tx7data = DXC.dxnodupes(dx7data, dx72data, tx7data,
                                                   dx72, TX7, nodupes2)

    if nosilence:
        dx7data, dx72data, tx7data = DXC.dxnosilence(dx7data, dx72data,
                                                     tx7data)

    if sort:
        dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data,
                                                dx72, TX7, False)
    if sort2:
        dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data,
                                                dx72, TX7, True)

    if copy:
        dx7data, dx72data, tx7data = DXC.dxcopy(dxcommon.range2list(copy[0]),
                                                int(copy[1]), dx7data,
                                                dx72data, tx7data)

    if swap:
        dx7data, dx72data, tx7data = DXC.dxswap(int(swap[0]), int(swap[1]),
                                                dx7data, dx72data, tx7data)

    if view:
        DXC.dxview(dx7data)

    for i in range(len(dx7data) // 128):
        if bc2at:
            dx72data[20 + 35 * i:24 + 35 * i] = dx72data[16 + 35 * i:20 +
                                                         35 * i]
        if fc1 == False:
            dx72data[12 + 35 * i:16 + 35 * i] = [0, 0, 0, 0]
        if fc2 == False:
            dx72data[26 + 35 * i:30 + 35 * i] = [0, 0, 0, 0]
        if bc == False:
            dx72data[16 + 35 * i:20 + 35 * i] = [0, 0, 0, 50]

    if split and (len(dx7data) // 128 > 1):
        for i in range(len(dx7data) // 128):
            outfile_name = dxcommon.list2string(dx7data[128 * i + 118:128 * i +
                                                        128])
            outfile_name = dxcommon.validfname(outfile_name)
            Outfile = os.path.join(outfile_dir, outfile_name + outfile_ext)

            count = 0
            while os.path.exists(Outfile):
                count += 1
                if count > 1:
                    Outfile = os.path.join(
                        outfile_dir,
                        outfile_name + "(" + str(count) + ")" + outfile_ext)

            print(
                DXC.write(Outfile, dx7data[128 * i:128 * (i + 1)],
                          dx72data[35 * i:35 * (i + 1)],
                          tx7data[64 * i:64 * (i + 1)], dx72, TX7, channel,
                          nosplit, mid_out))

    else:
        print(
            DXC.write(outfile, dx7data, dx72data, tx7data, dx72, TX7, channel,
                      nosplit, mid_out))

    return 0
Exemplo n.º 6
0
    def convert(self):
        self.status['text'] = '......'

        inpath = self.inpath.get()
        if not inpath:
            message = 'No input file(s) selected'
            tkinter.messagebox.showerror("TXconvert-{}".format(PROGRAMVERSION),
                                         message)
            self.status['text'] = 'Select file(s) for conversion'
            return

        # Workaround for tkFileDialog.askopenfilesnames bug
        # Hopefully one day this will not be needed anymore
        if type(inpath) == str:
            master = tkinter.Tk()
            master.withdraw()
            inpath = master.tk.splitlist(inpath)

        outpath = self.outpath.get()
        if not outpath:
            message = 'No output files selected'
            tkinter.messagebox.showerror("TXconvert-{}".format(PROGRAMVERSION),
                                         message)
            self.status['text'] = 'Select file(s) for conversion'
            return

        self.status['text'] = 'Reading ...'
        self.update()
        txdata = []
        offset = 0
        channel = 0

        if self.offset.get():
            offset = max(0, int(self.offset.get()))

        FB01 = False
        if self.yamaha.get():
            yamaha = self.yamaha.get().lower()
        if yamaha in ('dx100', 'dx27', 'dx27s'):
            split = 24
        elif yamaha in ('ds55', 'ys100', 'ys200', 'tq5', 'b200', 'v50'):
            split = 25
        elif yamaha == 'fb01':
            split = 48
            FB01 = True
        elif yamaha == 'vopm':
            split == 128
            FB01 = True
        else:
            split = 32

        for inp in inpath:
            inp = os.path.normpath(inp)
            if os.path.isfile(inp):

                if os.path.getsize(inp) > MAXFILESIZE:
                    if MAXFILESIZE != 0:
                        self.status[
                            'text'] = "Warning: only {} bytes will be read".format(
                                MAXFILESIZE)

                txdat, channel = TXC.read(inp, offset, self.check.get(),
                                          yamaha, self.mid_in, self.mid_out)
                txdata += txdat
                self.status['text'] = 'Read {}'.format(inp)
                self.update()

        if self.channel.get():
            channel = min(15, max(0, int(self.channel.get()) - 1))

        if self.nodupes2.get() == True:
            nodupes2 = True
        else:
            nodupes2 = False

        if self.select.get():
            txdat = []
            for i in dxcommon.range2list(self.select.get()):
                if FB01:
                    txdat += txdata[64 * (i - 1):64 * i]
                else:
                    txdat += txdata[128 * (i - 1):128 * i]
            txdata = txdat

        if self.txfind.get():
            self.status['text'] = 'Searching names ...'
            self.update()
            if FB01:
                txdata = TXC.fbfind(txdata, self.txfind.get())
            else:
                txdata = TXC.txfind(txdata, self.txfind.get())

        if self.random.get():
            self.status['text'] = "Randomizing voices ..."
            self.update()
            deviation = max(0, min(300, int(self.random.get())))
            if FB01:
                txdata = TXC.fbrandom(txdata, deviation)
            else:
                txdata = TXC.txrandom(txdata, deviation)

        if (self.nodupes.get() == True) or (self.nodupes2.get() == True):
            self.status['text'] = "Removing duplicates ..."
            self.update()
            if FB01:
                txdata = TXC.fbnodupes(txdata, nodupes2)
            else:
                txdata = TXC.txnodupes(txdata, nodupes2)

        if self.sort.get() == True:
            self.status['text'] = "Sorting voices by name ..."
            self.update()
            if FB01:
                txdata = TXC.fbsort(txdata)
            else:
                txdata = TXC.txsort(txdata)

        if self.split.get() == True:
            if FB01:
                count = 0
                for i in range(len(txdata) // 64):
                    outfile_name = dxcommon.list2string(txdata[64 * i:64 * i +
                                                               7])
                    for j in range(len(outfile_name)):
                        if not outfile_name[j] in ALLOWED_CHARACTERS:
                            outfile_name = outfile_name[:
                                                        j] + "_" + outfile_name[
                                                            j + 1:]
                    Outfile_Name = outfile_name
                    while os.path.exists(Outfile_Name + outpath):
                        count += 1
                        if count > 1:
                            Outfile_Name = outfile_name + "(" + str(
                                count) + ")"

                    outfile_name = os.path.join(
                        os.path.split(outpath)[0],
                        Outfile_Name + os.path.split(outpath)[1])
                    TXC.write(outfile_name,
                              txdata[64 * i:64 * (i + 1)], channel,
                              self.nosplit.get(), 1, yamaha, self.mid_out)
                message = "Ready. {} Patches written.".format(
                    len(txdata) // 128)
            else:
                count = 0
                for i in range(len(txdata) // 128):
                    outfile_name = dxcommon.list2string(
                        txdata[128 * i + 57:128 * i + 67])
                    for j in range(len(outfile_name)):
                        if not outfile_name[j] in ALLOWED_CHARACTERS:
                            outfile_name = outfile_name[:
                                                        j] + "_" + outfile_name[
                                                            j + 1:]
                    Outfile_Name = outfile_name
                    while os.path.exists(Outfile_Name + outpath):
                        count += 1
                        if count > 1:
                            Outfile_Name = outfile_name + "(" + str(
                                count) + ")"

                    outfile_name = os.path.join(
                        os.path.split(outpath)[0],
                        Outfile_Name + os.path.split(outpath)[1])
                    TXC.write(outfile_name,
                              txdata[128 * i:128 * (i + 1)], channel,
                              self.nosplit.get(), 1, yamaha, self.mid_out)
                message = "Ready. {} Patches written.".format(
                    len(txdata) // 128)
        else:
            message = TXC.write(outpath, txdata, channel, self.nosplit.get(),
                                split, yamaha, self.mid_out)

        self.status['text'] = 'Converting ...'
        self.update()

        tkinter.messagebox.showinfo("TXconvert-{}".format(PROGRAMVERSION),
                                    message)
        self.status['text'] = 'Select file(s) for conversion'
        self.update()
        return
Exemplo n.º 7
0
def cli_main(argv=sys.argv):
    progname=os.path.basename(argv[0])

    parser=ArgumentParser(
            description='{}\nVersion: {} ({})'.format(PROGRAMNAME, PROGRAMVERSION, PROGRAMDATE), )
    parser.add_argument('-bc2at', '--bc2at', action='store_true', default=False, help='Copy BreathControl data to AfterTouch')
    parser.add_argument('-bc', '--bc', action='store_true', default=False, help='Use Breath Controller data')
    parser.add_argument('-c', '--channel', default=0, type=int, help='Midi channel in SysEx header')
    parser.add_argument('-C', '--check', action='store_true', default=False, help='Check SysEx checksum before import') 
    parser.add_argument('-d', '--dx72', action='store_true', default=False, help='Save with AMEM/ACED (DX7II) data')
    parser.add_argument('-f', '--find', metavar='STRING', help='Search for STRING in patchnames')
    parser.add_argument('-fc1', '--fc1', action='store_true', default=False, help='Use FC1 foot controller data')
    parser.add_argument('-fc2', '--fc2', action='store_true', default=False, help='Use FC2 foot controller data')
    parser.add_argument('-mi', '--mid_in', help='select midiport MID_IN to receive data FROM synth when selecting a .req file')
    parser.add_argument('-mo', '--mid_out', help='select midiport MID_OUT to send data TO synth when choosing "MIDI" as outfile')
    parser.add_argument('-m', '--mid', help='use this option as a shortcut for "--mid_in MID_IN --mid_out MID_OUT", if MID_IN and MID_OUT have the same name MID')
    parser.add_argument('-n', '--nosplit', action='store_true', default=False, help="Don't split: save data in one file")
    parser.add_argument('-nd', '--nodupes', action='store_true', default=False, help='Remove duplicates')
    parser.add_argument('-nd2', '--nodupes2', action='store_true', default=False, help='Remove duplicates, also with different names')
    parser.add_argument('-o', '--offset', type=int, default=0, help="Ignore first OFFSET bytes in input file(s)")
    parser.add_argument('-r', '--random', metavar='NUMBER', type=int, default=-1, help="Randomize, NUMBER = a value between 0 and 300") 
    parser.add_argument('-R', '--Renata', action='store_true', default=False, help="Renata's Randomizer (same as --random=0") 
    parser.add_argument('-sp', '--split', action='store_true', help="save each single patch as a separate file")
    parser.add_argument('-s', '--select', metavar='RANGE', help='Select RANGE to save')
    parser.add_argument('-S', '--sort', action='store_true', default=False, help='Sort patches by name, not case-sensitive')
    parser.add_argument('-S2', '--sort2', action='store_true', default=False, help='Sort patches by name, case-sensitive')
    parser.add_argument('--copy', nargs=2, metavar=('X', 'Y'), help='Copy patch nr X to nr Y')
    parser.add_argument('--swap', nargs=2, metavar=('X', 'Y'), help='Swap patch nr X and nr Y')
    parser.add_argument('-t', '--tx7', action='store_true', default=False, help='Save with TX7 Performance data')
    parser.add_argument('-v', '--version', action='version', version='{} ({})'.format(PROGRAMVERSION, PROGRAMDATE))
    parser.add_argument('infile', nargs='+', help='Selects input file(s)')
    parser.add_argument('outfile', help='Select output file')

    args=parser.parse_args()
    infilez = args.infile
    infiles = []
    for i in infilez:
        infiles += glob(i)
    outfile = args.outfile

    mid_in = dxcommon.MID_IN
    mid_out = dxcommon.MID_OUT
    CFG = dxcommon.CFG
    if os.getenv('MID_IN'):
        mid_in = os.getenv('MID_IN')
    mid_out = os.getenv('MID_OUT')
    if os.path.exists(CFG):
        with open(CFG, 'r') as f:
            for line in f.readlines():
                l = line.split('=')
                if l[0].strip() == 'MID_IN':
                    mid_in = l[1].strip()
                if l[0].strip() == 'MID_OUT':
                    mid_out = l[1].strip()
    if args.mid:
        mid_in = args.mid
        mid_out =  args.mid
    if args.mid_in:
        mid_in = args.mid_in
    if args.mid_out:
        mid_out = args.mid_out
    if args.mid_in or args.mid_out:
        with open(CFG, 'w') as f:
            if mid_in: f.write('MID_IN = {}\n'.format(mid_in))
            if mid_out: f.write('MID_OUT = {}\n'.format(mid_out))

    dx72 = args.dx72
    TX7 = args.tx7
    nosplit = args.nosplit
    ch = args.channel
    check = args.check
    select = args.select
    sort = args.sort
    sort2 = args.sort2
    split = args.split
    swap = args.swap
    copy = args.copy
    nodupes = args.nodupes
    nodupes2 = args.nodupes2
    offset = args.offset
    bc2at = args.bc2at
    bc = args.bc
    fc1 = args.fc1
    fc2 = args.fc2
    deviation = max(-1, min(300, args.random))
    if args.Renata:
        deviation = 0
    find = args.find


    dx7data, tx7data, dx72data = [], [], []
    for infile in infiles:
        print("Reading {}".format(infile))
        if not os.path.exists(infile):
            print("{} not found".format(infile))
            return 1
        if os.path.getsize(infile)>MAXFILESIZE:
            if MAXFILESIZE != 0:
                print("Warning: File too large.\nOnly {} bytes will be read".format(MAXFILESIZE))
        if infile == outfile:
            print("Must have different input and output files")
            return 1

        if os.path.isfile(infile):
            dx7dat, dx72dat, tx7dat, channel = DXC.read(infile, offset, check, mid_in, mid_out)
            dx7data += dx7dat
            dx72data += dx72dat
            tx7data += tx7dat

    if ch != None:
        channel = ch-1
        channel = max(0, channel)
        channel = min(15, channel)

    if select != None:
        dx7dat, dx72dat, tx7dat = [], [], []
        for i in dxcommon.range2list(select):
            dx7dat += dx7data[128*(i-1): 128*i]
            dx72dat += dx72data[35*(i-1): 35*i]
            tx7dat += tx7data[64*(i-1): 64*i]
        dx7data, dx72data, tx7data = dx7dat, dx72dat, tx7dat
    
    if args.find != None:
        dx7data, dx72data, tx7data = DXC.dxfind(dx7data, dx72data, tx7data, find)

    if deviation != -1:
        dx7data = DXC.dxrandom(dx7data, deviation)

    if nodupes2:
        nodupes = True
            
    if nodupes or nodupes2:
        dx7data, dx72data, tx7data = DXC.dxnodupes(dx7data, dx72data, tx7data, dx72, TX7, nodupes2)
    
    if sort:
        dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data, dx72, TX7, False)
    if sort2:
        dx7data, dx72data, tx7data = DXC.dxsort(dx7data, dx72data, tx7data, dx72, TX7, True)
    
    if copy:
        dx7data, dx72data, tx7data = DXC.dxcopy(dxcommon.range2list(copy[0]), int(copy[1]), dx7data, dx72data, tx7data)
    
    if swap:
        dx7data, dx72data, tx7data = DXC.dxswap(int(swap[0]), int(swap[1]), dx7data, dx72data, tx7data)

    for i in range(len(dx7data)//128):
        if bc2at == True:
            dx72data[20+35*i:24+35*i] = dx72data[16+35*i:20+35*i]
        if fc1 == False:
            dx72data[12+35*i:16+35*i] = [0, 0, 0, 0]
        if fc2 == False:
            dx72data[26+35*i:30+35*i] = [0, 0, 0, 0]
        if bc == False:
            dx72data[16+35*i:20+35*i] = [0, 0, 0, 50]

    if split:
        for i in range(len(dx7data)//128):
            outfile_name = dxcommon.list2string(dx7data[128*i+118:128*i+128])
            for j in range(len(outfile_name)):
                if not outfile_name[j] in ALLOWED_CHARACTERS:
                    outfile_name = outfile_name[:j] + "_" + outfile_name[j+1:]
            count = 0
            Outfile_Name = outfile_name
            while os.path.exists(Outfile_Name+outfile):
                count += 1
                if count>1: Outfile_Name = outfile_name + "(" + str(count) + ")"

            outfile_name = os.path.join(os.path.split(outfile)[0], Outfile_Name + os.path.split(outfile)[1])


            DXC.write(outfile_name, dx7data[128*i:128*(i+1)], dx72data[35*i:35*(i+1)], tx7data[64*i:64*(i+1)], dx72, TX7, channel, nosplit, mid_out)

    else:
        DXC.write(outfile, dx7data, dx72data, tx7data, dx72, TX7, channel, nosplit, mid_out)

    return 0
Exemplo n.º 8
0
def cli_main(argv=sys.argv):
    progname = os.path.basename(argv[0])

    parser = ArgumentParser(description='{}\nVersion: {} ({})'.format(
        PROGRAMNAME, PROGRAMVERSION, PROGRAMDATE), )
    parser.add_argument('-c',
                        '--channel',
                        default=0,
                        type=int,
                        help='Midi channel in SysEx header')
    parser.add_argument('-C',
                        '--check',
                        action='store_true',
                        default=False,
                        help='Check SysEx checksum before import')
    parser.add_argument('-f',
                        '--find',
                        metavar='STRING',
                        help='Search for STRING in patchnames')
    parser.add_argument(
        '-mi',
        '--mid_in',
        help=
        'select midiport MID_IN to receive data FROM synth when selecting a .req file'
    )
    parser.add_argument(
        '-mo',
        '--mid_out',
        help=
        'select midiport MID_OUT to send data TO synth when choosing "MIDI" as outfile'
    )
    parser.add_argument(
        '-m',
        '--mid',
        help=
        'use this option as a shortcut for "--mid_in MID_IN --mid_out MID_OUT", if MID_IN and MID_OUT have the same name MID'
    )
    parser.add_argument('-n',
                        '--nosplit',
                        action='store_true',
                        default=False,
                        help="Don't split: save data in one file")
    parser.add_argument('-nd',
                        '--nodupes',
                        action='store_true',
                        default=False,
                        help='Remove duplicates')
    parser.add_argument('-nd2',
                        '--nodupes2',
                        action='store_true',
                        default=False,
                        help='Remove duplicates, also with different names')
    parser.add_argument('-o',
                        '--offset',
                        type=int,
                        default=0,
                        help="Ignore first OFFSET bytes in input file(s)")
    parser.add_argument('-r',
                        '--random',
                        metavar='NUMBER',
                        type=int,
                        default=-1,
                        help="Randomize, NUMBER = a value between 0 and 300")
    parser.add_argument('-R',
                        '--Renata',
                        action='store_true',
                        default=False,
                        help="Renata's Randomizer (same as --random=0)")
    parser.add_argument('-sp',
                        '--split',
                        action='store_true',
                        default=False,
                        help="Save each patch in a separate file")
    parser.add_argument('-s',
                        '--select',
                        metavar='RANGE',
                        help='Select patch RANGE to save')
    parser.add_argument('-S',
                        '--sort',
                        action='store_true',
                        default=False,
                        help='Sort patches by name, not case-sensitive')
    parser.add_argument('-S2',
                        '--sort2',
                        action='store_true',
                        default=False,
                        help='Sort patches by name, case-sensitive')
    parser.add_argument('--copy',
                        nargs=2,
                        metavar=('X', 'Y'),
                        help='Copy patch nr X to nr Y')
    parser.add_argument('--swap',
                        nargs=2,
                        metavar=('X', 'Y'),
                        help='Swap patch nr X and nr Y')
    parser.add_argument('-t',
                        '--tx7',
                        action='store_true',
                        default=False,
                        help='Save with TX7 Performance data')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='{} ({})'.format(PROGRAMVERSION, PROGRAMDATE))
    parser.add_argument('-y',
                        '--yamaha',
                        metavar='MODEL',
                        default='tx81z',
                        help='Specify Yamaha synth MODEL for outfile')
    parser.add_argument('infile', nargs='+', help='Selects input file(s)')
    parser.add_argument('outfile', help='Select output file')

    args = parser.parse_args()
    infilez = args.infile
    infiles = []
    for i in infilez:
        infiles += glob(i)
    outfile = args.outfile

    mid_in = dxcommon.MID_IN
    mid_out = dxcommon.MID_OUT
    CFG = dxcommon.CFG
    if os.getenv('MID_IN'):
        mid_in = os.getenv('MID_IN')
    mid_out = os.getenv('MID_OUT')
    if os.path.exists(CFG):
        with open(CFG, 'r') as f:
            for line in f.readlines():
                l = line.split('=')
                if l[0].strip() == 'MID_IN':
                    mid_in = l[1].strip()
                if l[0].strip() == 'MID_OUT':
                    mid_out = l[1].strip()

    if args.mid:
        mid_in = args.mid
        mid_out = args.mid
    if args.mid_in:
        mid_in = args.mid_in
    if args.mid_out:
        mid_out = args.mid_out
    if args.mid_in or args.mid_out:
        with open(CFG, 'w') as f:
            if mid_in: f.write('MID_IN = {}\n'.format(mid_in))
            if mid_out: f.write('MID_OUT = {}\n'.format(mid_out))

    nosplit = args.nosplit
    ch = args.channel
    check = args.check
    select = args.select
    sort = args.sort
    sort2 = args.sort2
    swap = args.swap
    copy = args.copy
    nodupes = args.nodupes
    nodupes2 = args.nodupes2
    offset = args.offset
    deviation = max(-1, min(300, args.random))
    if args.Renata:
        deviation = 0
    find = args.find
    yamaha = args.yamaha.lower().strip()
    FB01 = False
    if args.split:
        split = 1
    elif yamaha in ('ys100', 'ys200', 'tq5', 'b200', 'ds55', 'v50'):
        split = 25
    elif yamaha in ('dx27s', 'dx27', 'dx27s', 'dx100'):
        split = 24
    elif yamaha == 'fb01' or os.path.splitext(outfile)[1].lower() == '.fb1':
        yamaha = 'fb01'
        FB01 = True
        split = 48
    elif yamaha == 'vopm' or os.path.splitext(outfile)[1].lower() == '.opm':
        yamaha = 'vopm'
        FB01 = True
        split = 128
    else:
        split = 32

    txdata = []
    for infile in infiles:
        print("Reading {}".format(infile))
        if not os.path.exists(infile):
            print("{} not found".format(infile))
            return 1
        if os.path.getsize(infile) > MAXFILESIZE:
            if MAXFILESIZE != 0:
                print("Warning: File too large.\nOnly {} bytes will be read".
                      format(MAXFILESIZE))
        if infile == outfile:
            print("Must have different input and output files")
            return 1

        if os.path.isfile(infile):
            txdat, channel = TXC.read(infile, offset, check, yamaha, mid_in,
                                      mid_out)
            txdata += txdat

    if ch != None:
        channel = ch - 1
        channel = max(0, channel)
        channel = min(15, channel)

    if nodupes2:
        nodupes = True

    if nodupes or nodupes2:
        if FB01:
            txdata = TXC.fbnodupes(txdata, nodupes2)
        else:
            txdata = TXC.txnodupes(txdata, nodupes2)

    if select != None:
        txdat = []
        for i in dxcommon.range2list(select):
            if FB01:
                txdat += txdata[64 * (i - 1):64 * i]
            else:
                txdat += txdata[128 * (i - 1):128 * i]
        txdata = txdat

    if args.find != None:
        if FB01:
            txdata = TXC.fbfind(txdata, find)
        else:
            txdata = TXC.txfind(txdata, find)

    if deviation != -1:
        if FB01:
            txdata = TXC.fbrandom(txdata, deviation)
        else:
            txdata = TXC.txrandom(txdata, deviation)

    if sort:
        if FB01:
            txdata = TXC.fbsort(txdata, False)
        else:
            txdata = TXC.txsort(txdata, False)
    if sort2:
        if FB01:
            txdata = TXC.fbsort(txdata, True)
    if copy:
        if FB01:
            txdata = TXC.fbcopy(dxcommon.range2list(copy[0]), int(copy[1]),
                                txdata)
        else:
            txdata = TXC.txcopy(dxcommon.range2list(copy[0]), int(copy[1]),
                                txdata)

    if swap:
        if FB01:
            txdata = TXC.fbswap(int(swap[0]), int(swap[1]), txdata)
        else:
            txdata = TXC.txswap(int(swap[0]), int(swap[1]), txdata)

    if split == 1:
        if FB01:
            for i in range(len(txdata) // 64):
                outfile_name = dxcommon.list2string(txdata[64 * i:64 * i + 7])
                for j in range(len(outfile_name)):
                    if not outfile_name[j] in ALLOWED_CHARACTERS:
                        outfile_name = outfile_name[:j] + "_" + outfile_name[
                            j + 1:]
                count = 0
                Outfile_Name = outfile_name
                while os.path.exists(Outfile_Name + outfile):
                    count += 1
                    if count > 1:
                        Outfile_Name = outfile_name + "(" + str(count) + ")"

                outfile_name = os.path.join(
                    os.path.split(outfile)[0],
                    Outfile_Name + os.path.split(outfile)[1])

                TXC.write(outfile_name, txdata[64 * i:64 * (i + 1)], channel,
                          nosplit, 1, yamaha, mid_out)

        else:
            for i in range(len(txdata) // 128):
                outfile_name = dxcommon.list2string(txdata[128 * i +
                                                           57:128 * i + 67])
                for j in range(len(outfile_name)):
                    if not outfile_name[j] in ALLOWED_CHARACTERS:
                        outfile_name = outfile_name[:j] + "_" + outfile_name[
                            j + 1:]
                count = 0
                Outfile_Name = outfile_name
                while os.path.exists(Outfile_Name + outfile):
                    count += 1
                    if count > 1:
                        Outfile_Name = outfile_name + "(" + str(count) + ")"

                outfile_name = os.path.join(
                    os.path.split(outfile)[0],
                    Outfile_Name + os.path.split(outfile)[1])

                TXC.write(outfile_name, txdata[128 * i:128 * (i + 1)], channel,
                          nosplit, 1, yamaha, mid_out)
    else:
        TXC.write(outfile, txdata, channel, nosplit, split, yamaha, mid_out)

    return 0