Go Back   Cockos Incorporated Forums > REAPER Forums > MIDI Hardware, Control Surfaces, and OSC

Reply
 
Thread Tools Display Modes
Old 04-28-2019, 02:20 PM   #1
DarrenH
Human being with feelings
 
Join Date: Mar 2014
Posts: 347
Default MIDI...new connection, mappings all wrong. Is there a fix?

I changed how my MIDI keyboard was connected to my computer...changed from USB MIDI, which was always flaky, to using an M-Audio MIDI to USB device.

The device is different in Reaper now, of course. But all my synth MIDI mappings aren't working any more.

Is there some way of mapping the old mappings to the new MIDI input?

ReaLearn doesn't work as it doesn't map according to FX by name, only their position in the chain. So it's not effective for any situation where you might make changes to your FX chain (which is often in my case).

Thanks

Last edited by DarrenH; 04-29-2019 at 06:32 AM.
DarrenH is offline   Reply With Quote
Old 04-28-2019, 09:31 PM   #2
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,773
Default

If you now use 5 pin Midi via an USB Device, the Midi device name did change, and hence there is no way "see" the original device name in Reaper any more.
But you can manually change the input and output Mid Device ID in the Reaper "Midi devices" menu to match the old setting. After that the original project should run as before. (For loosely related technical stuff see -> https://forum.cockos.com/showthread.php?t=219792 )

-Michel
mschnell is offline   Reply With Quote
Old 04-29-2019, 07:48 AM   #3
DarrenH
Human being with feelings
 
Join Date: Mar 2014
Posts: 347
Default

Thank you Michel, appreciate your work on the related issues in that other thread. Sorry to see that it didn't get any notice. Reddit is a more active place for Reaper enthusiasts in general (at least in my experience)

I'm interested in the Python script you created if you ever feel like sharing....

Thanks again Darren


Quote:
Originally Posted by mschnell View Post
If you now use 5 pin Midi via an USB Device, the Midi device name did change, and hence there is no way "see" the original device name in Reaper any more.
But you can manually change the input and output Mid Device ID in the Reaper "Midi devices" menu to match the old setting. After that the original project should run as before. (For loosely related technical stuff see -> https://forum.cockos.com/showthread.php?t=219792 )

-Michel

Last edited by DarrenH; 04-29-2019 at 08:25 AM.
DarrenH is offline   Reply With Quote
Old 04-29-2019, 01:06 PM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 14,773
Default

Here you are.
Additionally the program selects one of four commands (e.g. batch files) to be started depending on the active USB Midi interfaces.

(Please pardon my programming style, as this is my first Python program ever.)

Code:
'''
@author: mschnell
'''

# import winreg
#import pygame
import pygame.midi
#import re
import os
import configparser
from pip._vendor.appdirs import unicode
            
def noprefix(n) :
    p = True
    prefix = n[0:3]
    if not (prefix[1:] == "- ") :
#        print("'"+prefix[1:3]+"'")
        p = False
    else :
        pp = ord(prefix[0])
        if (pp<ord("1")) or (pp >ord("9")) :
            p = False
    if p :
        nn = n[3:]
    else :
        nn = n
        prefix = ""
    return (nn, prefix)
        
        
def searchdevice(a, n, prefix, io):    
    i1 = ""
    o1 = ""
    if not prefix :
        [n, ap] = noprefix(n)        
    for x in a :
        if (x.find("in") >= 0) or (x.find("on") >= 0) :
            if not prefix :
                [an, ap] = noprefix(a[x])
            else:
                an = a[x]
            if  an ==  n :
                z = x[0:1]
                if z ==  "i" :
                    if not io :
                        i1 = x #int(y)
                        break
                else :
                    if io :
                        o1 = x #int(y)
                        break       
    return (i1, o1)

def swap1 (c, a1, ai, c2):
    a1 = a1[0]+c2+a1[2:]
    ai = ai[0]+c2+ai[2:]
#    print("swap ", a1, ai)
    x = c[a1]
    c[a1] = c[ai]
    c[ai] = x;
    return    

def swapdevices (c, x1, xi):
    if x1 != xi :
        s1 = x1[0]+"."+x1[2:];
        si = xi[0]+"."+xi[2:];
        print("   Device", '"'+c[xi]+'": swap Reaper ID', si, "to", s1)  
        swap1(c, x1, xi, "n")
        swap1(c, x1, xi, "a")
        swap1(c, x1, xi, "t")
#    else :
#        print("identical ", x1, xi)        
    return

if __name__ == '__main__':

    command_00 = "batch00"
    command_01 = "batch01"
    command_10 = "batch10"
    command_11 = "batch11"
    device_1  = "device1"  
    device_2  = "device2"  

    current = os.path.dirname(os.path.abspath(__file__))
#    print("current :", current)
    os.chdir(current)

    config = configparser.ConfigParser()
    config.read("start.ini")
    configmidi  = config["MIDI"]
    compare1 = configmidi[device_1]
    compare2 = configmidi[device_2]
    command = [configmidi[command_00],
               configmidi[command_01],
               configmidi[command_10],
               configmidi[command_11]]
#    print("compare =", compare)
#    confid = configmidi["ID"]
#    print("ID =", confid)

    midi = pygame.midi
    midi.init()
    devicecount = midi.get_count()
#    print("devicecount =", devicecount)
    i = 0
    found = 0
    devicelist = []
    while i < devicecount:
        info = midi.get_device_info(i)
        devicename = info[1]
        i_o = info[3]
        devicename = unicode(devicename, "utf-8")
        devicelist.append([devicename, i_o])
        if i_o != 0 :
            i_o_ = "out"
        else :
            i_o_ = " in"            
        print ("active", i_o_, "Device:", '"'+devicename+'"')
        n = devicename.find(compare1)
        if n>= 0:        
            print("   =", device_1)
            found |= 1        
#            found_id = i;    
        n = devicename.find(compare2)
        if n>= 0:        
            print("   =", device_2)
            found |= 2        
#            found_id = i;    
        i += 1
        
    midihw    = config["REAPER"]["midihwtemplate"]
    midihwneu = config["REAPER"]["midihw"]
    inisection = "mididevcache"

    config = configparser.ConfigParser()    
    config.read(midihw)
    cis = config[inisection]
    [i1, o1] = searchdevice(cis, compare1, False, False)
#    print("devicelist:", devicelist)
    for dev in devicelist :
        dev_n = dev[0]
        dev_o = dev[1] != 0;
        if dev_o :
            dev_o_ = "out"
        else:
            dev_o_ = " in"
        print(dev_o_, 'Device "'+dev_n+'" :')
        [i1, o1] = searchdevice(cis, dev_n, False, dev_o)
#        if i1 != "" :
#            print(" in: 1st Reaper ID =", i1[0]+"."+i1[2:], ":",  '"'+cis[i1]+'"')
#        if o1 != "" :
#            print("out: 1st Reaper ID =", o1[0]+"."+o1[2:], ":", '"'+cis[o1]+'"')
        if (i1 != "") or (o1 != "") :
            print("   found in", midihw)
        
        if (i1 != "") & (not dev_o) :
            [ii, oi] = searchdevice(cis, dev_n, True, dev_o)
            if ii != "" :
                swapdevices(cis, i1, ii)
        if (o1 != "") & dev_o :
            [ii, oi] = searchdevice(cis, dev_n, True, dev_o)
            if oi != "" :
                swapdevices(cis, o1, oi)

    inifileobj = open(midihwneu, 'w')
    config.write(inifileobj)
    inifileobj.close()
        
    c = command[found]
    print("execute command:",c)

    if c != 0: 
        os.system(c)
    midi.quit()
and an appropriate ini file:
Code:
[MIDI]
device1 = MIDI Mapper
device2 = SYNTH
batch00=start00.bat
batch01=start01.bat
batch10=start10.bat
batch11=start11.bat
[REAPER]
midihw = c:/Users/mschnell/AppData/Roaming/REAPER/reaper-midihw.ini
midihwtemplate = reaper-midihw.template
mschnell is offline   Reply With Quote
Old 05-01-2019, 06:00 AM   #5
DarrenH
Human being with feelings
 
Join Date: Mar 2014
Posts: 347
Default

Thanks very much for this...I'll give it a spin. Being a mediocre coder myself I wouldn't dare comment on your coding ; )
DarrenH is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.