diff --git a/src/actions.cc b/src/actions.cc index f08bdff..cc1efd4 100644 --- a/src/actions.cc +++ b/src/actions.cc @@ -1,56 +1,61 @@ -#include "ogg.h" - -// Here we're going to illustrate how to use the ogg module. +#include "actions.h" using namespace opustags; -enum StreamSelection { - ALL_STREAMS = -1, - FIRST_STREAM = -2, -}; - -void list_tags(ogg::Decoder *reader, long select) +void opustags::list_tags(ogg::Decoder &dec, TagsHandler &handler) { - 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; - } - } + ogg::Stream *s; + while (!handler.done()) { + s = dec.read_page(); + if (s == NULL) + break; // end of stream + switch (s->state) { + case ogg::HEADER_READY: + if (!handler.relevant(s->stream.serialno)) + s->downgrade(); + break; + case ogg::TAGS_READY: + handler.list(s->stream.serialno, s->tags); + break; + default: + ; + } + } } -void delete_tags(ogg::Decoder *reader, opustags::ogg::Encoder *writer, long select) +void opustags::edit_tags(ogg::Decoder &in, ogg::Encoder &out, TagsHandler &handler) { - 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(reader->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(reader->current_page); - break; - default: - ; - } - } + ogg::Stream *s; + while (true) { + s = in.read_page(); + if (s == NULL) + break; // end of stream + switch (s->state) { + + case ogg::HEADER_READY: + if (!handler.relevant(s->stream.serialno)) { + s->downgrade(); + out.write_raw_page(in.current_page); + } else { + out.write_page(in.current_page); + } + break; + + case ogg::TAGS_READY: + handler.edit(s->stream.serialno, s->tags); + out.write_tags(s->stream.serialno, s->tags); + break; + + case ogg::DATA_READY: + out.write_page(in.current_page); + break; + + case ogg::RAW_READY: + out.write_raw_page(in.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/actions.h b/src/actions.h index 6cb021f..8836df9 100644 --- a/src/actions.h +++ b/src/actions.h @@ -1,12 +1,10 @@ #pragma once +#include "tags.h" #include "ogg.h" namespace opustags { - // To be defined properly somewhere. - class Tags; - // TagsHandler define various operations related to tags and stream in // order to control the main loop. // In its implementation, it is expected to receive an option structure. diff --git a/src/ogg.h b/src/ogg.h index 5631e47..740dff0 100644 --- a/src/ogg.h +++ b/src/ogg.h @@ -5,11 +5,11 @@ #include #include +#include "tags.h" + namespace opustags { namespace ogg { - typedef std::map Tags; - enum StreamState { BEGIN_OF_STREAM, HEADER_READY, diff --git a/src/tags.h b/src/tags.h new file mode 100644 index 0000000..56be00b --- /dev/null +++ b/src/tags.h @@ -0,0 +1,8 @@ +#pragma once + +namespace opustags { + + class Tags { + }; + +}