diff --git a/extras/juce demo/Source/ApplicationStartup.cpp b/extras/juce demo/Source/ApplicationStartup.cpp index 63ce6ab8dc..d2719d5393 100644 --- a/extras/juce demo/Source/ApplicationStartup.cpp +++ b/extras/juce demo/Source/ApplicationStartup.cpp @@ -153,6 +153,8 @@ private: << File::getSpecialLocation (File::currentExecutableFile).getFullPathName() << "\nCurrent application file: " << File::getSpecialLocation (File::currentApplicationFile).getFullPathName() + << "\nCurrent working directory: " + << File::getCurrentWorkingDirectory().getFullPathName() << "\nUser home directory: " << File::getSpecialLocation (File::userHomeDirectory).getFullPathName() << "\nUser documents directory: " diff --git a/src/audio/audio_file_formats/juce_WavAudioFormat.cpp b/src/audio/audio_file_formats/juce_WavAudioFormat.cpp index 8347c1a46b..716ca972d3 100644 --- a/src/audio/audio_file_formats/juce_WavAudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_WavAudioFormat.cpp @@ -238,6 +238,16 @@ struct SMPLChunk } } PACKED; + +struct ExtensibleWavSubFormat +{ + uint32 data1; + uint16 data2; + uint16 data3; + uint8 data4[8]; +} PACKED; + + #if JUCE_MSVC #pragma pack (pop) #endif @@ -285,7 +295,7 @@ public: if (chunkType == chunkName ("fmt ")) { // read the format chunk - const short format = input->readShort(); + const unsigned short format = input->readShort(); const short numChans = input->readShort(); sampleRate = input->readInt(); const int bytesPerSec = input->readInt(); @@ -295,9 +305,41 @@ public: bitsPerSample = 8 * bytesPerFrame / numChans; if (format == 3) + { usesFloatingPointData = true; + } + else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/) + { + if (length < 40) // too short + { + bytesPerFrame = 0; + } + else + { + input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask + ExtensibleWavSubFormat subFormat; + subFormat.data1 = input->readInt(); + subFormat.data2 = input->readShort(); + subFormat.data3 = input->readShort(); + input->read (subFormat.data4, sizeof (subFormat.data4)); + + const ExtensibleWavSubFormat pcmFormat + = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } }; + + if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0) + { + const ExtensibleWavSubFormat ambisonicFormat + = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } }; + + if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0) + bytesPerFrame = 0; + } + } + } else if (format != 1) + { bytesPerFrame = 0; + } hasGotType = true; } diff --git a/src/io/files/juce_File.cpp b/src/io/files/juce_File.cpp index 742cc39722..22a9ddbfaa 100644 --- a/src/io/files/juce_File.cpp +++ b/src/io/files/juce_File.cpp @@ -113,10 +113,14 @@ static const String parseAbsolutePath (String path) { if (path[1] != File::separator) { - jassertfalse // using a filename that starts with a slash is a bit dodgy on - // Windows, because it needs a drive letter, which in this case - // we'll take from the CWD.. but this is a bit of an assumption that - // could be wrong.. + /* When you supply a raw string to the File object constructor, it must be an absolute path. + If you're trying to parse a string that may be either a relative path or an absolute path, + you MUST provide a context against which the partial path can be evaluated - you can do + this by simply using File::getChildFile() instead of the File constructor. E.g. saying + "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute + path if that's what was supplied, or would evaluate a partial path relative to the CWD. + */ + jassertfalse path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path; } @@ -126,10 +130,14 @@ static const String parseAbsolutePath (String path) if (path.isEmpty()) return String::empty; - jassertfalse // using a partial filename is a bad way to initialise a file, because - // we don't know what directory to put it in. - // Here we'll assume it's in the CWD, but this might not be what was - // intended.. + /* When you supply a raw string to the File object constructor, it must be an absolute path. + If you're trying to parse a string that may be either a relative path or an absolute path, + you MUST provide a context against which the partial path can be evaluated - you can do + this by simply using File::getChildFile() instead of the File constructor. E.g. saying + "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute + path if that's what was supplied, or would evaluate a partial path relative to the CWD. + */ + jassertfalse return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName(); } @@ -168,16 +176,14 @@ static const String parseAbsolutePath (String path) } else if (! path.startsWithChar (File::separator)) { - while (path.startsWith (T("./"))) - path = path.substring (2); - - if (path.isEmpty()) - return String::empty; - - jassertfalse // using a partial filename is a bad way to initialise a file, because - // we don't know what directory to put it in. - // Here we'll assume it's in the CWD, but this might not be what was - // intended.. + /* When you supply a raw string to the File object constructor, it must be an absolute path. + If you're trying to parse a string that may be either a relative path or an absolute path, + you MUST provide a context against which the partial path can be evaluated - you can do + this by simply using File::getChildFile() instead of the File constructor. E.g. saying + "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute + path if that's what was supplied, or would evaluate a partial path relative to the CWD. + */ + jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD) return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName(); } diff --git a/src/io/files/juce_File.h b/src/io/files/juce_File.h index 2737178217..dfd11eb4fb 100644 --- a/src/io/files/juce_File.h +++ b/src/io/files/juce_File.h @@ -146,7 +146,7 @@ public: @see getFileName, getRelativePathFrom */ - const String& getFullPathName() const { return fullPath; } + const String& getFullPathName() const throw() { return fullPath; } /** Returns the last section of the pathname. diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index bc1b9b8050..bd7314c6cc 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -162,6 +162,29 @@ void JUCE_CALLTYPE Thread::sleep (int millisecs) const tchar File::separator = T('/'); const tchar* File::separatorString = T("/"); +//============================================================================== +const File File::getCurrentWorkingDirectory() +{ + HeapBlock heapBuffer; + + char localBuffer [1024]; + char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1); + int bufferSize = 4096; + + while (cwd == 0 && errno == ERANGE) + { + heapBuffer.malloc (bufferSize); + cwd = getcwd (heapBuffer, bufferSize - 1); + bufferSize += 1024; + } + + return File (String::fromUTF8 ((const uint8*) cwd)); +} + +bool File::setAsCurrentWorkingDirectory() const +{ + return chdir (getFullPathName().toUTF8()) == 0; +} //============================================================================== bool juce_copyFile (const String& s, const String& d); diff --git a/src/native/linux/juce_linux_Files.cpp b/src/native/linux/juce_linux_Files.cpp index f2914a0c83..9440802995 100644 --- a/src/native/linux/juce_linux_Files.cpp +++ b/src/native/linux/juce_linux_Files.cpp @@ -238,19 +238,6 @@ const File File::getSpecialLocation (const SpecialLocationType type) return File::nonexistent; } - -//============================================================================== -const File File::getCurrentWorkingDirectory() -{ - char buf [2048]; - return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf)))); -} - -bool File::setAsCurrentWorkingDirectory() const -{ - return chdir (getFullPathName().toUTF8()) == 0; -} - //============================================================================== const String File::getVersion() const { diff --git a/src/native/mac/juce_mac_Files.mm b/src/native/mac/juce_mac_Files.mm index d1ce0e3ecb..f12edc7418 100644 --- a/src/native/mac/juce_mac_Files.mm +++ b/src/native/mac/juce_mac_Files.mm @@ -261,20 +261,6 @@ const File File::getSpecialLocation (const SpecialLocationType type) return File::nonexistent; } -//============================================================================== -const File File::getCurrentWorkingDirectory() -{ - char buf [2048]; - getcwd (buf, sizeof(buf)); - - return File (PlatformUtilities::convertToPrecomposedUnicode (buf)); -} - -bool File::setAsCurrentWorkingDirectory() const -{ - return chdir (getFullPathName().toUTF8()) == 0; -} - //============================================================================== const String File::getVersion() const {