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

Get TagLib 2.0.1 working #143

Merged
merged 5 commits into from
Apr 17, 2024
Merged

Get TagLib 2.0.1 working #143

merged 5 commits into from
Apr 17, 2024

Conversation

jacobvosmaer
Copy link
Collaborator

This pulls together various commits into something reasonably clean that:

  • uses TagLib 2.0.1
  • passes our test suite

@jacobvosmaer
Copy link
Collaborator Author

@robinst what do you think about merging main into taglib-2? That would shrink this PR to about 4-5 commits.

@jacobvosmaer jacobvosmaer force-pushed the jv-taglib-2 branch 2 times, most recently from 434d8a7 to 6be8db5 Compare April 11, 2024 11:43
@jacobvosmaer
Copy link
Collaborator Author

This isn't quite there yet; we need to fix _wrap_picture_type_to_string so that it doesn't return TagLib::String but a Ruby string instead (and vice versa).

@jacobvosmaer
Copy link
Collaborator Author

This isn't quite there yet; we need to fix _wrap_picture_type_to_string so that it doesn't return TagLib::String but a Ruby string instead (and vice versa).

I think I fixed this now by replacing a lot of #include <taglib/tpicturetype.h> lines with a few targeted %include <taglib/tpicturetype.h>.

@jacobvosmaer jacobvosmaer force-pushed the jv-taglib-2 branch 4 times, most recently from 5962a86 to a60bfb4 Compare April 11, 2024 14:06
@jacobvosmaer
Copy link
Collaborator Author

Still not sure if I'm handling TagLib::offset_t correctly. TagLib uses an ifdef to define it at compile time (its definition depends on whether we're on WIN32). But Swig runs before compile time so what do we tell it?

For now I have told Swig to use long long.

@robinst
Copy link
Owner

robinst commented Apr 11, 2024

@robinst what do you think about merging main into taglib-2? That would shrink this PR to about 4-5 commits.

Sounds good. Also fine with rebasing if that's easier.

jacobvosmaer and others added 3 commits April 11, 2024 17:51
This will help with the switch to TagLib 2 because that version has a
dependency in a Git submodule.
@jacobvosmaer jacobvosmaer force-pushed the jv-taglib-2 branch 2 times, most recently from bbdd6ed to c06a8ec Compare April 11, 2024 15:55
Copy link
Collaborator Author

@jacobvosmaer jacobvosmaer left a comment

Choose a reason for hiding this comment

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

I wrote some note about the changes.

@@ -20,6 +20,7 @@

// Ignore IOStream and all the constructors using it.
%ignore IOStream;
%ignore TagLib::RIFF::AIFF::File::File(IOStream *, bool, Properties::ReadStyle, ID3v2::FrameFactory *);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a new constructor we have to ignore because it uses IOStream.

@@ -26,6 +26,7 @@ namespace TagLib {
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
using offset_t = long long;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems to do the job of telling Swig that offset_t is an integer type and not a C++ object. On platforms where offset_t is smaller than long long, this will use an intermediate long long variable before converting to offset_t.

@@ -3211,17 +3325,19 @@ _wrap_File_find__SWIG_0(int argc, VALUE *argv, VALUE self) {
tmp2 = ruby_string_to_taglib_bytevector(argv[0]);
arg2 = &tmp2;
}
ecode3 = SWIG_AsVal_long(argv[1], &val3);
ecode3 = SWIG_AsVal_long_SS_long(argv[1], &val3);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an example of how the Swig definition of offset_t as long long turns out. First Swig converts a ruby object argv[1] to a long long stored in val3.

}
arg3 = static_cast< long >(val3);
arg3 = static_cast< TagLib::offset_t >(val3);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here long long val3 is cast to TagLib::offset_t arg3.

vresult = SWIG_From_long(static_cast< long >(result));
result = (TagLib::offset_t)(arg1)->find((TagLib::ByteVector const &)*arg2,arg3,(TagLib::ByteVector const &)*arg4);
{
vresult = taglib_offset_t_to_ruby_int(result);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the way out, an offset_t value is passed to our taglib_offset_t_to_ruby_int function which uses the Ruby LL2NUM or OFFT2NUM macro depending on the compile constant _WIN32.

%freefunc TagLib::MP4::File "free_taglib_mp4_file";

// Ignore IOStream and all the constructors using it.
%ignore IOStream;
%ignore TagLib::MP4::File::File(IOStream *, bool, Properties::ReadStyle);
%ignore TagLib::MP4::File::File(IOStream *, bool, Properties::ReadStyle, ItemFactory *);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another new constructor for us to ignore.

@@ -14,6 +14,7 @@
%ignore TagLib::MPEG::Header::operator=;
%include <taglib/xingheader.h>

%include <taglib/id3v2.h>
%include <taglib/mpegheader.h>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As before in id3v2.i we need this new header file.

@@ -30,6 +31,10 @@
%ignore TagLib::MPEG::File::File(IOStream *, ID3v2::FrameFactory *, bool, Properties::ReadStyle);
%ignore TagLib::MPEG::File::File(IOStream *, ID3v2::FrameFactory *, bool);
%ignore TagLib::MPEG::File::File(IOStream *, ID3v2::FrameFactory *);
%ignore TagLib::MPEG::File::File(IOStream *, bool, Properties::ReadStyle, ID3v2::FrameFactory *);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More ignored IOStream constructors.

@@ -4,8 +4,6 @@
#include <taglib/oggfile.h>
#include <taglib/flacpicture.h>
#include <taglib/xiphcomment.h>
// Help find FLAC::
using namespace TagLib;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Everything still works without this line.

@@ -4,7 +4,7 @@
#include <taglib/wavfile.h>
#include <taglib/wavproperties.h>
#include <taglib/id3v2tag.h>
using namespace TagLib::RIFF;
using StripTags = TagLib::File::StripTags;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we're doing something wrong here. Swig is not "seeing" TagLib::File so it doesn't know what StripTags is. The proper solution would be to %include <taglib/rifffile.h> but then we run afoul of namespace flattening.

Maybe we need a separate .i for riff?

Since the test pass now, maybe we should fix this in a later PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I figured out how to do it, it was a matter of %ignore TagLib::RIFF::File.

@@ -14,12 +14,16 @@
%ignore TagLib::RIFF::AIFF::Properties::length;
%ignore TagLib::RIFF::AIFF::Properties::sampleWidth;

%ignore TagLib::RIFF::File;
%include <taglib/rifffile.h>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fixes a Swig warning:

Warning 401: Nothing known about base class 'TagLib::RIFF::File'. Ignored.

@@ -4,7 +4,6 @@
#include <taglib/wavfile.h>
#include <taglib/wavproperties.h>
#include <taglib/id3v2tag.h>
using namespace TagLib::RIFF;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I replaced this line with %include <taglib/rifffile.h> below.

@jacobvosmaer
Copy link
Collaborator Author

jacobvosmaer commented Apr 12, 2024

@ufleisch I have turned your patch from #129 (comment) into a commit in this PR, I hope that is OK. ee55a43

@robinst I think this PR is ready for review.

@ufleisch
Copy link
Contributor

@ufleisch I have turned your patch from #129 (comment) into a commit in this PR, I hope that is OK. ee55a43

I am not really a great help concerning Ruby and SWIG, so I am just trying to comment about what was discussed concerning TagLib:

  • The rationale behind offset_t is that we need 64-bit integers to work with large files. These offsets were long in TagLib 1.x, which was not a problem on 64-bit Linux because long has 64 bits there. However, on Windows, long is only 32 bits, also on 64-bit architectures, therefore, it was not possible to work with large files on Windows. off_t would be a good solution on POSIX, but it does not exist on Windows, therefore offset_t was introduced. If you use long long instead, this will be correct on 64-bit architectures.

  • It would be probably nice to support properties and complexProperties with taglib-ruby, these should be enough for most use cases, so users do not have to deal with the format specific classes.

@jacobvosmaer
Copy link
Collaborator Author

@ufleisch thanks for taking a look!

I didn't mean to complain about offset_t, I am just clueless about SWIG and I was trying to convince myself and @robinst that the current code correctly handles the ifdef. (It's too late now but I wonder if int64_t would have done what you wanted without needing an ifdef?)

Regarding the properties interfaces: I agree it would be good to support them for the reason you state. We never did until now because we wanted to remain compatible with older taglib 1.x versions that didn't have properties. The reason I'm letting SWIG ignore them in this PR is that I don't want to do too many things in one PR.

My main question was if you are OK with the fact that I made a commit with your name in it (by feeding the patch you posted to git am).

@ufleisch
Copy link
Contributor

My main question was if you are OK with the fact that I made a commit with your name in it (by feeding the patch you posted to git am).

Of course this is OK, thanks for all your work!

Copy link
Owner

@robinst robinst left a comment

Choose a reason for hiding this comment

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

Changes LGTM! Great work, and thanks to @ufleisch for the help too!

I'll let you merge this one first, then I'll have a look at #129 later to resolve any conflicts.

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.

3 participants