Skip to content

Commit

Permalink
add c++ code to create/update tags in a WAV file
Browse files Browse the repository at this point in the history
also add c++ code to dump tags from a WAV file
remove ruby code to create tags in a WAV file
  • Loading branch information
Thomas Chevereau committed Jul 30, 2014
1 parent 8dce8fe commit 2dff3e3
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ Makefile
/test/data/id3v1-create
/test/data/vorbis-create
/test/data/mp4-create
/test/data/wav-create
/test/data/wav-dump
3 changes: 2 additions & 1 deletion taglib-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ DESC
"test/data/unicode.mp3",
"test/data/vorbis-create.cpp",
"test/data/vorbis.oga",
"test/data/wav-create.rb",
"test/data/wav-create.cpp",
"test/data/wav-dump.cpp",
"test/data/wav-sample.wav",
"test/aiff_examples_test.rb",
"test/aiff_file_test.rb",
Expand Down
10 changes: 8 additions & 2 deletions test/data/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all clean

all:: add-relative-volume id3v1-create vorbis-create flac-create mp4-create
all:: add-relative-volume id3v1-create vorbis-create flac-create mp4-create wav-create wav-dump

add-relative-volume: add-relative-volume.cpp
g++ -o $@ $< -ltag -I/usr/include/taglib
Expand All @@ -17,5 +17,11 @@ flac-create: flac-create.cpp
mp4-create: mp4-create.cpp
g++ -o $@ $< -ltag -I/usr/include/taglib

wav-create: wav-create.cpp
g++ -o $@ $< -ltag -I/usr/include/taglib

wav-dump: wav-dump.cpp
g++ -o $@ $< -ltag -I/usr/include/taglib

clean::
-rm add-relative-volume id3v1-create vorbis-create flac-create mp4-create
-rm add-relative-volume id3v1-create vorbis-create flac-create mp4-create wav-create wav-dump
55 changes: 55 additions & 0 deletions test/data/wav-create.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <taglib/taglib.h>
#include <taglib/wavfile.h>
#include <taglib/wavproperties.h>
#include <taglib/attachedpictureframe.h>

#include "get_picture_data.cpp"

using namespace TagLib;


int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "usage: " << argv[0] << " file.wav" << std::endl;
exit(1);
}
char *filename = argv[1];

RIFF::WAV::File file(filename);
ID3v2::Tag *tag = file.tag();

tag->setArtist("WAV Dummy Artist Name");
tag->setAlbum("WAV Dummy Album Title");
tag->setTitle("WAV Dummy Track Title");
tag->setTrack(5);
tag->setYear(2014);
tag->setGenre("Jazz");
tag->setComment("WAV Dummy Comment");

tag->removeFrames("APIC");

ByteVector picture_data;
ID3v2::AttachedPictureFrame *apic;

picture_data = getPictureData("globe_east_540.jpg");
apic = new ID3v2::AttachedPictureFrame();
apic->setPicture(picture_data);
apic->setMimeType("image/jpeg");
apic->setType(ID3v2::AttachedPictureFrame::FrontCover);
apic->setDescription("WAV Dummy Front Cover-Art");
apic->setTextEncoding(String::UTF8);
tag->addFrame(apic);

picture_data = getPictureData("globe_east_90.jpg");
apic = new ID3v2::AttachedPictureFrame();
apic->setPicture(picture_data);
apic->setMimeType("image/jpeg");
apic->setType(ID3v2::AttachedPictureFrame::Other);
apic->setDescription("WAV Dummy Thumbnail");
apic->setTextEncoding(String::UTF8);
tag->addFrame(apic);

file.save();
}

// vim: set filetype=cpp sw=2 ts=2 expandtab:
104 changes: 0 additions & 104 deletions test/data/wav-create.rb

This file was deleted.

74 changes: 74 additions & 0 deletions test/data/wav-dump.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <taglib/taglib.h>
#include <taglib/wavfile.h>
#include <taglib/wavproperties.h>
#include <taglib/attachedpictureframe.h>

using namespace TagLib;


void dump_id3v2(ID3v2::Tag *tag)
{
if (!tag || tag->isEmpty())
{
std::cout << " NO TAGS" << std::endl;
return;
}

std::cout << " ID3v2." << tag->header()->majorVersion() << "." << tag->header()->revisionNumber() << std::endl;
std::cout << " title: '" << tag->title() << "'" << std::endl;
std::cout << " artist: '" << tag->artist() << "'" << std::endl;
std::cout << " album: '" << tag->album() << "'" << std::endl;
std::cout << " track: " << tag->track() << std::endl;
std::cout << " year: " << tag->year() << std::endl;
std::cout << " genre: '" << tag->genre() << "'" << std::endl;
std::cout << " comment: '" << tag->comment() << "'" << std::endl;

std::cout << " Frames" << std::endl;
const ID3v2::FrameList frameList = tag->frameList();
for(ID3v2::FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); ++it)
std::cout << " " << (*it)->frameID() << " - " << (*it)->toString() << std::endl;

const ID3v2::FrameList apicList = tag->frameList("APIC");
for(ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it)
{
const ID3v2::AttachedPictureFrame *apic = static_cast<ID3v2::AttachedPictureFrame *>(*it);
std::cout << " Picture" << std::endl;
std::cout << " type: " << apic->type() << std::endl;
std::cout << " mime_type: '" << apic->mimeType() << "'" << std::endl;
std::cout << " description: '" << apic->description() << "'" << std::endl;
std::cout << " size: " << apic->picture().size() << " bytes" << std::endl;
}
}

void dump_audio_properties(AudioProperties *properties)
{
std::cout << " Audio Properties" << std::endl;
std::cout << " length: " << properties->length() << " (seconds)" << std::endl;
std::cout << " bitrate: " << properties->bitrate() << " (kbits/sec)" << std::endl;
std::cout << " sample_rate: " << properties->sampleRate() << " (Hz)" << std::endl;
std::cout << " channels: " << properties->channels() << std::endl;
}

void dump_wav_properties(RIFF::WAV::Properties *properties)
{
std::cout << " WAV-specific Properties" << std::endl;
std::cout << " sample_width: " << properties->sampleWidth() << " (bits)" << std::endl;
}

int main(int argc, char **argv) {
if (argc != 2) {
std::cout << "usage: " << argv[0] << " file.wav" << std::endl;
exit(1);
}
char *filename = argv[1];

std::cout << "WAV file '" << filename << "'..." << std::endl;

RIFF::WAV::File file(filename);

dump_id3v2(file.tag());
dump_audio_properties(file.audioProperties());
dump_wav_properties(file.audioProperties());
}

// vim: set filetype=cpp sw=2 ts=2 expandtab:

0 comments on commit 2dff3e3

Please sign in to comment.