Skip to content

Commit fdb7c08

Browse files
committed
Added all files that currently exist
1 parent 140e697 commit fdb7c08

File tree

7 files changed

+141
-0
lines changed

7 files changed

+141
-0
lines changed

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
CC=g++
2+
CFLAGS=-Wall -Wextra \
3+
-I /Users/tavis.aitken/SourceCode/aif-project/cpp/taglib-1.7/include \
4+
-I /Users/tavis.aitken/SourceCode/aif-project/cpp/taglib-1.7 \
5+
-I /Users/tavis.aitken/SourceCode/aif-project/cpp/jsoncpp-src-0.5.0/include
6+
#-I /Users/tavis.aitken/SourceCode/aif-project/cpp/libjson/include \
7+
8+
LDFLAGS=-L /Users/tavis.aitken/SourceCode/aif-project/cpp/taglib-1.7/taglib -l tag \
9+
-L /Users/tavis.aitken/SourceCode/aif-project/cpp/jsoncpp-src-0.5.0/libs/linux-gcc-4.2.1 -l json_linux-gcc-4.2.1_libmt
10+
#-L /Users/tavis.aitken/SourceCode/aif-project/cpp/libjson/src -l json \
11+
12+
13+
all: main.o
14+
$(CC) $(LDFLAGS) main.o -o tagger
15+
16+
main.o: main.cpp
17+
$(CC) $(CFLAGS) -c main.cpp
18+
19+
clean: clean-o clean-bin clean-aif clean-json
20+
21+
clean-o:
22+
rm -vf *.o
23+
24+
clean-bin:
25+
rm -vf tagger
26+
27+
clean-aif:
28+
cp test/clean/clean.aif test/test.aif
29+
30+
clean-json:
31+
cp test/clean/clean.json test/test.json
32+
33+
run: clean all
34+
./tagger --file test/test.aif --tags test/test.json

main.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include <getopt.h>
2+
#include <iostream>
3+
#include <fstream>
4+
using namespace std;
5+
6+
/* TagLib */
7+
#include <aifffile.h>
8+
#include <id3v2header.h>
9+
#include <tag.h>
10+
#include <fileref.h>
11+
#include <tbytevector.h>
12+
13+
/* LibJson */
14+
#include <json/json.h>
15+
16+
17+
static struct option long_options[] = {
18+
{"help", no_argument, 0, 'h'},
19+
{"file", required_argument, 0, 'f'},
20+
{"tags", required_argument, 0, 't'},
21+
{0, 0, 0, 0}
22+
};
23+
24+
string read_file(string file_name)
25+
{
26+
ifstream input(file_name.c_str());
27+
string line;
28+
string contents;
29+
if (input.is_open()) {
30+
while (input.good()) {
31+
getline(input, line);
32+
contents += line;
33+
}
34+
input.close();
35+
} else {
36+
cerr << "File not found: " << file_name << endl;
37+
}
38+
return contents;
39+
}
40+
41+
void usage(char **argv)
42+
{
43+
cerr << "Usage: ./" << *argv << " -h --help -f --file [file] -t --tags [file]" << endl;
44+
}
45+
46+
int main(int argc, char **argv)
47+
{
48+
setlocale(LC_ALL, "");
49+
int return_code;
50+
int option_index = 0;
51+
string file_name;
52+
string tag_file;
53+
54+
while(42) {
55+
return_code = getopt_long(argc, argv, "hf:o:a:", long_options,
56+
&option_index);
57+
if(return_code == -1)
58+
break;
59+
60+
switch(return_code) {
61+
case 'h': /* --help */
62+
usage(argv);
63+
return 0;
64+
case 'f': /* --file*/
65+
cout << "Tagging file: " << optarg << endl;
66+
file_name = optarg;
67+
break;
68+
case 't': /* --file*/
69+
cout << "Using tag file: " << optarg << endl;
70+
tag_file = optarg;
71+
break;
72+
default: /* ??? */
73+
usage(argv);
74+
return 1;
75+
}
76+
}
77+
78+
Json::Value root; // will contains the root value after parsing.
79+
Json::Reader reader;
80+
81+
//string json_tags = read_file(tag_file);
82+
//json::Value *v = json::parse(json_tags);
83+
//json::Object *obj = dynamic_cast<json::Object *>(v);
84+
85+
//for (json::Object::const_iterator i = obj->begin(); i != obj->end(); ++i) {
86+
//if (i.key() == "tags") {
87+
//json::Object tags_obj = dynamic_cast<const json::Object &>(i.value());
88+
//for (json::Object::const_iterator j = tags_obj.begin(); j != tags_obj.end(); ++j) {
89+
//if (j->type() == json::TYPE_STRING) {
90+
//string tag_value = j.key() + " => " + dynamic_cast<const json::String &>(*j).value();
91+
//cout << tag_value << endl;
92+
//}
93+
//}
94+
//}
95+
//cout << i.key() << endl;
96+
//}
97+
98+
99+
TagLib::FileRef f(file_name.c_str());
100+
f.tag()->setAlbum("Album");
101+
f.tag()->setArtist("Foobar");
102+
f.save();
103+
104+
return 0;
105+
}

main.o

25.4 KB
Binary file not shown.

tagger

34.6 KB
Binary file not shown.

test/clean/clean.aif

57.3 KB
Binary file not shown.

test/clean/clean.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "tags": {"artist": "Artist from Json", "album": "Album from JSON"} }

test/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "tags": {"artist": "Artist from Json", "album": "Album from JSON"} }

0 commit comments

Comments
 (0)