diff --git a/src/Files/Resources.cpp b/src/Files/Resources.cpp index 86903b2..2616067 100644 --- a/src/Files/Resources.cpp +++ b/src/Files/Resources.cpp @@ -27,8 +27,6 @@ static std::vector rezSearchStack; static int rezSearchStackIndex = 0; -static fs::path rezDumpHostDestinationPath = ""; - //----------------------------------------------------------------------------- // Internal @@ -45,76 +43,6 @@ static ResourceFork& GetCurRF() return rezSearchStack[rezSearchStackIndex]; } -#if 0 -static void PrintStack(const char* msg) { - LOG << "------ RESOURCE SEARCH STACK " << msg << " -------\n"; - for (int i = int(rezSearchStack.size() - 1); i >= 0; i--) { - LOG << (rezSearchStackIndex == i? " =====> " : " ") - << " StackPos=" << i << " " - << " RefNum=" << rezSearchStack[i].fileRefNum << " " -// << Pomme::Files::GetHostFilename(rezSearchStack[i].fileRefNum) - << "\n"; - } - LOG << "------------------------------------\n"; -} -#endif - -static void DumpResource(const ResourceMetadata& meta) -{ - const FSSpec& spec = Pomme::Files::GetSpec(meta.forkRefNum); - - Handle handle = NewHandle(meta.size); - auto& fork = Pomme::Files::GetStream(meta.forkRefNum); - fork.seekg(meta.dataOffset, std::ios::beg); - fork.read(*handle, meta.size); - - fs::path outPath; - outPath = rezDumpHostDestinationPath; - outPath /= spec.cName; - outPath /= Pomme::FourCCString(meta.type, '_'); - fs::create_directories(outPath); - - std::stringstream ss; - ss << meta.id; - if (!meta.name.empty()) - { - ss << "-"; - for (auto c: meta.name) - ss << (char)(isalnum(c)? c: '_'); - } - outPath /= ss.str(); - outPath += "." + Pomme::FourCCString(meta.type, '_'); - - std::ofstream dump(outPath, std::ios::binary); - - // Add a 512-byte blank header to PICTs so tools such as ImageMagick or Preview.app will display them - if (meta.type == 'PICT') - { - for (int i = 0; i < 512; i++) - dump.put(0); - } - - - dump.write(*handle, meta.size); - dump.close(); - std::cout << "wrote " << outPath << "\n"; - -#if _DEBUG && !POMME_NO_SOUND - // Dump sounds as AIFF as well - if (meta.type == 'snd ') - { - outPath.replace_extension(".aiff"); - std::ofstream aiff(outPath, std::ios::binary); - Pomme::Sound::DumpSoundResourceToAIFF(handle, aiff, meta.name); - aiff.close(); - - std::cout << "wrote " << outPath << "\n"; - } -#endif - - DisposeHandle(handle); -} - //----------------------------------------------------------------------------- // Resource file management @@ -214,10 +142,6 @@ short FSpOpenResFile(const FSSpec* spec, char permission) resMetadata.size = size; resMetadata.name = name; GetCurRF().resourceMap[resType][resID] = resMetadata; - - // Dump resource to file (if user called Pomme_StartDumpingResource) - if (!rezDumpHostDestinationPath.empty()) - DumpResource(resMetadata); } } @@ -451,15 +375,3 @@ long SizeResource(Handle theResource) { return GetResourceSizeOnDisk(theResource); } - -void Pomme_StartDumpingResources(const char* hostDestinationPath) -{ - if (hostDestinationPath) - { - rezDumpHostDestinationPath = hostDestinationPath; - } - else - { - rezDumpHostDestinationPath.clear(); - } -} \ No newline at end of file diff --git a/src/Pomme.h b/src/Pomme.h index 995a60b..d1917dd 100644 --- a/src/Pomme.h +++ b/src/Pomme.h @@ -130,11 +130,6 @@ long GetResourceSizeOnDisk(Handle); long SizeResource(Handle); -// After calling this function, Pomme will dump all resources to separate files -// whenever a new resource fork is opened. -// Pass in NULL to stop dumping resources. -void Pomme_StartDumpingResources(const char* hostDestinationPath); - //----------------------------------------------------------------------------- // QuickDraw 2D: Errors diff --git a/src/PommeSound.h b/src/PommeSound.h index 8b2f406..5fec45c 100644 --- a/src/PommeSound.h +++ b/src/PommeSound.h @@ -16,8 +16,6 @@ namespace Pomme::Sound void ReadAIFF(std::istream& input, cmixer::WavStream& output); - void DumpSoundResourceToAIFF(Handle input, std::ostream& output, const std::string& resourceName); - class Codec { public: diff --git a/src/Sound/SoundManager.cpp b/src/Sound/SoundManager.cpp index ef4b055..3530355 100644 --- a/src/Sound/SoundManager.cpp +++ b/src/Sound/SoundManager.cpp @@ -924,139 +924,3 @@ std::unique_ptr Pomme::Sound::GetCodec(uint32_t fourCC) throw std::runtime_error("Unknown audio codec: " + Pomme::FourCCString(fourCC)); } } - -//----------------------------------------------------------------------------- -// Dump 'snd ' resource to AIFF - -void Pomme::Sound::DumpSoundResourceToAIFF(Handle sndHandle, std::ostream& output, const std::string& resourceName) -{ - class AIFFChunkGuard - { - public: - AIFFChunkGuard(Pomme::BigEndianOStream& theOutput, uint32_t chunkID) - : output(theOutput) - { - output.Write(chunkID); - lengthFieldPosition = output.Tell(); - output.Write('#LEN'); // placeholder - } - - ~AIFFChunkGuard() - { - std::streampos endOfChunk = output.Tell(); - std::streamoff chunkLength = endOfChunk - lengthFieldPosition - static_cast(4); - - // Add zero pad byte if chunk length is odd - if (0 != (chunkLength & 1)) - { - output.Write(0); - endOfChunk += 1; - } - - output.Goto(lengthFieldPosition); - output.Write(chunkLength); - output.Goto(endOfChunk); - } - - private: - Pomme::BigEndianOStream& output; - std::streampos lengthFieldPosition; - }; - - - SampledSoundInfo info; - GetSoundInfoFromSndResource(sndHandle, info); - - char sampleRate80bit[10]; - ConvertToIeeeExtended(info.sampleRate, sampleRate80bit); - - Pomme::BigEndianOStream of(output); - - bool hasLoop = info.loopEnd - info.loopStart > 1; - - { - AIFFChunkGuard form(of, 'FORM'); - of.Write('AIFC'); - - { - AIFFChunkGuard chunk(of, 'FVER'); - of.Write(0xA2805140u); - } - - { - AIFFChunkGuard chunk(of, 'COMM'); - of.Write(info.nChannels); - of.Write(info.nPackets); - of.Write(info.codecBitDepth); - of.Write(sampleRate80bit, sizeof(sampleRate80bit)); - of.Write(info.compressionType); - - std::string compressionName; - switch (info.compressionType) - { - case 'MAC3': compressionName = "MACE 3-to-1"; break; - case 'ima4': compressionName = "IMA 16 bit 4-to-1"; break; - case 'NONE': compressionName = "Signed PCM"; break; - case 'twos': compressionName = "Signed big-endian PCM"; break; - case 'sowt': compressionName = "Signed little-endian PCM"; break; - case 'raw ': compressionName = "Unsigned PCM"; break; - case 'ulaw': compressionName = "mu-law"; break; - case 'alaw': compressionName = "A-law"; break; - default: compressionName = ""; - } - of.WritePascalString(compressionName, 2); // human-readable compression type pascal string - } - - if (hasLoop) - { - AIFFChunkGuard chunk(of, 'MARK'); - of.Write(2); // 2 markers - of.Write(101); // marker ID - of.Write(info.loopStart); - of.WritePascalString("beg loop", 2); - of.Write(102); // marker ID - of.Write(info.loopEnd); - of.WritePascalString("end loop", 2); - } - - if (info.baseNote != kMiddleC || hasLoop) - { - AIFFChunkGuard chunk(of, 'INST'); - of.Write(info.baseNote); - of.Write(0); // detune - of.Write(0x00); // lowNote - of.Write(0x7F); // highNote - of.Write(0x00); // lowVelocity - of.Write(0x7F); // highVelocity - of.Write(0); // gain - of.Write(hasLoop? 1: 0); // sustainLoop.playMode - of.Write(hasLoop? 101: 0); // sustainLoop.beginLoop - of.Write(hasLoop? 102: 0); // sustainLoop.endLoop - of.Write(0); - of.Write(0); - of.Write(0); - } - - if (!resourceName.empty()) - { - AIFFChunkGuard chunk(of, 'NAME'); - of.WriteRawString(resourceName); - } - - { - AIFFChunkGuard chunk(of, 'ANNO'); - std::stringstream ss; - ss << "Verbatim copy of data stream from 'snd ' resource.\n" - << "MIDI base note: " << int(info.baseNote) - << ", sustain loop: " << info.loopStart << "-" << info.loopEnd; - of.WriteRawString(ss.str()); - } - - { - AIFFChunkGuard chunk(of, 'SSND'); - of.Write(0); // offset; don't care - of.Write(0); // blockSize; don't care - of.Write(info.dataStart, info.compressedLength); - } - } -}