From a8a6552f29dfa6f4f11f5d2bf66a82a2e802edf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Sat, 20 Feb 2016 13:20:49 +0100 Subject: [PATCH] sample main loops for ogg manipulation linking now breaks because the ogg module isn't implemented --- src/actions.cc | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ogg.h | 4 +++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/actions.cc diff --git a/src/actions.cc b/src/actions.cc new file mode 100644 index 0000000..0b07c70 --- /dev/null +++ b/src/actions.cc @@ -0,0 +1,56 @@ +#include "ogg.h" + +// Here we're going to illustrate how to use the ogg module. + +using namespace opustags; + +enum StreamSelection { + ALL_STREAMS = -1, + FIRST_STREAM = -2, +}; + +void list_tags(ogg::Reader *reader, long select) +{ + ogg::Stream *s; + while ((s = reader->read_page()) != NULL) { + if (s->state == ogg::TAGS_READY && (select == ALL_STREAMS || select == FIRST_STREAM || s->stream.serialno == select)) { + // print_tags(s->tags); + if (select != ALL_STREAMS) + break; + } + } +} + +void delete_tags(ogg::Reader *reader, opustags::ogg::Writer *writer, long select) +{ + ogg::Stream *s; + while ((s = reader->read_page()) != NULL) { + switch (s->state) { + case ogg::HEADER_READY: + // TODO what if select == FIRST_STREAM? + if (select != ALL_STREAMS && s->stream.serialno != select) + // act like nothing happened and copy this "unknown" stream identically + s->type = ogg::UNKNOWN_STREAM; + // fall through + case ogg::RAW_READY: + writer->write_raw_page(s->current_page); + break; + case ogg::TAGS_READY: + // only streams selected at HEADER_READY reach this point + writer->write_tags(s->stream.serialno, ogg::Tags()); + break; + case ogg::DATA_READY: + writer->write_page(s->current_page); + break; + default: + ; + } + } +} + +// To write edit_tags, we're gonna need something like the options structure in +// order to know what to do exactly. + +// The command-line interface has yet to be done, but it'd be nice it let the +// user edit several streams at once, like : +// $ opustags --stream 1 --set TITLE=Foo --stream 2 --set TITLE=Bar diff --git a/src/ogg.h b/src/ogg.h index 5099e11..6f04688 100644 --- a/src/ogg.h +++ b/src/ogg.h @@ -5,7 +5,8 @@ #include #include -namespace opustags::ogg +namespace opustags { +namespace ogg { typedef std::map Tags; @@ -89,3 +90,4 @@ namespace opustags::ogg std::map streams; }; } +}