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#include "operations_shorthand.h" 29 30FLAC__bool do_shorthand_operation__streaminfo(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write) 31{ 32 unsigned i; 33 FLAC__bool ok = true; 34 FLAC__StreamMetadata *block; 35 FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new(); 36 37 if(0 == iterator) 38 die("out of memory allocating iterator"); 39 40 FLAC__metadata_iterator_init(iterator, chain); 41 42 block = FLAC__metadata_iterator_get_block(iterator); 43 44 FLAC__ASSERT(0 != block); 45 FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_STREAMINFO); 46 47 if(prefix_with_filename) 48 printf("%s:", filename); 49 50 switch(operation->type) { 51 case OP__SHOW_MD5SUM: 52 for(i = 0; i < 16; i++) 53 printf("%02x", block->data.stream_info.md5sum[i]); 54 printf("\n"); 55 break; 56 case OP__SHOW_MIN_BLOCKSIZE: 57 printf("%u\n", block->data.stream_info.min_blocksize); 58 break; 59 case OP__SHOW_MAX_BLOCKSIZE: 60 printf("%u\n", block->data.stream_info.max_blocksize); 61 break; 62 case OP__SHOW_MIN_FRAMESIZE: 63 printf("%u\n", block->data.stream_info.min_framesize); 64 break; 65 case OP__SHOW_MAX_FRAMESIZE: 66 printf("%u\n", block->data.stream_info.max_framesize); 67 break; 68 case OP__SHOW_SAMPLE_RATE: 69 printf("%u\n", block->data.stream_info.sample_rate); 70 break; 71 case OP__SHOW_CHANNELS: 72 printf("%u\n", block->data.stream_info.channels); 73 break; 74 case OP__SHOW_BPS: 75 printf("%u\n", block->data.stream_info.bits_per_sample); 76 break; 77 case OP__SHOW_TOTAL_SAMPLES: 78#ifdef _MSC_VER 79 printf("%I64u\n", block->data.stream_info.total_samples); 80#else 81 printf("%llu\n", (unsigned long long)block->data.stream_info.total_samples); 82#endif 83 break; 84 case OP__SET_MD5SUM: 85 memcpy(block->data.stream_info.md5sum, operation->argument.streaminfo_md5.value, 16); 86 *needs_write = true; 87 break; 88 case OP__SET_MIN_BLOCKSIZE: 89 block->data.stream_info.min_blocksize = operation->argument.streaminfo_uint32.value; 90 *needs_write = true; 91 break; 92 case OP__SET_MAX_BLOCKSIZE: 93 block->data.stream_info.max_blocksize = operation->argument.streaminfo_uint32.value; 94 *needs_write = true; 95 break; 96 case OP__SET_MIN_FRAMESIZE: 97 block->data.stream_info.min_framesize = operation->argument.streaminfo_uint32.value; 98 *needs_write = true; 99 break; 100 case OP__SET_MAX_FRAMESIZE: 101 block->data.stream_info.max_framesize = operation->argument.streaminfo_uint32.value; 102 *needs_write = true; 103 break; 104 case OP__SET_SAMPLE_RATE: 105 block->data.stream_info.sample_rate = operation->argument.streaminfo_uint32.value; 106 *needs_write = true; 107 break; 108 case OP__SET_CHANNELS: 109 block->data.stream_info.channels = operation->argument.streaminfo_uint32.value; 110 *needs_write = true; 111 break; 112 case OP__SET_BPS: 113 block->data.stream_info.bits_per_sample = operation->argument.streaminfo_uint32.value; 114 *needs_write = true; 115 break; 116 case OP__SET_TOTAL_SAMPLES: 117 block->data.stream_info.total_samples = operation->argument.streaminfo_uint64.value; 118 *needs_write = true; 119 break; 120 default: 121 ok = false; 122 FLAC__ASSERT(0); 123 break; 124 }; 125 126 FLAC__metadata_iterator_delete(iterator); 127 128 return ok; 129} 130