add 2007 copyright
[platform/upstream/flac.git] / src / metaflac / operations_shorthand_streaminfo.c
1 /* metaflac - Command-line FLAC metadata editor
2  * Copyright (C) 2001,2002,2003,2004,2005,2006,2007  Josh Coalson
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18
19 #if HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "options.h"
24 #include "utils.h"
25 #include "FLAC/assert.h"
26 #include "FLAC/metadata.h"
27 #include <string.h>
28
29 FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
30 {
31         unsigned i;
32         FLAC__bool ok = true;
33         FLAC__StreamMetadata *block;
34         FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
35
36         if(0 == iterator)
37                 die("out of memory allocating iterator");
38
39         FLAC__metadata_iterator_init(iterator, chain);
40
41         block = FLAC__metadata_iterator_get_block(iterator);
42
43         FLAC__ASSERT(0 != block);
44         FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO);
45
46         if(prefix_with_filename)
47                 printf("%s:", filename);
48
49         switch(operation->type) {
50                 case OP__SHOW_MD5SUM:
51                         for(i = 0; i < 16; i++)
52                                 printf("%02x", block->data.stream_info.md5sum[i]);
53                         printf("\n");
54                         break;
55                 case OP__SHOW_MIN_BLOCKSIZE:
56                         printf("%u\n", block->data.stream_info.min_blocksize);
57                         break;
58                 case OP__SHOW_MAX_BLOCKSIZE:
59                         printf("%u\n", block->data.stream_info.max_blocksize);
60                         break;
61                 case OP__SHOW_MIN_FRAMESIZE:
62                         printf("%u\n", block->data.stream_info.min_framesize);
63                         break;
64                 case OP__SHOW_MAX_FRAMESIZE:
65                         printf("%u\n", block->data.stream_info.max_framesize);
66                         break;
67                 case OP__SHOW_SAMPLE_RATE:
68                         printf("%u\n", block->data.stream_info.sample_rate);
69                         break;
70                 case OP__SHOW_CHANNELS:
71                         printf("%u\n", block->data.stream_info.channels);
72                         break;
73                 case OP__SHOW_BPS:
74                         printf("%u\n", block->data.stream_info.bits_per_sample);
75                         break;
76                 case OP__SHOW_TOTAL_SAMPLES:
77 #ifdef _MSC_VER
78                         printf("%I64u\n", block->data.stream_info.total_samples);
79 #else
80                         printf("%llu\n", (unsigned long long)block->data.stream_info.total_samples);
81 #endif
82                         break;
83                 case OP__SET_MD5SUM:
84                         memcpy(block->data.stream_info.md5sum, operation->argument.streaminfo_md5.value, 16);
85                         *needs_write = true;
86                         break;
87                 case OP__SET_MIN_BLOCKSIZE:
88                         block->data.stream_info.min_blocksize = operation->argument.streaminfo_uint32.value;
89                         *needs_write = true;
90                         break;
91                 case OP__SET_MAX_BLOCKSIZE:
92                         block->data.stream_info.max_blocksize = operation->argument.streaminfo_uint32.value;
93                         *needs_write = true;
94                         break;
95                 case OP__SET_MIN_FRAMESIZE:
96                         block->data.stream_info.min_framesize = operation->argument.streaminfo_uint32.value;
97                         *needs_write = true;
98                         break;
99                 case OP__SET_MAX_FRAMESIZE:
100                         block->data.stream_info.max_framesize = operation->argument.streaminfo_uint32.value;
101                         *needs_write = true;
102                         break;
103                 case OP__SET_SAMPLE_RATE:
104                         block->data.stream_info.sample_rate = operation->argument.streaminfo_uint32.value;
105                         *needs_write = true;
106                         break;
107                 case OP__SET_CHANNELS:
108                         block->data.stream_info.channels = operation->argument.streaminfo_uint32.value;
109                         *needs_write = true;
110                         break;
111                 case OP__SET_BPS:
112                         block->data.stream_info.bits_per_sample = operation->argument.streaminfo_uint32.value;
113                         *needs_write = true;
114                         break;
115                 case OP__SET_TOTAL_SAMPLES:
116                         block->data.stream_info.total_samples = operation->argument.streaminfo_uint64.value;
117                         *needs_write = true;
118                         break;
119                 default:
120                         ok = false;
121                         FLAC__ASSERT(0);
122                         break;
123         };
124
125         FLAC__metadata_iterator_delete(iterator);
126
127         return ok;
128 }