is there a way to configure input using joystick name rather than index number?

[I’ve posted this [same question at RetroArch-Linux section](http://libretro.com/forums/showthread.php?t=6202), but I think it’s a “General” question. Sorry for the duplication.] hey guys!

First the question and then an explanation of what I want to do.

Question: Is there a way to configure the input joystick for players 1-4 using the joystick name, rather than the index (input_playerX_joypad_index)?

What I want to do…

I’m running RetroArch on Linux on a Raspberry Pi (more specifically, the system is RetroPie).

I like to play SNES games with a SNES-like bluetooth controller, NES games with a NES-like bluetooth controller (both are from 8bitdo), and arcade games with an arcade-like controller. And I’m used to change the input using the input_playerX_joypad_index on system’s specific retroarch.cfg.

The problem is that due to the dynamic nature of Bluetooth conections, the index may change. So keeping these configurations hardcoded isn’t that practical.

BTW: to turn the configuration process easier for the n00bs/lazy people, I made an script with some dialog boxes to let the users configure the input joystick for players 1-4. (It can be found on my github: https://github.com/meleu/RetroPie-joystick-selection )

The script gets the joystick indexes and names from a really small C program I wrote (source code at the end of this message). It gets these information using SDL2 functions. During the configuration process the user sees the joystick names, but in the end it uses the index on a retroarch.cfg-like file with input_playerX_joypad_index lines. Then, if the the joystick order changes (adding/removing devices), the user needs to execute the script again.

If I could configure this using the names, it would avoid the need of rerunning the script frequently.

Here is the C code to list the joysticks indexes and names:

/* jslist.c
* This little program just list the joysticks connected to the system.
* The ouput format is "index:JoystickName".
*
* Compile it with: 
* [prompt]$ gcc jslist.c -o jslist $(sdl2-config --cflags --libs)
*/

#include <stdio.h>
#include "SDL.h"

int main(void) {
    int num_joy, i;

    SDL_Init(SDL_INIT_JOYSTICK);

    num_joy = SDL_NumJoysticks();

    for(i = 0; i < num_joy; i++)
        printf("%d:%s
", i, SDL_JoystickNameForIndex(i));

    SDL_Quit();
    return 0;
}

is there a reason you can’t just turn off the other controllers and turn on the appropriate one when you want to use it? if you do that, and they’re autoconfigured properly, core input remapping should handle shuffling the inputs around on the retropad as necessary.

Yes, there is. User laziness. :smiley:

I simplified the usecase a lot… Let’s imagine this situation:

I’m playing Castlevania (NES) with my NES-like controller. And then my friend arrives and says “Wazzup dude! Let’s play Super Mario Kart on versus mode! Let me use this cool SNES bluetooth controller and be the player 1!”. As I am a kind host, I have to answer “Sure! Let’s go!”. Then we simply turn on the SNES controller and launch a SNES core with Super Mario Kart.

I want to write a shell script do something like this pseudo-code:


launch snes9x-next {
    if snes-controller is on; then {
        player1 = snes-controller
        player2 = first_non_snes-controller
        player3 = second_non_snes-controller
        player4 = third_non_snes-controller
    } else {
        player1 = 0 //default indexes
        player2 = 1
        player3 = 2
        player4 = 3
}  

And repeat this kind of code for other cores.

Summing up: I want to define some joystick priorities for some cores. Example: if the SNES controller is on when launching a SNES core, use it as player1; otherwise use the defaults.

Please, keep in mind that I’m not having problems with reordering the input to fit my own playing. I’m just trying to simplify some steps for the non-tech people.

(I’m not sure if I’m being clear… sorry english is not my native language. let me try other words…)

Please, consider my question as a frontend developer question, not as an end-user question.

That’s fine. No judgment here :slight_smile:

I think your biggest impediment is going to be that RetroArch only knows about vid/pid and doesn’t have any mechanism for keeping track of anything about any specific controller. Moreover, RetroArch doesn’t have any concept of “systems,” so there’s no way to say “this is an SNES-style controller” or even “these cores are for SNES games.”

I’m not sure what your best strategy would be to achieve your goal. Maybe look into using/extending the autoconfig files to include additional fields that you can look for…?

Yeah! It’s very clear for me. I don’t want to give such tasks to RetroArch. I want to develop it myself.

The mechanism to let RetroArch know “these cores are for these games” is already provided by RetroPie system. And I want to develop a tool to say to RetroArch “use the joystick named ‘foobar-bluetooth-controller’ as player1”. I know how to do it using the joystick index, and I would like to know how to do it using the joystick name (and it was my initial question).

Oh… Thanks for the tip. So I’m considering that there is no way to tell to RetroArch what controller I want for playerN using the joystick name.

But it’s OK. I’m thinking on this solution:

  • the user sets the configuration using my script.
  • it creates some config files, separated by systems (nothing new here, RetroPie already do this way). And these files are filled with “input_playerX_joypad_index = joystick-name” (the name obtained with my jslist.c [code on the first post of this thread]).
  • right before RetroArch begins, I’ll substitute the joystick-name by the respective index (using sed).

Now I have another question: Do you know how RetroArch add these trailing #numbers at the end of the repeated joystick names? (Pointing the source code on github would be nice :slight_smile: )

Sorry to hijack an old topic, but i’m having a similar problem which could possibly be rectified by such a solution. To preface, I’m trying to configure the following for the Nestopia core. See, i just acquired a few adapters for my original nes/snes controllers: 2 Tomee NES ones and a Dual SNES adapter from Mayflash.

The thing is, i can connect both nes controllers up, and configure them just fine. They are appropriately assigned a joypad_index of 0 and 1. However, when i plug in the mayflash adapter (to play NES four score games), it seems to hijack device indexes 1 and 2, forcing the second nes game pad into index 3 (player 4).

I can then configure NES pad 2 to be user 2, the first snes controller to user 3 and the second snes controller to user 4 and save this arrangement. However, when i then remove the snes controller adapter, the second nes controller returns to index 1 and as a result controls user 3 and not 2.

Ideally, when i plug in the snes adapter, these controllers should be bound to users 3 and 4 (device indexes 2 and 3) automatically - with no impact on the index of the second nes controller, and when removed it is users 3 and 4 which should be left without a controller.

In a similar way, it would be great if - for example, unplugging the second nes controller would make the snes controllers players 2 and 3. This could perhaps be achieved by providing each individual controller with a fixed device index.

In my case:

  • Index 0: NES controller 1 = user 1
  • Index 1: NES controller 2 = user 2
  • Index 2: SNES controller 1 = user 3
  • Index 3: SNES controller 2 = user 4

Upon unplugging a controller (e.g. nes controller 2), the device indexes of each controller will not change, but each index would be automatically matched to the previous user. Users 1, 2 and 3 should always be provided with a controller prior to user 4.

  • Index 0: NES controller 1 = user 1
  • Index 1: None = no user
  • Index 2: SNES controller 1 = user 2
  • Index 3: SNES controller 2 = user 3

This could be done per core so controllers could be prioritised for individual systems or games (e.g. genesis controller, snes controller, snes controller, dualshock for playing Sega Genesis games) according to personal preference.

If there’s some existing way of doing this and i’ve completely missed it, feel free to point it out. If not, i think such a feature would be incredibly useful to owners of individual controller adapters, offering them hot pluggability comparable to the 4-play and prioritisation of several controllers. If it causes too many problems, perhaps it could be implemented as an optional setting.

Sorry for the (hopefully not completely indecipherable) wall of text. :wink: