Bug 269106 - audio/milkytracker: Include MIDI support
Summary: audio/milkytracker: Include MIDI support
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Emanuel Haupt
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-23 01:21 UTC by Alex Bylund
Modified: 2023-02-28 21:02 UTC (History)
4 users (show)

See Also:
fernape: maintainer-feedback? (ehaupt)


Attachments
Adding MIDI support (556 bytes, patch)
2023-01-24 16:30 UTC, Alex Bylund
no flags Details | Diff
Working MIDI support patch (612 bytes, patch)
2023-01-25 02:14 UTC, Alex Bylund
no flags Details | Diff
MIDI support patch candidate (1.33 KB, patch)
2023-02-14 16:27 UTC, Alex Bylund
no flags Details | Diff
Good MIDI support patch (1.56 KB, patch)
2023-02-14 23:56 UTC, Alex Bylund
no flags Details | Diff
proposed patch for audio/rtmidi (781 bytes, patch)
2023-02-23 04:39 UTC, Tatsuki Makino
no flags Details | Diff
Good MIDI support patch fix (1.58 KB, patch)
2023-02-27 08:08 UTC, Alex Bylund
no flags Details | Diff
MIDI via rtmidi patch (1.57 KB, patch)
2023-02-27 18:31 UTC, Alex Bylund
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Bylund 2023-01-23 01:21:52 UTC
I don't know enough about ports/cmake to submit a patch, but I can with some instruction or pointers. This is the just get it to work fix.

Add this to the cmake build text (just making sure it includes all the MIDI files):

add_subdirectory(src/midi)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/include/rtmidi -L/usr/local/lib/ -lrtmidi")
find_library(RTMIDI_LIBRARY RtMidi)

find_package(RTMIDI REQUIRED)
find_package(JACK REQUIRED)
find_package(ALSA REQUIRED)
find_package(SDL2 REQUIRED)

Also change some includes to absolute paths in the midi header because it doesn't read the src/midi includes.

Then the MIDI support is working as described in the docs.
Comment 1 Alex Bylund 2023-01-24 16:30:35 UTC
Created attachment 239678 [details]
Adding MIDI support

Breaks the installation, compiles the right binary
Comment 2 Alex Bylund 2023-01-25 02:14:25 UTC
Created attachment 239692 [details]
Working MIDI support patch

This one is good as far as I can tell.
Comment 3 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-06 09:44:26 UTC
Thank you for the patch. I am looking into it.
Comment 4 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-07 10:19:50 UTC
The patch looks good. Passes all fine in poudriere.

Just curious: I am able to load *.mid files but don't get any audio. Are you able to play midi with output? Is there additional configuration needed?
Comment 5 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-07 10:34:11 UTC
Sorry, I missed your original message.

In order to create a patch for cmake you can do the following:

make clean
make extract
cd work/MilkyTracker-1.03.00/
[create a copy of the file you're editing ending in .orig, eg:]
cp CMakeLists.txt CMakeLists.txt.orig
[make your changes to CMakeLists.txt]
[go back to the ports directory]
make makepatch
[This will create a patch in ./files/]
Comment 6 Alex Bylund 2023-02-07 15:15:39 UTC
(In reply to Emanuel Haupt from comment #4)
The description might be better as "ALSA MIDI Support" This is for a MIDI controller, and will enable MIDI for input.

The original fix is kind of like a broken patch, so it doesn't need to be made.
Comment 7 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-09 07:12:00 UTC
What do you think about?

RTMIDI_DESC=    MIDI input support via rtmidi

Other options use a similar wording:

# grep MIDI /usr/ports/Mk/bsd.options.desc.mk 
FLUIDSYNTH_DESC?=       MIDI playback support via FluidSynth
Comment 8 Alex Bylund 2023-02-09 11:18:05 UTC
(In reply to Emanuel Haupt from comment #7)
That's probably good. The description has a couple of reasons to select it or not, and the lib if somebody wants to know more.
Comment 9 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-09 19:02:34 UTC
Unfortunately it fails to compile:

https://critical.ch/people/0d017638-a8ac-11ed-b6c8-10bf48e1088e/milkytracker-1.03.00_2.log

In order to test it with poudriere you can just add:

OPTIONS_DEFAULT=DOCS RTMIDI

to the Makefile in order to enable the RTMIDI option.
Comment 10 Alex Bylund 2023-02-09 19:19:40 UTC
I'm on 12.3, but looking at the log it appears that RtMidi is broken on 13.1.
Comment 11 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-09 19:24:17 UTC
It fails with the same error in poudriere on 12.3 amd64:

https://critical.ch/people/2b1c010d-a8af-11ed-b6c8-10bf48e1088e/milkytracker-1.03.00_2.log
Comment 12 Alex Bylund 2023-02-09 19:28:28 UTC
I'll see what I can find out with poudriere.
Comment 13 Alex Bylund 2023-02-10 08:39:52 UTC
I'm unable to find anything out, it compiles and installs. I can't find a "noexcept" keyword anywhere in MilkyTracker or RtMidi, though.

It's a new poudriere install and a jail built from the RELEASE DVD.
Comment 14 Alex Bylund 2023-02-13 21:34:44 UTC
The poudriere builds are using rtmidi-5.0.0.pkg, and I used building from source instead of using the packages. The package has the noexcept keywords in it, which I think would have also came up with errors with any other software using the installed /usr/local/include/rtmidi/RtMidi.h from the package.

I don't know if a PR needs to be made for RtMidi or if something else is going on.
Comment 15 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-14 09:23:35 UTC
I've added the rtmidi ports maintainer as cc.
Comment 16 Alex Bylund 2023-02-14 16:27:18 UTC
Created attachment 240157 [details]
MIDI support patch candidate

After restarting from the beginning, I consider this the superior patch. It still gets the same errors with RtMidi. The same .h is also on github.
Comment 17 Alex Bylund 2023-02-14 23:56:46 UTC
Created attachment 240164 [details]
Good MIDI support patch

The problem was MilkyTracker was being compiled with C++98, and the RtMidi lib must have upgraded because I was building with 4.0.0. Thankfully, MilkyTracker is good with the newer standard.
Comment 18 Tatsuki Makino 2023-02-15 05:44:37 UTC
(In reply to Emanuel Haupt from comment #4)
(In reply to Emanuel Haupt from comment #15)

You may also want to call hselasky@FreeBSD, maybe :)

It seems to me that MIDI in milkytracker would require audio/alsa-seq-server, since it appears to go through ALSA.
If so...
Additionally, if MIDI hardware is not had, install audio/fluidsynth with the option ALSA enabled.

Fluidsynth requires audio/fluid-soundfont to be installed in order to output sound.
Create the following symlink to omit the setting of the fluidsynth sound font.
${LOCALBASE}/share/soundfonts/default.sf2 -> ../sounds/sf2/FluidR3_GM.sf2

audio/alsa-utils is used to check if MIDI can be played in ALSA.

I thought the following command would make it possible to play the rest.

service alsa_seq_server onestart
fluidsynth -a oss -m alsa_seq -i -s &
aconnect -l -i -o # check port of fluidsynth
aplaymidi -p 1 some_GM.mid

Note that alsa-seq-server cannot convey system exclusives longer than pointer size to software MIDI.
Probably something like this.
Comment 19 Alex Bylund 2023-02-15 13:30:36 UTC
(In reply to Tatsuki Makino from comment #18)

Based from the documentation that level of detail would be on each user's part.
Comment 20 Tatsuki Makino 2023-02-23 04:39:39 UTC
Created attachment 240337 [details]
proposed patch for audio/rtmidi

(In reply to notbylundzander from comment #19)

I have looked into how to use this software.
As a result, this appears to have only MIDI input.
Therefore, comment #18 is almost irrelevant :)

And since RtMidi currently only supports JACK, it is necessary to be able to use a MIDI device with JACK.
With the attachment I have brought here, RtMidi will be adding ALSA support.
There is also an option to remove JACK, as MilkyTracker has no way to select a MIDI device and uses JACK preferentially, with the behavior of falling down to ALSA when it fails.

audio/milkytracker is fine with the patch as per attachment 240164 [details].
If MilkyTracker is to receive MIDI input via ALSA, it must be pre-existed by some MIDI device that will be displayed when aconnect -i is run.
If you tap the space key on the PC keyboard while the cursor in the middle dot-encrusted area is at the leftmost position, and when the MIDI device sends some note message, the note is entered successfully.

Again, MIDI does not seem to have anything to do with whether or not sound comes out of the speakers.
Comment 21 Alex Bylund 2023-02-23 14:30:20 UTC
The MIDI input port is only listening and receiving MIDI signals. Different software has the ability to change how all the ports are configured. MilkyTracker outputs sound so nothing else is needed. All it's doing is allowing an external keyboard device to control the internal keyboard device. It can be a hardware keyboard or a virtual one. 

MIDI ports can be configured to multiple ports at the same time, so using multiple outputs from the same input is optional.

I'm currently using alsa-seq-server. No changes need to be done to RtMidi, unless a different configuration is needed. Which I imagine would be support for more software.
Comment 22 Tatsuki Makino 2023-02-23 23:03:56 UTC
(In reply to notbylundzander from comment #21)

> It can be a hardware keyboard or a virtual one.

What software keyboards work via JACK on FreeBSD?

For now, it seems that if we don't use the attachment 240337 [details] patch, audio/a2jmidid will allow us to use MIDI through ALSA with MilkyTracker.
2 commands are required before MilkyTracker can be started.

jack_control start
a2j_control --start

This means that I have confirmed that it works at mine.

vmpk(audio/vmpk) -> alsa-seq-server -> a2jmidid(audio/a2jmidid) -> jackdbus -> MilkyTracker(attachment 240164 [details] patched)
Comment 23 Alex Bylund 2023-02-24 02:23:53 UTC
(In reply to Tatsuki Makino from comment #22)

I don't know, it all seems irrelevant to me. I'm just the guy that wants the MIDI input port for the Installathon.
Comment 24 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-25 13:29:53 UTC
The patches LGTM. Yuri, what about the rtmidi patch? Would you like a separate PR for that? The rtmidi patch should probably be committed first.
Comment 25 Tatsuki Makino 2023-02-25 21:38:31 UTC
Umm, please ignore the rtmidi patch in my attachment 240337 [details].
As long as JACK finds a MIDI device, there seems to be no problem. maybe :)

notbylundzander's attachment 240164 [details] has logic problems that cannot be solved by substituting Linux for FreeBSD.
The choices are...
MIDI option, but turn it on all the time.
Because when alsa, or any rtmidi that depends on jack, is installed in the environment, those libraries are linked.
It seems to me that we need to consider the use of something like CMAKE_DISABLE_FIND_PACKAGE_ALSA, CMAKE_DISABLE_FIND_PACKAGE_JACK or CMAKE_DISABLE_FIND_PACKAGE_RTMIDI.
Comment 26 Alex Bylund 2023-02-27 08:08:40 UTC
Created attachment 240437 [details]
Good MIDI support patch fix

That part of the logic is only used to add MIDI. Now instead of changing the system name it's just changed with a CMAKE option.
Comment 27 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-27 08:23:49 UTC
(In reply to notbylundzander from comment #26)
Your patch doesn't apply cleanly:

> patch: **** malformed patch at line 26:  PORTSCOUT=     ignore:1

Could you maybe re-create your patch with:

$ git diff > /tmp/foo.patch
Comment 28 Alex Bylund 2023-02-27 18:31:18 UTC
Created attachment 240457 [details]
MIDI via rtmidi patch

Thanks. Here is the remade patch.
Comment 29 commit-hook freebsd_committer freebsd_triage 2023-02-28 21:01:22 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c14e8a660992114f8bbcf8523dd566b317da392c

commit c14e8a660992114f8bbcf8523dd566b317da392c
Author:     Emanuel Haupt <ehaupt@FreeBSD.org>
AuthorDate: 2023-02-28 20:59:52 +0000
Commit:     Emanuel Haupt <ehaupt@FreeBSD.org>
CommitDate: 2023-02-28 21:00:30 +0000

    audio/milkytracker: Add MIDI support

    While here pacify portfmt, portclippy.

    PR:             269106
    Submitted by:   notbylundzander@gmail.com

 audio/milkytracker/Makefile                        | 27 +++++++++++++---------
 .../milkytracker/files/patch-CMakeLists.txt (new)  | 20 ++++++++++++++++
 2 files changed, 36 insertions(+), 11 deletions(-)
Comment 30 Emanuel Haupt freebsd_committer freebsd_triage 2023-02-28 21:02:13 UTC
Committed, thanks!