Skip to content

Commit

Permalink
Fix build with TagLib 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ufleisch authored and jacobvosmaer committed Apr 11, 2024
1 parent ed827e7 commit ee55a43
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 23 deletions.
2 changes: 2 additions & 0 deletions ext/taglib_aiff/taglib_aiff.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <taglib/aifffile.h>
#include <taglib/aiffproperties.h>
#include <taglib/id3v2tag.h>
#include <taglib/tpicturetype.h>
using namespace TagLib;
%}

%include "../taglib_base/includes.i"
Expand Down
22 changes: 8 additions & 14 deletions ext/taglib_base/includes.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define TAGLIB_IGNORE_MISSING_DESTRUCTOR
#define TAGLIB_DEPRECATED
#define TAGLIB_MSVC_SUPPRESS_WARNING_NEEDS_TO_HAVE_DLL_INTERFACE
%include <taglib/tpicturetype.h>

// Replaces the typemap from swigtype.swg and just adds the line
// SWIG_RubyUnlinkObjects. This is done to be safe in the case when a
Expand All @@ -24,6 +25,7 @@
#include <taglib/tbytevector.h>
#include <taglib/tbytevectorlist.h>
#include <taglib/tfile.h>
#include <taglib/tvariant.h>

#if defined(HAVE_RUBY_ENCODING_H) && HAVE_RUBY_ENCODING_H
# include <ruby/encoding.h>
Expand All @@ -37,34 +39,26 @@
#endif

VALUE taglib_bytevector_to_ruby_string(const TagLib::ByteVector &byteVector) {
if (byteVector.isNull()) {
return Qnil;
} else {
return rb_str_new(byteVector.data(), byteVector.size());
}
return rb_str_new(byteVector.data(), byteVector.size());
}

TagLib::ByteVector ruby_string_to_taglib_bytevector(VALUE s) {
if (NIL_P(s)) {
return TagLib::ByteVector::null;
return TagLib::ByteVector();
} else {
return TagLib::ByteVector(RSTRING_PTR(StringValue(s)), RSTRING_LEN(s));
}
}

VALUE taglib_string_to_ruby_string(const TagLib::String & string) {
if (string.isNull()) {
return Qnil;
} else {
VALUE result = rb_str_new2(string.toCString(true));
ASSOCIATE_UTF8_ENCODING(result);
return result;
}
VALUE result = rb_str_new2(string.toCString(true));
ASSOCIATE_UTF8_ENCODING(result);
return result;
}

TagLib::String ruby_string_to_taglib_string(VALUE s) {
if (NIL_P(s)) {
return TagLib::String::null;
return TagLib::String();
} else {
return TagLib::String(RSTRING_PTR(CONVERT_TO_UTF8(StringValue(s))), TagLib::String::UTF8);
}
Expand Down
4 changes: 4 additions & 0 deletions ext/taglib_base/taglib_base.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <taglib/tlist.h>
#include <taglib/fileref.h>
#include <taglib/tag.h>
#include <taglib/tpropertymap.h>
#include <taglib/tvariant.h>
#include <taglib/tpicturetype.h>
using namespace TagLib;
%}

%include "includes.i"
Expand Down
1 change: 1 addition & 0 deletions ext/taglib_flac/taglib_flac.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <taglib/flacproperties.h>
#include <taglib/id3v1tag.h>
#include <taglib/id3v2tag.h>
using namespace TagLib;
%}

%include "../taglib_base/includes.i"
Expand Down
2 changes: 2 additions & 0 deletions ext/taglib_id3v1/taglib_id3v1.i
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
%{
#include <taglib/id3v1tag.h>
#include <taglib/id3v1genres.h>
#include <taglib/tpicturetype.h>
using namespace TagLib;
%}

%include "../taglib_base/includes.i"
Expand Down
2 changes: 2 additions & 0 deletions ext/taglib_id3v2/taglib_id3v2.i
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <taglib/unknownframe.h>
#include <taglib/unsynchronizedlyricsframe.h>
#include <taglib/urllinkframe.h>
using namespace TagLib;
%}

%include "../taglib_base/includes.i"
Expand Down Expand Up @@ -81,6 +82,7 @@ VALUE taglib_id3v2_framelist_to_ruby_array(TagLib::ID3v2::FrameList *list) {
}
%}

%include <taglib/id3v2.h>
%include <taglib/id3v2header.h>

// Only useful internally.
Expand Down
2 changes: 2 additions & 0 deletions ext/taglib_mp4/taglib_mp4.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include <taglib/mp4properties.h>
#include <taglib/mp4tag.h>
#include <taglib/mp4atom.h>
#include <taglib/tpicturetype.h>
// To resolve some symbols, like AtomDataType in Item.
using namespace TagLib::MP4;
using namespace TagLib;
%}

%include "../taglib_base/includes.i"
Expand Down
2 changes: 2 additions & 0 deletions ext/taglib_mpeg/taglib_mpeg.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <taglib/mpegproperties.h>
#include <taglib/mpegfile.h>
#include <taglib/id3v2tag.h>
#include <taglib/tpicturetype.h>
using namespace TagLib;
%}

%include "../taglib_base/includes.i"
Expand Down
7 changes: 7 additions & 0 deletions ext/taglib_wav/taglib_wav.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include <taglib/wavfile.h>
#include <taglib/wavproperties.h>
#include <taglib/id3v2tag.h>
#include <taglib/tpicturetype.h>
using namespace TagLib::RIFF;
using namespace TagLib;
using StripTags = TagLib::File::StripTags;
%}

%include "../taglib_base/includes.i"
Expand Down Expand Up @@ -55,7 +58,11 @@ namespace TagLib {
static void free_taglib_riff_wav_file(void *ptr) {
TagLib::RIFF::WAV::File *file = (TagLib::RIFF::WAV::File *) ptr;

#if TAGLIB_MAJOR_VERSION >= 2
TagLib::ID3v2::Tag *id3v2tag = file->ID3v2Tag();
#else
TagLib::ID3v2::Tag *id3v2tag = file->tag();
#endif
if (id3v2tag) {
TagLib::ID3v2::FrameList frames = id3v2tag->frameList();
for (TagLib::ID3v2::FrameList::ConstIterator it = frames.begin(); it != frames.end(); it++) {
Expand Down
1 change: 1 addition & 0 deletions tasks/ext.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ taglib_url = "https://github.com/taglib/taglib/archive/v#{Build.version}.tar.gz"
taglib_options = ['-DCMAKE_BUILD_TYPE=Release',
'-DBUILD_EXAMPLES=OFF',
'-DBUILD_TESTS=OFF',
'-DBUILD_TESTING=OFF', # used since 1.13 instead of BUILD_TESTS
'-DBUILD_BINDINGS=OFF', # 1.11 builds bindings by default
'-DBUILD_SHARED_LIBS=ON', # 1.11 builds static by default
'-DWITH_MP4=ON', # WITH_MP4, WITH_ASF only needed with taglib 1.7, will be default in 1.8
Expand Down
2 changes: 1 addition & 1 deletion test/id3v2_write_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def reloaded(&block)
end

should 'be able to save ID3v2.3' do
success = @file.save(TagLib::MPEG::File::ID3v2, true, 3)
success = @file.save(TagLib::MPEG::File::ID3v2, TagLib::File::StripOthers, TagLib::ID3v2::V3)
assert_equal true, success
@file.close
@file = nil
Expand Down
2 changes: 1 addition & 1 deletion test/wav_examples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WAVExamples < Test::Unit::TestCase

# Saving ID3v2 cover-art to disk
TagLib::RIFF::WAV::File.open("#{DATA_FILE_PREFIX}sample.wav") do |file|
id3v2_tag = file.tag
id3v2_tag = file.id3v2_tag
cover = id3v2_tag.frame_list('APIC').first
ext = cover.mime_type.rpartition('/')[2]
File.open("#{DATA_FILE_PREFIX}cover-art.#{ext}", 'wb') { |f| f.write cover.picture }
Expand Down
2 changes: 1 addition & 1 deletion test/wav_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class WAVFileTest < Test::Unit::TestCase

context 'ID3V2 tag' do
setup do
@tag = @file.tag
@tag = @file.id3v2_tag
end

should 'exist' do
Expand Down
12 changes: 6 additions & 6 deletions test/wav_file_write_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ def reloaded(&block)
end

should 'have one picture frame' do
assert_equal 2, @file.tag.frame_list('APIC').size
assert_equal 2, @file.id3v2_tag.frame_list('APIC').size
end

should 'be able to remove all picture frames' do
@file.tag.remove_frames('APIC')
@file.id3v2_tag.remove_frames('APIC')
success = @file.save
assert success
@file.close
@file = nil

reloaded do |file|
assert_equal 0, file.tag.frame_list('APIC').size
assert_equal 0, file.id3v2_tag.frame_list('APIC').size
end
end

Expand All @@ -58,18 +58,18 @@ def reloaded(&block)
apic.picture = picture_data
apic.type = TagLib::ID3v2::AttachedPictureFrame::BackCover

@file.tag.add_frame(apic)
@file.id3v2_tag.add_frame(apic)
success = @file.save
assert success
@file.close
@file = nil

reloaded do |file|
assert_equal 3, file.tag.frame_list('APIC').size
assert_equal 3, file.id3v2_tag.frame_list('APIC').size
end

reloaded do |file|
written_apic = file.tag.frame_list('APIC')[2]
written_apic = file.id3v2_tag.frame_list('APIC')[2]
assert_equal 'image/jpeg', written_apic.mime_type
assert_equal 'desc', written_apic.description
assert_equal picture_data, written_apic.picture
Expand Down

0 comments on commit ee55a43

Please sign in to comment.