implementation of list_tags and edit_tags (actions)

This commit is contained in:
Frédéric Mangano
2016-02-23 10:31:59 +01:00
parent 6baf120a94
commit c2d6763e2b
4 changed files with 64 additions and 53 deletions

View File

@ -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

View File

@ -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.

View File

@ -5,11 +5,11 @@
#include <map>
#include <ogg/ogg.h>
#include "tags.h"
namespace opustags {
namespace ogg
{
typedef std::map<std::string, std::string> Tags;
enum StreamState {
BEGIN_OF_STREAM,
HEADER_READY,

8
src/tags.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
namespace opustags {
class Tags {
};
}