summaryrefslogtreecommitdiff
path: root/plugins/liboggedit/oggedit_utils.c
blob: 2d40e275d4263a1173df7a2b7cdfcc898863f8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
  This file is part of Deadbeef Player source code
  http://deadbeef.sourceforge.net

  DeaDBeeF Ogg Edit library miscellaneous functions

  Copyright (C) 2014 Ian Nartowicz <deadbeef@nartowicz.co.uk>

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

uint8_t *oggedit_vorbis_channel_map(const int channel_count)
{
    size_t map_size = channel_count * sizeof(uint8_t);
    uint8_t *map = malloc(map_size);
    if (!map)
        return NULL;
    switch(channel_count) {
        case 3:
            return memcpy(map, &((uint8_t[]){0,2,1}), map_size);
        case 5:
            return memcpy(map, &((uint8_t[]){0,2,1,3,4}), map_size);
        case 6:
            return memcpy(map, &((uint8_t[]){0,2,1,4,5,3}), map_size);
        case 7:
            return memcpy(map, &((uint8_t[]){0,2,1,4,5,6,3}), map_size);
        case 8:
            return memcpy(map, &((uint8_t[]){0,2,1,6,7,4,5,3}), map_size);
        default:
            free(map);
            return NULL;
    }
}

const char *oggedit_map_tag(char *key, const char *in_or_out)
{
    typedef struct {
        const char *tag;
        const char *meta;
    } key_t;
    const key_t keys[] = {
        /* Permanent named tags in DeaDBeef */
//        {.tag = "ARTIST",         .meta = "artist"},
//        {.tag = "TITLE",          .meta = "title"},
//        {.tag = "ALBUM",          .meta = "album"},
        {.tag = "DATE",           .meta = "year"},
        {.tag = "TRACKNUMBER",    .meta = "track"},
        {.tag = "TRACKTOTAL",     .meta = "numtracks"},
//        {.tag = "GENRE",          .meta = "genre"},
//        {.tag = "COMPOSER",       .meta = "composer"},
        {.tag = "DISCNUMBER",     .meta = "disc"},
//        {.tag = "COMMENT",        .meta = "comment"},
        /* Vorbis standard tags */
//        {.tag = "ARRANGER",       .meta = "Arranger"},
//        {.tag = "AUTHOR",         .meta = "Author"},
//        {.tag = "CONDUCTOR",      .meta = "Conductor"},
//        {.tag = "ENSEMBLE",       .meta = "Ensemble"},
//        {.tag = "LYRICIST",       .meta = "Lyricist"},
//        {.tag = "PERFORMER",      .meta = "Performer"},
//        {.tag = "PUBLISHER",      .meta = "Publisher"},
//        {.tag = "DISCTOTAL",      .meta = "Disctotal"},
//        {.tag = "OPUS",           .meta = "Opus"},
//        {.tag = "PART",           .meta = "Part"},
//        {.tag = "PARTNUMBER",     .meta = "Partnumber"},
//        {.tag = "VERSION",        .meta = "Version"},
//        {.tag = "DESCRIPTION",    .meta = "Description"},
//        {.tag = "COPYRIGHT",      .meta = "Copyright"},
//        {.tag = "LICENSE",        .meta = "License"},
//        {.tag = "CONTACT",        .meta = "Contact"},
//        {.tag = "ORGANIZATION",   .meta = "Organization"},
//        {.tag = "LOCATION",       .meta = "Location"},
//        {.tag = "EAN/UPN",        .meta = "EAN/UPN"},
//        {.tag = "ISRC",           .meta = "ISRC"},
//        {.tag = "LABEL",          .meta = "Label"},
//        {.tag = "LABELNO",        .meta = "Labelno"},
//        {.tag = "ENCODER",        .meta = "Encoder"},
//        {.tag = "ENCODED-BY",     .meta = "Encoded-by"},
//        {.tag = "ENCODING",       .meta = "Encoding"},
        /* Other tags */
//        {.tag = "ALBUMARTIST",    .meta = "Albumartist"},
//        {.tag = "ALBUM ARTIST",   .meta = "Album artist"},
//        {.tag = "BAND",           .meta = "Band"},
//        {.tag = "COMPILATION",    .meta = "Compilation"},
//        {.tag = "TOTALTRACKS",    .meta = "Totaltracks"},
//        {.tag = "ENCODED_BY",     .meta = "Encoded_by"},
//        {.tag = "ENCODER_OPTIONS",.meta = "Encoder_options"},
        {.tag = NULL}
    };

    /* Mapping for special Deadbeef internal metadata */
    for (const key_t *match = keys; match->tag; match++)
        if (!strcasecmp(*in_or_out == 't' ? match->tag : match->meta, key))
            return *in_or_out == 't' ? match->meta : match->tag;

    /* Upper-case all Vorbis Comment tag names */
    if (*in_or_out == 'm')
        for (size_t i = 0; key[i]; i++)
            key[i] = toupper(key[i]);

    return key;
}