Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alsa Midi Ports reservation while not in use #27

Open
jhordies opened this issue Oct 20, 2024 · 1 comment
Open

Alsa Midi Ports reservation while not in use #27

jhordies opened this issue Oct 20, 2024 · 1 comment

Comments

@jhordies
Copy link

Hello,

Sorry to revive an old topic.

I'm using Mixing Station (Java) on my rpi with Jack and mod-host/mod-ui.
Long story short, Mixing Station cannot use any midi port even-though the ports are not in use by any jack client.

I already contacted Mixing Station to try and get them to use jack midi but they say they use the standard java midi and their customer base is too small on Linux & Jack to change their implementation for this use case.

I understand the ports are being locked to one consumer (in SEQ) but does a2jmidid absolutely need to open the ports only to list them as available to jack ?

This project seem to have taken that approach to solve the same problem.

Alternatively could jack somehow expose an alsa software midi port to act as a jack client ?

Any idea is welcome !

Thanks a lot for all the excellent work.

@jhordies jhordies changed the title Midi reservation Alsa Midi Ports reservation while not in use Oct 20, 2024
@jhordies
Copy link
Author

Here is a simple Java program to test the behaviour:
Save as MidiPortTest.java
compilce with : javac MidiPortTest.java
Run with: java MidiPortTest.class

import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import java.util.Scanner;

public class MidiPortTest {

    public static void main(String[] args) {
        // Get user input to select a MIDI device
        Scanner scanner = new Scanner(System.in);
        while (true) {
            MidiDevice.Info[] midiDevices = getMidiDevices();
            int deviceIndex = -1;
            System.out.print("Enter the number of the MIDI device you want to open or 'q' to quit : ");
            String userInput = scanner.nextLine();
            if (userInput.compareToIgnoreCase("q") == 0) {
                break;
            } else {
                if (!userInput.isEmpty()) {
                    try {
                        deviceIndex = Integer.parseInt(userInput);
                        testDevice(midiDevices, deviceIndex);
                    } catch (NumberFormatException e) {
                        System.out.println("Invalid Option.");
                    }
                }
            }
        }

    }

    private static void testDevice(MidiDevice.Info[] midiDevices, int deviceIndex) {
        try {

            if (deviceIndex < 0 || deviceIndex >= midiDevices.length) {
                System.out.println("Invalid device number.");
                return;
            }

            // Get the selected device and open it
            MidiDevice device = MidiSystem.getMidiDevice(midiDevices[deviceIndex]);
            if (!device.isOpen()) {
                device.open();
                System.out.println("MIDI device opened successfully.");
            } else {
                System.out.println("MIDI device is already open.");
            }

            // Test if it can send and receive MIDI data
            if (device.getMaxTransmitters() != 0 || device.getMaxReceivers() != 0) {
                System.out.println("MIDI device supports data transmission.");
            } else {
                System.out.println("MIDI device does not support data transmission.");
            }

            // Close the device
            device.close();
            System.out.println("MIDI device closed.");
        } catch (MidiUnavailableException e) {
            System.err.println("Failed to open the MIDI device: " + e.getMessage());
        }

    }

    private static MidiDevice.Info[] getMidiDevices() {
        // List all available MIDI devices
        MidiDevice.Info[] midiDevices = MidiSystem.getMidiDeviceInfo();
        System.out.println("Available MIDI Devices:");
        for (int i = 0; i < midiDevices.length; i++) {
            System.out.println(i + ": " + midiDevices[i].getName() + " - " + midiDevices[i].getDescription());
        }
        return midiDevices;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant