--- libgig/trunk/src/gigdump.cpp 2004/09/09 18:37:22 235 +++ libgig/trunk/src/gigdump.cpp 2006/11/24 12:50:05 933 @@ -1,9 +1,11 @@ /*************************************************************************** * * - * libgig - C++ cross-platform Gigasampler format file loader library * + * libgig - C++ cross-platform Gigasampler format file access library * * * - * Copyright (C) 2003, 2004 by Christian Schoenebeck * - * * + * Copyright (C) 2003-2006 by Christian Schoenebeck * + * * + * * + * This program is part of libgig. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -27,11 +29,16 @@ #include #include +#include #include "gig.h" using namespace std; +string Revision(); +void PrintVersion(); +void PrintFileInformations(gig::File* gig); +void PrintGroups(gig::File* gig); void PrintSamples(gig::File* gig); void PrintInstruments(gig::File* gig); void PrintRegions(gig::Instrument* instr); @@ -44,6 +51,13 @@ PrintUsage(); return EXIT_FAILURE; } + if (argv[1][0] == '-') { + switch (argv[1][1]) { + case 'v': + PrintVersion(); + return EXIT_SUCCESS; + } + } FILE* hFile = fopen(argv[1], "r"); if (!hFile) { cout << "Invalid file argument!" << endl; @@ -53,6 +67,10 @@ try { RIFF::File* riff = new RIFF::File(argv[1]); gig::File* gig = new gig::File(riff); + PrintFileInformations(gig); + cout << endl; + PrintGroups(gig); + cout << endl; PrintSamples(gig); cout << endl; PrintInstruments(gig); @@ -71,16 +89,82 @@ return EXIT_SUCCESS; } +void PrintFileInformations(gig::File* gig) { + cout << "Global File Informations:" << endl; + cout << " Total instruments: " << gig->Instruments << endl; + if (gig->pVersion) { + cout << " Version: " << gig->pVersion->major << "." + << gig->pVersion->minor << "." + << gig->pVersion->release << "." + << gig->pVersion->build << endl; + } + if (gig->pInfo) { + if (gig->pInfo->Name.size()) + cout << " Name: '" << gig->pInfo->Name << "'\n"; + if (gig->pInfo->ArchivalLocation.size()) + cout << " ArchivalLocation: '" << gig->pInfo->ArchivalLocation << "'\n"; + if (gig->pInfo->CreationDate.size()) + cout << " CreationDate: '" << gig->pInfo->CreationDate << "'\n"; + if (gig->pInfo->Comments.size()) + cout << " Comments: '" << gig->pInfo->Comments << "'\n"; + if (gig->pInfo->Product.size()) + cout << " Product: '" << gig->pInfo->Product << "'\n"; + if (gig->pInfo->Copyright.size()) + cout << " Copyright: '" << gig->pInfo->Copyright << "'\n"; + if (gig->pInfo->Artists.size()) + cout << " Artists: '" << gig->pInfo->Artists << "'\n"; + if (gig->pInfo->Genre.size()) + cout << " Genre: '" << gig->pInfo->Genre << "'\n"; + if (gig->pInfo->Keywords.size()) + cout << " Keywords: '" << gig->pInfo->Keywords << "'\n"; + if (gig->pInfo->Engineer.size()) + cout << " Engineer: '" << gig->pInfo->Engineer << "'\n"; + if (gig->pInfo->Technician.size()) + cout << " Technician: '" << gig->pInfo->Technician << "'\n"; + if (gig->pInfo->Software.size()) + cout << " Software: '" << gig->pInfo->Software << "'\n"; + if (gig->pInfo->Medium.size()) + cout << " Medium: '" << gig->pInfo->Medium << "'\n"; + if (gig->pInfo->Source.size()) + cout << " Source: '" << gig->pInfo->Source << "'\n"; + if (gig->pInfo->SourceForm.size()) + cout << " SourceForm: '" << gig->pInfo->SourceForm << "'\n"; + if (gig->pInfo->Commissioned.size()) + cout << " Commissioned: '" << gig->pInfo->Commissioned << "'\n"; + } +} + +void PrintGroups(gig::File* gig) { + int groups = 0; + cout << "ALL defined Groups:" << endl; + for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup()) { + groups++; + string name = pGroup->Name; + if (name == "") name = ""; + else name = '\"' + name + '\"'; + cout << " Group " << groups << ")" << endl; + cout << " Name: " << name << endl; + } +} + void PrintSamples(gig::File* gig) { int samples = 0; cout << "ALL Available Samples (as there might be more than referenced by Instruments):" << endl; gig::Sample* pSample = gig->GetFirstSample(); while (pSample) { samples++; + // determine sample's name string name = pSample->pInfo->Name; if (name == "") name = ""; else name = '\"' + name + '\"'; + // determine group this sample belongs to + int iGroup = 1; + for (gig::Group* pGroup = gig->GetFirstGroup(); pGroup; pGroup = gig->GetNextGroup(), iGroup++) { + if (pGroup == pSample->GetGroup()) break; + } + // print sample info cout << " Sample " << samples << ") " << name << ", "; + cout << "Group " << iGroup << ", "; cout << pSample->SamplesPerSecond << "Hz, " << pSample->Channels << " Channels, " << pSample->Loops << " Loops"; if (pSample->Loops) { cout << " (Type: "; @@ -90,6 +174,7 @@ case gig::loop_type_backward: cout << "reverse)"; break; } cout << ", LoopFraction=" << pSample->LoopFraction << ", Start=" << pSample->LoopStart << ", End=" << pSample->LoopEnd; + cout << ", LoopPlayCount=" << pSample->LoopPlayCount; } cout << ", Length=" << pSample->SamplesTotal << " Compressed=" << ((pSample->Compressed) ? "true" : "false") << endl; pSample = gig->GetNextSample(); @@ -131,7 +216,7 @@ cout << " "; } cout << " KeyRange=" << pRegion->KeyRange.low << "-" << pRegion->KeyRange.high << ", "; - cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layer=" << pRegion->Layer << endl; + cout << "VelocityRange=" << pRegion->VelocityRange.low << "-" << pRegion->VelocityRange.high << ", Layers=" << pRegion->Layers << endl; cout << " Loops=" << pRegion->SampleLoops << endl; cout << " Dimensions=" << pRegion->Dimensions << endl; for (int iDimension = 0; iDimension < pRegion->Dimensions; iDimension++) { @@ -144,10 +229,11 @@ case gig::dimension_samplechannel: // If used sample has more than one channel (thus is not mono). cout << "SAMPLECHANNEL"; break; - case gig::dimension_layer: // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers). + case gig::dimension_layer: { // For layering of up to 8 instruments (and eventually crossfading of 2 or 4 layers). gig::crossfade_t crossfade = pRegion->pDimensionRegions[iDimension]->Crossfade; cout << "LAYER (Crossfade in_start=" << (int) crossfade.in_start << ",in_end=" << (int) crossfade.in_end << ",out_start=" << (int) crossfade.out_start << ",out_end=" << (int) crossfade.out_end << ")"; break; + } case gig::dimension_velocity: // Key Velocity (this is the only dimension where the ranges can exactly be defined). cout << "VELOCITY"; break; @@ -160,6 +246,12 @@ case gig::dimension_keyboard: // Key Position cout << "KEYBOARD"; break; + case gig::dimension_roundrobin: // Different samples triggered each time a note is played, dimension regions selected in sequence + cout << "ROUNDROBIN"; + break; + case gig::dimension_random: // Different samples triggered each time a note is played, random order + cout << "RANDOM"; + break; case gig::dimension_modwheel: // Modulation Wheel (MIDI Controller 1) cout << "MODWHEEL"; break; @@ -230,10 +322,21 @@ cout << "EFFECT5DEPTH"; break; default: - cout << "UNKNOWN - please report this !"; + cout << "UNKNOWN (" << int(DimensionDef.dimension) << ") - please report this !"; break; } - cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones << endl; + cout << ", Bits=" << (uint) DimensionDef.bits << ", Zones=" << (uint) DimensionDef.zones; + cout << ", SplitType="; + switch (DimensionDef.split_type) { + case gig::split_type_normal: + cout << "NORMAL" << endl; + break; + case gig::split_type_bit: + cout << "BIT" << endl; + break; + default: + cout << "UNKNOWN" << endl; + } } PrintDimensionRegions(pRegion); @@ -245,7 +348,7 @@ void PrintDimensionRegions(gig::Region* rgn) { int dimensionRegions = 0; gig::DimensionRegion* pDimensionRegion; - while (dimensionRegions < 32) { + while (dimensionRegions < rgn->DimensionRegions) { pDimensionRegion = rgn->pDimensionRegions[dimensionRegions]; if (!pDimensionRegion) break; @@ -257,7 +360,8 @@ if (pSample->pInfo->Name != "") { cout << "\"" << pSample->pInfo->Name << "\", "; } - cout << pSample->SamplesPerSecond << "Hz, " << endl; + cout << pSample->SamplesPerSecond << "Hz, "; + cout << "UnityNote=" << (int) pDimensionRegion->UnityNote << ", FineTune=" << (int) pDimensionRegion->FineTune << ", Gain=" << (-pDimensionRegion->Gain / 655360.0) << "dB, SampleStartOffset=" << pDimensionRegion->SampleStartOffset << endl; } else { cout << " Sample: " << endl; @@ -284,13 +388,27 @@ cout << "UNKNOWN - please report this !"; } cout << ", VelocityResponseDepth=" << (int) pDimensionRegion->VelocityResponseDepth << ", VelocityResponseCurveScaling=" << (int) pDimensionRegion->VelocityResponseCurveScaling << endl; + cout << " Pan=" << (int) pDimensionRegion->Pan << endl; dimensionRegions++; } } +string Revision() { + string s = "$Revision: 1.22 $"; + return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword +} + +void PrintVersion() { + cout << "gigdump revision " << Revision() << endl; + cout << "using " << gig::libraryName() << " " << gig::libraryVersion() << endl; +} + void PrintUsage() { cout << "gigdump - parses Gigasampler files and prints out the content." << endl; cout << endl; - cout << "Usage: gigdump FILE" << endl; + cout << "Usage: gigdump [-v] FILE" << endl; + cout << endl; + cout << " -v Print version and exit." << endl; + cout << endl; }