Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 2 1 2 LastLast
Results 1 to 25 of 29

Thread: Adjusting the Teensy MIDI device name

  1. #1
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    537

    Adjusting the Teensy MIDI device name

    Hi all

    i note in this thread it is possible to hack your teensyduino install with a new USB device type and code to rename your midi controller.

    https://forum.pjrc.com/threads/23523-Change-device-name

    it is functional but not elegant in the usual PJRC manner, and ongoing support is unlikely to be available using this method.

    are there any better ways to achieve this from code in 2016?

    thanks

    jon

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Posts
    132
    follow with interest.

  3. #3
    Senior Member
    Join Date
    Nov 2015
    Posts
    132
    No answer for this question?
    Thanks

  4. #4
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    537
    Quote Originally Posted by urbanspaceman View Post
    No answer for this question?
    Thanks
    No - there is no new approach unfortunately - you can do it - but you have to hack your Teensyduino install about, and if anyone has previously plugged in a teensy on a host windows computer, it will almost certainly pop up as a Teensy, ignoring your changes.

    Right now, this is probably bubbling around at the very bottom of Paul's todo list if it is on it at all - so I wouldn't hold your breath.

  5. #5
    Senior Member
    Join Date
    Nov 2015
    Posts
    132
    Thanks for your reply Pensive

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,191
    Actually, there is some provision for this using weak linking you can override, but no friendly documentation on how to actually do it.

    https://github.com/PaulStoffregen/co...y3/usb_names.h

  7. #7
    Junior Member
    Join Date
    Jan 2016
    Location
    Ohio, USA
    Posts
    14
    also following this one

  8. #8
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    906
    Quote Originally Posted by PaulStoffregen View Post
    Actually, there is some provision for this using weak linking you can override, but no friendly documentation on how to actually do it.

    https://github.com/PaulStoffregen/co...y3/usb_names.h
    Any chance on some unfriendly documentation or even a hint or two?

    I get that the weak attribute means these defines can be overridden so I assume the sketch would need to have some #define statements to take the place of the ones in usb_desc.h.

    But I gather it's not a simple as adding the replacements in the setup section of the sketch:

    #define PRODUCT_NAME {'M','y',' ','M','I','D','I'}
    #define PRODUCT_NAME_LEN 7


    So are there some broad strokes or general guidance on this as the question keeps coming up but there are still no details.

  9. #9
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    537
    i've done some googling and in c++ you can punch in weak link overrides before runtime via DLL file, i maybe a million miles away but i think you might need to pull in a dll which defines these values in the correct structs which will be pulled into the compile chain before runtime.

    Total guess, i'm sure there's an easier way, and it might not be arduino compatible - i've never seen a DLL in an arduino project before.

    EDIT - I don't think this is right at all, I'm totally at sea here, missing out some core knowledge.
    Last edited by Pensive; 10-08-2016 at 01:47 PM. Reason: Suspected Idiocy

  10. #10
    Senior Member oddson's Avatar
    Join Date
    Feb 2013
    Location
    Isle in the Salish Sea
    Posts
    906
    DLLs use weak linking so they show up in searches on the topic but the idea is more general.

    There's a hint in the other thread where Paul indicates why the fix isn't simple:

    Quote Originally Posted by PaulStoffregen View Post
    ...The trouble with a weak symbol is the USB descriptor stuff depends on finding the string length as a compile-time constant. Obviously the compiler can't know the length of your string in the sketch while compiling the USB code (remember, restructuring the build process is not an option because compatibility with Arduino is a major design goal). So the USB descriptor sending code, inside that interrupt-based code, needs to be redesigned to handle data somewhat differently. That's the main reason this is still on my to-do list... there's no quick and easy way to do it. On AVR, there's also the issue of making sure the user's data is in the right memory space, but that's a lesser concern because people will probably just copy and edit an example.
    So I gather we have to declare the structure(s) since that's what has the weak attribute, thereby overwriting the structure declarations at about line 1200 of usb_desc.c.

  11. #11
    Senior Member
    Join Date
    Jan 2013
    Posts
    843
    The weak symbol stuff is implemented and works. However, there appears to be no way to make it work directly from C++ (e.g. your .ino sketch). So go to your sketch folder and create a new C file "usb_desc.c":
    Code:
    #include <usb_names.h>
    
    #define MANUFACTURER_NAME    {'t','n','i'}
    #define MANUFACTURER_NAME_LEN 3
    #define PRODUCT_NAME    {'t','i','n', 'y', ' ', 'd', 'e', 'v', 'i', 'c', 'e'}
    #define PRODUCT_NAME_LEN 11
    
    struct usb_string_descriptor_struct usb_string_manufacturer_name = {
            2 + MANUFACTURER_NAME_LEN * 2,
            3,
            MANUFACTURER_NAME
    };
    
    struct usb_string_descriptor_struct usb_string_product_name = {
            2 + PRODUCT_NAME_LEN * 2,
            3,
            PRODUCT_NAME
    };
    The weak symbols that get overwritten are "usb_string_manufacturer_name" and "usb_string_product_name".

  12. #12
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    537
    well this is exciting, i've held off bothering because i need to re-do it all every time i update

  13. #13
    Junior Member
    Join Date
    Jan 2018
    Posts
    4
    Quote Originally Posted by tni View Post
    The weak symbol stuff is implemented and works. However, there appears to be no way to make it work directly from C++ (e.g. your .ino sketch). So go to your sketch folder and create a new C file "usb_desc.c":
    Code:
    #include <usb_names.h>
    
    #define MANUFACTURER_NAME    {'t','n','i'}
    #define MANUFACTURER_NAME_LEN 3
    #define PRODUCT_NAME    {'t','i','n', 'y', ' ', 'd', 'e', 'v', 'i', 'c', 'e'}
    #define PRODUCT_NAME_LEN 11
    
    struct usb_string_descriptor_struct usb_string_manufacturer_name = {
            2 + MANUFACTURER_NAME_LEN * 2,
            3,
            MANUFACTURER_NAME
    };
    
    struct usb_string_descriptor_struct usb_string_product_name = {
            2 + PRODUCT_NAME_LEN * 2,
            3,
            PRODUCT_NAME
    };
    The weak symbols that get overwritten are "usb_string_manufacturer_name" and "usb_string_product_name".

    Hi there. Has anyone got this working? What is the definition of "your sketch folder" for placing the usb_desc.c file? The folder besides the .ino?

    thanks

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,191
    Quote Originally Posted by chaosmoon View Post
    Has anyone got this working?
    Yes, they have.

    First, open the example code by clicking File > Examples > Teensy > USB_MIDI > MIDI_name.

    Now, here's the trick. This "sketch" is actually 2 files. Arduino shows them in tabs. You need to click the "name.c" tab.

    Here's a screenshot:

    Click image for larger version. 

Name:	sc.png 
Views:	17 
Size:	30.2 KB 
ID:	12686

    This is where you will edit the name. But perhaps just try it as-is, where the name changes from "Teensy MIDI" to "My MIDI". Make sure Tools > USB Type is set to MIDI, and upload to your Teensy.

  15. #15
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,191
    There's one more tricky step, which is getting your computer to "forget" the old name and show you the new name. Just today, these words were suggested for Macintosh:

    Macintosh: Open “Audio Midi Setup”, unplug the Teensy device, delete it from the Midi Devices/Midi Studio Window, replug the Teensy device and your changes will show.
    My guess is you would do something similar on Windows, perhaps involving uninstalling the "driver" from the Device Manager. This last part is still in need of specific instructions, maybe even with screenshots. If anyone can contribute specific advice for Windows users, please do?

  16. #16
    Junior Member
    Join Date
    Jan 2018
    Posts
    4
    Thanks for the swift reply, i'll check this out and report back. (i see im running a few versions behind on both Arduino and Teensyduino)

  17. #17
    Junior Member
    Join Date
    Jan 2018
    Posts
    4
    After updating Arduino and Teensyduino i can confirm that the methods described above are working under OSX 10.11.16, Arduino 1.8.5, Teensy 1.41

    i saved the example as plain text in my sketch folder from notepad as "name.c"
    re-opened the sketch
    edited the filename characters in the example
    adjusted the length
    uploaded sketch
    unplugged Teensy
    deleted the old device in Audio Midi Setup

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,191
    I've updated the website with instructions.

    https://www.pjrc.com/teensy/td_midi.html

    Still hoping someone can contribute instructions on Windows, ideally specific to each mouse click or other action taken. Screenshots wanted for both systems.

  19. #19
    Senior Member
    Join Date
    Nov 2012
    Posts
    904
    FYI: I just tried my sketch which combines two keyboards and a couple of buttons into one USB stream from the T3.6. I added the name.c tab to it, recompiled and uploaded and it works immediately - Midi-Ox sees it as "My MIDI". I then recompiled the original version and uploaded that and it immediately shows up in Midi-Ox as "Teensy MIDI".
    So, you don't have to delete drivers. Just compile, upload and go.
    BTW, this was on a Win 10 Pro X64, Arduino 1.8.5 + TD 1.41

    Pete

  20. #20
    Senior Member
    Join Date
    Nov 2012
    Posts
    904
    Here's a screencap of MIDI-OX
    Click image for larger version. 

Name:	usbhost_my_name.gif 
Views:	43 
Size:	50.6 KB 
ID:	12687

    Pete

  21. #21
    Senior Member
    Join Date
    Nov 2012
    Posts
    904
    @Paul:
    Did you see #19? Windows users shouldn't need to delete the device.

    Pete

  22. #22
    Senior Member Davidelvig's Avatar
    Join Date
    Aug 2015
    Location
    Wisconsin
    Posts
    221
    Woo Hoo!
    I added a new tab to my project in the Arduino IDE titled MIDI_Name.c... copied in the code, and Audacity on OSX now reports "My MIDI"
    Very cool!

  23. #23
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Essonne, France
    Posts
    154
    One thing I learned while doing the early USB Audio tests was that the device name and general USB properties are not automatically updated on an host for devices using the same name, VendorID and ProductID unless the bcdDevice field in the Device Descriptor is not updated too (usb_desc.c, line 90)

  24. #24
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,191
    Quote Originally Posted by el_supremo View Post
    Did you see #19? Windows users shouldn't need to delete the device.
    Thanks. I've updated the web page with a link to this thread.

    Can anyone confirm whether Windows 7 automatically detects the MIDI name change?

  25. #25
    Junior Member
    Join Date
    Jan 2018
    Posts
    4
    Quote Originally Posted by PaulStoffregen View Post
    I've updated the website with instructions.

    https://www.pjrc.com/teensy/td_midi.html

    Still hoping someone can contribute instructions on Windows, ideally specific to each mouse click or other action taken. Screenshots wanted for both systems.
    Here's a screenshot of OSX Audio MIDI setup.

    Click image for larger version. 

Name:	MIDI_name-OSX_AudioMidi.jpg 
Views:	23 
Size:	64.3 KB 
ID:	12728

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •