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

Haiku port #1490

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Haiku port #1490

wants to merge 7 commits into from

Conversation

mmuman
Copy link

@mmuman mmuman commented Feb 16, 2025

It seems we had patches getting dust. I rebased them and dropped stuff that didn't seem needed anymore.
All tests pass though I haven't tried the audio or MIDI outputs, but the code worked in previous versions.

@mmuman
Copy link
Author

mmuman commented Feb 16, 2025

Ugh, seems they missed the proper Haiku check 🤷

@mmuman
Copy link
Author

mmuman commented Feb 16, 2025

That should fix it.

@mmuman
Copy link
Author

mmuman commented Feb 16, 2025

For some reason tests 25 & 27 fail now… !?

@mmuman
Copy link
Author

mmuman commented Feb 16, 2025

Oh, yeah… nothing LANC=C LC_ALL=C can't fix. (comma vs decimal point)

Copy link
Member

@derselbst derselbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting. However, this is not yet in a shape that is ready to accept. It needs some work. Comments below. Also, it would be very helpful to have a Haiku CI build in place, to avoid breaking stuff in the future.
Edit: Here's an example of how SDL coped with Haiku CI: libsdl-org/SDL#6739

include ( TestBigEndian )
test_big_endian ( WORDS_BIGENDIAN )
endif ( NOT HAIKU )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that if-ed out?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macros were broken on Haiku I believe.

# Haiku
if ( HAIKU )
set ( CMAKE_CXX_FLAGS "-fpermissive")
endif ( HAIKU )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that needed?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it was needed because the compiler would start spitting out errors for what was seemingly valid C++ code for non-permissive builds.

message ( "Haiku MediaKit support: yes" )
else ( HAIKU_SUPPORT )
message ( "Haiku MediaKit support: no" )
endif ( HAIKU_SUPPORT )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant to above and should be removed.

@@ -94,6 +94,8 @@ option ( enable-dsound "compile DirectSound support (if it is available)" on )
option ( enable-wasapi "compile Windows WASAPI support (if it is available)" on )
option ( enable-waveout "compile Windows WaveOut support (if it is available)" on )
option ( enable-winmidi "compile Windows MIDI support (if it is available)" on )
option ( enable-haiku "compile Haiku MediaKit audio support (if it is available)" on )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
option ( enable-haiku "compile Haiku MediaKit audio support (if it is available)" on )
option ( enable-mediakit "compile Haiku MediaKit audio support (if it is available)" on )

IMO, the naming is unfortunate. enable-haiku would enable the audio driver and not support for Haiku in general. I'd suggest to rename it mediakit.

@@ -94,6 +94,8 @@ option ( enable-dsound "compile DirectSound support (if it is available)" on )
option ( enable-wasapi "compile Windows WASAPI support (if it is available)" on )
option ( enable-waveout "compile Windows WaveOut support (if it is available)" on )
option ( enable-winmidi "compile Windows MIDI support (if it is available)" on )
option ( enable-haiku "compile Haiku MediaKit audio support (if it is available)" on )
option ( enable-midikit2 "compile Haiku MidiKit2 MIDI support (if it is available)" on )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of these cmake options should be wraped inside a if ( CMAKE_SYSTEM MATCHES "Haiku" ), as we do it below, since they are platform-specific options.

driver->m_consumer->Release();
delete_fluid_midi_parser(driver->parser);
FLUID_FREE(driver);
return NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're leaking driver->m_consumer here. Pls. avoid these manual partial cleanup logic and instead, properly do the cleanup in delete_fluid_midikit2_driver

driver->m_consumer->Unregister();
driver->m_consumer->Release();
delete_fluid_midi_parser(driver->parser);
FLUID_FREE(driver);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're leaking driver->m_consumer.

Copy link
Author

@mmuman mmuman Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release() will delete it by itself as it's ref-counted. I'll add a comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how is it supposed to know that m_consumer (an instance of fluid_midikit2_input) was allocated via new? And not via new[]? And not on the stack either?? I have no doubt that Release() will cleanup the internal state of the BMidiEndpoint object (i.e. all the things that were ref-counted allocated in its constructor). But it surely cannot release the memory of the derived fluid_midikit2_input, esp. because fluid_midikit2_input currently has a non-virtual destructor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meanwhile I discovered the implementation of BMidiEndpoint: https://github.com/haiku/haiku/blob/c8252422b8b3a2a293fb3be039eec6f87b30b467/src/kits/midi2/MidiEndpoint.cpp#L118-L135

So it turns out that they do make a hard call to delete this. If you used new[] to allocate the endpoint this will cause undefined behavior. And if you stack allocated this you might get a log message: https://github.com/haiku/haiku/blob/c8252422b8b3a2a293fb3be039eec6f87b30b467/src/kits/midi2/MidiEndpoint.cpp#L258-L260

Poor implementation, IMO. But still: You must declare an empty destructor for fluid_midikit2_input and mark it virtual to make this cleanup work as intended.

Comment on lines +226 to +239
char midiSettings[PATH_MAX] = "";
if (find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, midiSettings, sizeof(midiSettings)) == B_OK) {
strcat(midiSettings, "/Media/midi_settings");
if( access( midiSettings, F_OK ) != -1 ) {
FILE *inFile = fopen(midiSettings, "rt");
if (inFile) {
char sf2file[PATH_MAX];
if (fscanf(inFile, "# Midi\n\tsoundfont \"%[^\"]\"", sf2file)) {
fluid_settings_register_str(settings, "synth.default-soundfont", sf2file, 0);
}
fclose(inFile);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does that do??

Copy link
Author

@mmuman mmuman Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemingly fetches the first path to the sound fonts from the Media preferences, as it is used internally.

@mmuman
Copy link
Author

mmuman commented Feb 17, 2025

Thanks for submitting. However, this is not yet in a shape that is ready to accept. It needs some work. Comments below.

Well I didn't write most of this code, just trying to upstream before it bit-rots, so I'll have to figure it out as well.

Also, it would be very helpful to have a Haiku CI build in place, to avoid breaking stuff in the future.
Edit: Here's an example of how SDL coped with Haiku CI: libsdl-org/SDL#6739

Yes, though our cross-compiler is only built as part of our build system, but there are a few solutions now.

@mmuman
Copy link
Author

mmuman commented Feb 17, 2025

poke @Cacodemon345 @threedeyes :-)

@Cacodemon345
Copy link

I can't directly push to the branch (and I don't have a working Haiku OS installation at the moment either at the moment to help out with the changes).

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

Successfully merging this pull request may close these issues.

4 participants