From 7228c6b5930355e38577cda255d5d3cf9a157d36 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Tue, 16 Mar 2010 19:51:58 +0000 Subject: [PATCH] Minor clean-ups and fix for posix WaitableEvent. --- .../ui/Drawable Editor/jucer_DrawableEditor.h | 2 +- .../formats/juce_AudioUnitPluginFormat.mm | 33 ++- src/gui/graphics/geometry/juce_Path.cpp | 224 +++++++++--------- src/gui/graphics/geometry/juce_Path.h | 161 ++++++------- .../graphics/geometry/juce_PathIterator.cpp | 12 +- src/gui/graphics/geometry/juce_PathIterator.h | 10 +- src/gui/graphics/geometry/juce_Rectangle.h | 8 +- src/native/common/juce_posix_SharedCode.h | 158 ++++++------ src/native/linux/juce_linux_FileChooser.cpp | 2 +- src/native/linux/juce_linux_Files.cpp | 2 +- src/native/linux/juce_linux_Network.cpp | 4 +- src/native/linux/juce_linux_Threads.cpp | 2 +- src/native/mac/juce_mac_CameraDevice.mm | 32 +-- 13 files changed, 329 insertions(+), 321 deletions(-) diff --git a/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditor.h b/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditor.h index e073375eae..ab72973fe8 100644 --- a/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditor.h +++ b/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditor.h @@ -78,7 +78,7 @@ public: Point origin; }; - Canvas* getCanvas() const { return (Canvas*) viewport->getViewedComponent(); } + Canvas* getCanvas() const { return static_cast (viewport->getViewedComponent()); } SelectedItemSet selectedItems; diff --git a/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm b/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm index 4e24e5d2f2..118cd09fc2 100644 --- a/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm +++ b/src/audio/plugins/formats/juce_AudioUnitPluginFormat.mm @@ -68,7 +68,7 @@ BEGIN_JUCE_NAMESPACE static int insideCallback = 0; //============================================================================== -static const String osTypeToString (OSType type) throw() +static const String osTypeToString (OSType type) { char s[4]; s[0] = (char) (((uint32) type) >> 24); @@ -78,7 +78,7 @@ static const String osTypeToString (OSType type) throw() return String (s, 4); } -static OSType stringToOSType (const String& s1) throw() +static OSType stringToOSType (const String& s1) { const String s (s1 + " "); @@ -107,10 +107,8 @@ static const String createAUPluginIdentifier (const ComponentDescription& desc) else if (desc.componentType == kAudioUnitType_Panner) s << "Panners/"; - s << osTypeToString (desc.componentType) - << T(",") - << osTypeToString (desc.componentSubType) - << T(",") + s << osTypeToString (desc.componentType) << "," + << osTypeToString (desc.componentSubType) << "," << osTypeToString (desc.componentManufacturer); return s; @@ -133,7 +131,7 @@ static void getAUDetails (ComponentRecord* comp, String& name, String& manufactu if (nameString != 0 && nameString[0] != 0) { const String all ((const char*) nameString + 1, nameString[0]); -DBG ("name: "+ all); + DBG ("name: "+ all); manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim(); name = all.fromFirstOccurrenceOf (T(":"), false, false).trim(); @@ -141,8 +139,7 @@ DBG ("name: "+ all); if (infoString != 0 && infoString[0] != 0) { - const String all ((const char*) infoString + 1, infoString[0]); -DBG ("info: " + all); + DBG ("info: " + String ((const char*) infoString + 1, infoString[0])); } if (name.isEmpty()) @@ -406,17 +403,15 @@ AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier AudioUnitPluginInstance::~AudioUnitPluginInstance() { + const ScopedLock sl (lock); + + jassert (insideCallback == 0); + + if (audioUnit != 0) { - const ScopedLock sl (lock); - - jassert (insideCallback == 0); - - if (audioUnit != 0) - { - AudioUnitUninitialize (audioUnit); - CloseComponent (audioUnit); - audioUnit = 0; - } + AudioUnitUninitialize (audioUnit); + CloseComponent (audioUnit); + audioUnit = 0; } } diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index 5a5612b13a..8ca1021f6d 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -38,6 +38,51 @@ BEGIN_JUCE_NAMESPACE #define CHECK_COORDS_ARE_VALID(x, y) \ jassert (x == x && y == y); +//============================================================================== +namespace PathHelpers +{ + static const float ellipseAngularIncrement = 0.05f; + + static void perpendicularOffset (const float x1, const float y1, + const float x2, const float y2, + const float offsetX, const float offsetY, + float& resultX, float& resultY) throw() + { + const float dx = x2 - x1; + const float dy = y2 - y1; + const float len = juce_hypotf (dx, dy); + + if (len == 0) + { + resultX = x1; + resultY = y1; + } + else + { + resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len; + resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len; + } + } + + static const String nextToken (const tchar*& t) + { + while (CharacterFunctions::isWhitespace (*t)) + ++t; + + const tchar* const start = t; + + while (*t != 0 && ! CharacterFunctions::isWhitespace (*t)) + ++t; + + const int length = (int) (t - start); + + while (CharacterFunctions::isWhitespace (*t)) + ++t; + + return String (start, length); + } +} + //============================================================================== const float Path::lineMarker = 100001.0f; const float Path::moveMarker = 100002.0f; @@ -45,10 +90,9 @@ const float Path::quadMarker = 100003.0f; const float Path::cubicMarker = 100004.0f; const float Path::closeSubPathMarker = 100005.0f; -static const int defaultGranularity = 32; //============================================================================== -Path::Path() throw() +Path::Path() : numElements (0), pathXMin (0), pathXMax (0), @@ -58,11 +102,11 @@ Path::Path() throw() { } -Path::~Path() throw() +Path::~Path() { } -Path::Path (const Path& other) throw() +Path::Path (const Path& other) : numElements (other.numElements), pathXMin (other.pathXMin), pathXMax (other.pathXMax), @@ -77,7 +121,7 @@ Path::Path (const Path& other) throw() } } -Path& Path::operator= (const Path& other) throw() +Path& Path::operator= (const Path& other) { if (this != &other) { @@ -109,7 +153,7 @@ void Path::clear() throw() void Path::swapWithPath (Path& other) { data.swapWith (other.data); - swapVariables (numElements, other.numElements); + swapVariables (numElements, other.numElements); swapVariables (pathXMin, other.pathXMin); swapVariables (pathXMax, other.pathXMax); swapVariables (pathYMin, other.pathYMin); @@ -132,7 +176,7 @@ void Path::scaleToFit (const float x, const float y, const float w, const float //============================================================================== bool Path::isEmpty() const throw() { - int i = 0; + size_t i = 0; while (i < numElements) { @@ -153,7 +197,7 @@ bool Path::isEmpty() const throw() return true; } -const Rectangle Path::getBounds () const throw() +const Rectangle Path::getBounds() const throw() { return Rectangle (pathXMin, pathYMin, pathXMax - pathXMin, @@ -167,8 +211,7 @@ const Rectangle Path::getBoundsTransformed (const AffineTransform& transf } //============================================================================== -void Path::startNewSubPath (const float x, - const float y) throw() +void Path::startNewSubPath (const float x, const float y) { CHECK_COORDS_ARE_VALID (x, y); @@ -192,7 +235,7 @@ void Path::startNewSubPath (const float x, data.elements [numElements++] = y; } -void Path::lineTo (const float x, const float y) throw() +void Path::lineTo (const float x, const float y) { CHECK_COORDS_ARE_VALID (x, y); @@ -212,7 +255,7 @@ void Path::lineTo (const float x, const float y) throw() } void Path::quadraticTo (const float x1, const float y1, - const float x2, const float y2) throw() + const float x2, const float y2) { CHECK_COORDS_ARE_VALID (x1, y1); CHECK_COORDS_ARE_VALID (x2, y2); @@ -236,7 +279,7 @@ void Path::quadraticTo (const float x1, const float y1, void Path::cubicTo (const float x1, const float y1, const float x2, const float y2, - const float x3, const float y3) throw() + const float x3, const float y3) { CHECK_COORDS_ARE_VALID (x1, y1); CHECK_COORDS_ARE_VALID (x2, y2); @@ -261,7 +304,7 @@ void Path::cubicTo (const float x1, const float y1, pathYMax = jmax (pathYMax, y1, y2, y3); } -void Path::closeSubPath() throw() +void Path::closeSubPath() { if (numElements > 0 && data.elements [numElements - 1] != closeSubPathMarker) @@ -296,7 +339,7 @@ const Point Path::getCurrentPosition() const } void Path::addRectangle (const float x, const float y, - const float w, const float h) throw() + const float w, const float h) { float x1 = x, y1 = y, x2 = x + w, y2 = y + h; @@ -338,7 +381,7 @@ void Path::addRectangle (const float x, const float y, data.elements [numElements++] = closeSubPathMarker; } -void Path::addRectangle (const Rectangle& rectangle) throw() +void Path::addRectangle (const Rectangle& rectangle) { addRectangle ((float) rectangle.getX(), (float) rectangle.getY(), (float) rectangle.getWidth(), (float) rectangle.getHeight()); @@ -347,7 +390,7 @@ void Path::addRectangle (const Rectangle& rectangle) throw() void Path::addRoundedRectangle (const float x, const float y, const float w, const float h, float csx, - float csy) throw() + float csy) { csx = jmin (csx, w * 0.5f); csy = jmin (csy, h * 0.5f); @@ -370,14 +413,14 @@ void Path::addRoundedRectangle (const float x, const float y, void Path::addRoundedRectangle (const float x, const float y, const float w, const float h, - float cs) throw() + float cs) { addRoundedRectangle (x, y, w, h, cs, cs); } void Path::addTriangle (const float x1, const float y1, const float x2, const float y2, - const float x3, const float y3) throw() + const float x3, const float y3) { startNewSubPath (x1, y1); lineTo (x2, y2); @@ -388,7 +431,7 @@ void Path::addTriangle (const float x1, const float y1, void Path::addQuadrilateral (const float x1, const float y1, const float x2, const float y2, const float x3, const float y3, - const float x4, const float y4) throw() + const float x4, const float y4) { startNewSubPath (x1, y1); lineTo (x2, y2); @@ -398,7 +441,7 @@ void Path::addQuadrilateral (const float x1, const float y1, } void Path::addEllipse (const float x, const float y, - const float w, const float h) throw() + const float w, const float h) { const float hw = w * 0.5f; const float hw55 = hw * 0.55f; @@ -419,7 +462,7 @@ void Path::addArc (const float x, const float y, const float w, const float h, const float fromRadians, const float toRadians, - const bool startAsNewSubPath) throw() + const bool startAsNewSubPath) { const float radiusX = w / 2.0f; const float radiusY = h / 2.0f; @@ -432,14 +475,12 @@ void Path::addArc (const float x, const float y, startAsNewSubPath); } -static const float ellipseAngularIncrement = 0.05f; - void Path::addCentredArc (const float centreX, const float centreY, const float radiusX, const float radiusY, const float rotationOfEllipse, const float fromRadians, const float toRadians, - const bool startAsNewSubPath) throw() + const bool startAsNewSubPath) { if (radiusX > 0.0f && radiusY > 0.0f) { @@ -460,7 +501,7 @@ void Path::addCentredArc (const float centreX, const float centreY, if (fromRadians < toRadians) { if (startAsNewSubPath) - angle += ellipseAngularIncrement; + angle += PathHelpers::ellipseAngularIncrement; while (angle < toRadians) { @@ -472,13 +513,13 @@ void Path::addCentredArc (const float centreX, const float centreY, lineTo (x, y); - angle += ellipseAngularIncrement; + angle += PathHelpers::ellipseAngularIncrement; } } else { if (startAsNewSubPath) - angle -= ellipseAngularIncrement; + angle -= PathHelpers::ellipseAngularIncrement; while (angle > toRadians) { @@ -490,7 +531,7 @@ void Path::addCentredArc (const float centreX, const float centreY, lineTo (x, y); - angle -= ellipseAngularIncrement; + angle -= PathHelpers::ellipseAngularIncrement; } } @@ -555,51 +596,29 @@ void Path::addPieSegment (const float x, const float y, closeSubPath(); } -//============================================================================== -static void perpendicularOffset (const float x1, const float y1, - const float x2, const float y2, - const float offsetX, const float offsetY, - float& resultX, float& resultY) throw() -{ - const float dx = x2 - x1; - const float dy = y2 - y1; - const float len = juce_hypotf (dx, dy); - - if (len == 0) - { - resultX = x1; - resultY = y1; - } - else - { - resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len; - resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len; - } -} - //============================================================================== void Path::addLineSegment (const float startX, const float startY, const float endX, const float endY, - float lineThickness) throw() + float lineThickness) { lineThickness *= 0.5f; float x, y; - perpendicularOffset (startX, startY, endX, endY, - 0, lineThickness, x, y); + PathHelpers::perpendicularOffset (startX, startY, endX, endY, + 0, lineThickness, x, y); startNewSubPath (x, y); - perpendicularOffset (startX, startY, endX, endY, - 0, -lineThickness, x, y); + PathHelpers::perpendicularOffset (startX, startY, endX, endY, + 0, -lineThickness, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - 0, lineThickness, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + 0, lineThickness, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - 0, -lineThickness, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + 0, -lineThickness, x, y); lineTo (x, y); closeSubPath(); @@ -609,7 +628,7 @@ void Path::addArrow (const float startX, const float startY, const float endX, const float endY, float lineThickness, float arrowheadWidth, - float arrowheadLength) throw() + float arrowheadLength) { lineThickness *= 0.5f; arrowheadWidth *= 0.5f; @@ -618,32 +637,32 @@ void Path::addArrow (const float startX, const float startY, float x, y; - perpendicularOffset (startX, startY, endX, endY, - 0, lineThickness, x, y); + PathHelpers::perpendicularOffset (startX, startY, endX, endY, + 0, lineThickness, x, y); startNewSubPath (x, y); - perpendicularOffset (startX, startY, endX, endY, - 0, -lineThickness, x, y); + PathHelpers::perpendicularOffset (startX, startY, endX, endY, + 0, -lineThickness, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - arrowheadLength, lineThickness, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + arrowheadLength, lineThickness, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - arrowheadLength, arrowheadWidth, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + arrowheadLength, arrowheadWidth, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - 0, 0, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + 0, 0, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - arrowheadLength, -arrowheadWidth, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + arrowheadLength, -arrowheadWidth, x, y); lineTo (x, y); - perpendicularOffset (endX, endY, startX, startY, - arrowheadLength, -lineThickness, x, y); + PathHelpers::perpendicularOffset (endX, endY, startX, startY, + arrowheadLength, -lineThickness, x, y); lineTo (x, y); closeSubPath(); @@ -754,15 +773,15 @@ void Path::addBubble (float x, float y, lineTo (x, y + cs); if (cs > 0.0f) - addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement); + addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement); closeSubPath(); } } -void Path::addPath (const Path& other) throw() +void Path::addPath (const Path& other) { - int i = 0; + size_t i = 0; while (i < other.numElements) { @@ -814,9 +833,9 @@ void Path::addPath (const Path& other) throw() } void Path::addPath (const Path& other, - const AffineTransform& transformToApply) throw() + const AffineTransform& transformToApply) { - int i = 0; + size_t i = 0; while (i < other.numElements) { @@ -871,7 +890,7 @@ void Path::addPath (const Path& other, //============================================================================== void Path::applyTransform (const AffineTransform& transform) throw() { - int i = 0; + size_t i = 0; pathYMin = pathXMin = 0; pathYMax = pathXMax = 0; bool setMaxMin = false; @@ -954,7 +973,7 @@ void Path::applyTransform (const AffineTransform& transform) throw() const AffineTransform Path::getTransformToScaleToFit (const float x, const float y, const float w, const float h, const bool preserveProportions, - const Justification& justification) const throw() + const Justification& justification) const { Rectangle bounds (getBounds()); @@ -1008,7 +1027,7 @@ const AffineTransform Path::getTransformToScaleToFit (const float x, const float } //============================================================================== -bool Path::contains (const float x, const float y, const float tolerence) const throw() +bool Path::contains (const float x, const float y, const float tolerence) const { if (x <= pathXMin || x >= pathXMax || y <= pathYMin || y >= pathYMax) @@ -1042,7 +1061,7 @@ bool Path::contains (const float x, const float y, const float tolerence) const bool Path::intersectsLine (const float x1, const float y1, const float x2, const float y2, - const float tolerence) throw() + const float tolerence) { PathFlatteningIterator i (*this, AffineTransform::identity, tolerence); @@ -1061,13 +1080,13 @@ bool Path::intersectsLine (const float x1, const float y1, } //============================================================================== -const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw() +const Path Path::createPathWithRoundedCorners (const float cornerRadius) const { if (cornerRadius <= 0.01f) return *this; int indexOfPathStart = 0, indexOfPathStartThis = 0; - int n = 0; + size_t n = 0; bool lastWasLine = false, firstWasLine = false; Path p; @@ -1283,18 +1302,17 @@ void Path::loadPathFromStream (InputStream& source) } } -void Path::loadPathFromData (const unsigned char* const data, - const int numberOfBytes) throw() +void Path::loadPathFromData (const void* const data, const int numberOfBytes) { - MemoryInputStream in ((const char*) data, numberOfBytes, false); + MemoryInputStream in (data, numberOfBytes, false); loadPathFromStream (in); } void Path::writePathToStream (OutputStream& dest) const { - dest.writeByte ((useNonZeroWinding) ? 'n' : 'z'); + dest.writeByte (useNonZeroWinding ? 'n' : 'z'); - int i = 0; + size_t i = 0; while (i < numElements) { const float type = data.elements [i++]; @@ -1344,7 +1362,7 @@ const String Path::toString() const if (! useNonZeroWinding) s << "a "; - int i = 0; + size_t i = 0; float lastMarker = 0.0f; while (i < numElements) @@ -1413,24 +1431,6 @@ const String Path::toString() const return String (result, len); } -static const String nextToken (const tchar*& t) -{ - while (CharacterFunctions::isWhitespace (*t)) - ++t; - - const tchar* const start = t; - - while (*t != 0 && ! CharacterFunctions::isWhitespace (*t)) - ++t; - - const int length = (int) (t - start); - - while (CharacterFunctions::isWhitespace (*t)) - ++t; - - return String (start, length); -} - void Path::restoreFromString (const String& stringVersion) { clear(); @@ -1443,7 +1443,7 @@ void Path::restoreFromString (const String& stringVersion) while (*t != 0) { - const String token (nextToken (t)); + const String token (PathHelpers::nextToken (t)); const tchar firstChar = token[0]; int startNum = 0; @@ -1479,7 +1479,7 @@ void Path::restoreFromString (const String& stringVersion) } for (int i = startNum; i < numValues; ++i) - values [i] = nextToken (t).getFloatValue(); + values [i] = PathHelpers::nextToken (t).getFloatValue(); switch (marker) { diff --git a/src/gui/graphics/geometry/juce_Path.h b/src/gui/graphics/geometry/juce_Path.h index 5bdcc44ef5..0b1061440f 100644 --- a/src/gui/graphics/geometry/juce_Path.h +++ b/src/gui/graphics/geometry/juce_Path.h @@ -74,16 +74,16 @@ class JUCE_API Path public: //============================================================================== /** Creates an empty path. */ - Path() throw(); + Path(); /** Creates a copy of another path. */ - Path (const Path& other) throw(); + Path (const Path& other); /** Destructor. */ - ~Path() throw(); + ~Path(); /** Copies this path from another one. */ - Path& operator= (const Path& other) throw(); + Path& operator= (const Path& other); //============================================================================== /** Returns true if the path doesn't contain any lines or curves. */ @@ -111,9 +111,8 @@ public: @see closeSubPath, setUsingNonZeroWinding */ - bool contains (const float x, - const float y, - const float tolerence = 10.0f) const throw(); + bool contains (float x, float y, + float tolerence = 10.0f) const; /** Checks whether a line crosses the path. @@ -125,9 +124,9 @@ public: is used to trace the path - for more info about it, see the notes for the PathFlatteningIterator constructor. */ - bool intersectsLine (const float x1, const float y1, - const float x2, const float y2, - const float tolerence = 10.0f) throw(); + bool intersectsLine (float x1, float y1, + float x2, float y2, + float tolerence = 10.0f); //============================================================================== /** Removes all lines and curves, resetting the path completely. */ @@ -144,8 +143,7 @@ public: @see lineTo, quadraticTo, cubicTo, closeSubPath */ - void startNewSubPath (const float startX, - const float startY) throw(); + void startNewSubPath (float startX, float startY); /** Closes a the current sub-path with a line back to its start-point. @@ -159,7 +157,7 @@ public: @see startNewSubPath, lineTo, quadraticTo, cubicTo, closeSubPath */ - void closeSubPath() throw(); + void closeSubPath(); /** Adds a line from the shape's last position to a new end-point. @@ -170,8 +168,7 @@ public: @see startNewSubPath, quadraticTo, cubicTo, closeSubPath */ - void lineTo (const float endX, - const float endY) throw(); + void lineTo (float endX, float endY); /** Adds a quadratic bezier curve from the shape's last position to a new position. @@ -182,10 +179,10 @@ public: @see startNewSubPath, lineTo, cubicTo, closeSubPath */ - void quadraticTo (const float controlPointX, - const float controlPointY, - const float endPointX, - const float endPointY) throw(); + void quadraticTo (float controlPointX, + float controlPointY, + float endPointX, + float endPointY); /** Adds a cubic bezier curve from the shape's last position to a new position. @@ -196,12 +193,12 @@ public: @see startNewSubPath, lineTo, quadraticTo, closeSubPath */ - void cubicTo (const float controlPoint1X, - const float controlPoint1Y, - const float controlPoint2X, - const float controlPoint2Y, - const float endPointX, - const float endPointY) throw(); + void cubicTo (float controlPoint1X, + float controlPoint1Y, + float controlPoint2X, + float controlPoint2Y, + float endPointX, + float endPointY); /** Returns the last point that was added to the path by one of the drawing methods. */ @@ -215,8 +212,7 @@ public: @see addRoundedRectangle, addTriangle */ - void addRectangle (const float x, const float y, - const float w, const float h) throw(); + void addRectangle (float x, float y, float width, float height); /** Adds a rectangle to the path. @@ -225,7 +221,7 @@ public: @see addRoundedRectangle, addTriangle */ - void addRectangle (const Rectangle& rectangle) throw(); + void addRectangle (const Rectangle& rectangle); /** Adds a rectangle with rounded corners to the path. @@ -234,9 +230,8 @@ public: @see addRectangle, addTriangle */ - void addRoundedRectangle (const float x, const float y, - const float w, const float h, - float cornerSize) throw(); + void addRoundedRectangle (float x, float y, float width, float height, + float cornerSize); /** Adds a rectangle with rounded corners to the path. @@ -245,10 +240,9 @@ public: @see addRectangle, addTriangle */ - void addRoundedRectangle (const float x, const float y, - const float w, const float h, + void addRoundedRectangle (float x, float y, float width, float height, float cornerSizeX, - float cornerSizeY) throw(); + float cornerSizeY); /** Adds a triangle to the path. @@ -259,9 +253,9 @@ public: order will affect how the triangle is filled when it overlaps other shapes (the winding order setting will affect this of course). */ - void addTriangle (const float x1, const float y1, - const float x2, const float y2, - const float x3, const float y3) throw(); + void addTriangle (float x1, float y1, + float x2, float y2, + float x3, float y3); /** Adds a quadrilateral to the path. @@ -272,10 +266,10 @@ public: order will affect how the quad is filled when it overlaps other shapes (the winding order setting will affect this of course). */ - void addQuadrilateral (const float x1, const float y1, - const float x2, const float y2, - const float x3, const float y3, - const float x4, const float y4) throw(); + void addQuadrilateral (float x1, float y1, + float x2, float y2, + float x3, float y3, + float x4, float y4); /** Adds an ellipse to the path. @@ -284,8 +278,7 @@ public: @see addArc */ - void addEllipse (const float x, const float y, - const float width, const float height) throw(); + void addEllipse (float x, float y, float width, float height); /** Adds an elliptical arc to the current path. @@ -308,11 +301,10 @@ public: @see addCentredArc, arcTo, addPieSegment, addEllipse */ - void addArc (const float x, const float y, - const float width, const float height, - const float fromRadians, - const float toRadians, - const bool startAsNewSubPath = false) throw(); + void addArc (float x, float y, float width, float height, + float fromRadians, + float toRadians, + bool startAsNewSubPath = false); /** Adds an arc which is centred at a given point, and can have a rotation specified. @@ -336,12 +328,12 @@ public: @see addArc, arcTo */ - void addCentredArc (const float centreX, const float centreY, - const float radiusX, const float radiusY, - const float rotationOfEllipse, - const float fromRadians, - const float toRadians, - const bool startAsNewSubPath = false) throw(); + void addCentredArc (float centreX, float centreY, + float radiusX, float radiusY, + float rotationOfEllipse, + float fromRadians, + float toRadians, + bool startAsNewSubPath = false); /** Adds a "pie-chart" shape to the path. @@ -366,11 +358,11 @@ public: @see addArc */ - void addPieSegment (const float x, const float y, - const float width, const float height, - const float fromRadians, - const float toRadians, - const float innerCircleProportionalSize); + void addPieSegment (float x, float y, + float width, float height, + float fromRadians, + float toRadians, + float innerCircleProportionalSize); /** Adds a line with a specified thickness. @@ -379,30 +371,30 @@ public: @see addArrow */ - void addLineSegment (const float startX, const float startY, - const float endX, const float endY, - float lineThickness) throw(); + void addLineSegment (float startX, float startY, + float endX, float endY, + float lineThickness); /** Adds a line with an arrowhead on the end. The arrow is added as a new closed sub-path. (Any currently open paths will be left open). */ - void addArrow (const float startX, const float startY, - const float endX, const float endY, + void addArrow (float startX, float startY, + float endX, float endY, float lineThickness, float arrowheadWidth, - float arrowheadLength) throw(); + float arrowheadLength); /** Adds a star shape to the path. */ - void addStar (const float centreX, - const float centreY, - const int numberOfPoints, - const float innerRadius, - const float outerRadius, - const float startAngle = 0.0f); + void addStar (float centreX, + float centreY, + int numberOfPoints, + float innerRadius, + float outerRadius, + float startAngle = 0.0f); /** Adds a speech-bubble shape to the path. @@ -434,7 +426,7 @@ public: @param pathToAppend the path to add */ - void addPath (const Path& pathToAppend) throw(); + void addPath (const Path& pathToAppend); /** Adds another path to this one, transforming it on the way in. @@ -445,7 +437,7 @@ public: @param transformToApply an optional transform to apply to the incoming vertices */ void addPath (const Path& pathToAppend, - const AffineTransform& transformToApply) throw(); + const AffineTransform& transformToApply); /** Swaps the contents of this path with another one. @@ -476,9 +468,8 @@ public: @see applyTransform, getTransformToScaleToFit */ - void scaleToFit (const float x, const float y, - const float width, const float height, - const bool preserveProportions) throw(); + void scaleToFit (float x, float y, float width, float height, + bool preserveProportions) throw(); /** Returns a transform that can be used to rescale the path to fit into a given space. @@ -497,17 +488,16 @@ public: @see applyTransform, scaleToFit */ - const AffineTransform getTransformToScaleToFit (const float x, const float y, - const float width, const float height, - const bool preserveProportions, - const Justification& justificationType = Justification::centred) const throw(); + const AffineTransform getTransformToScaleToFit (float x, float y, float width, float height, + bool preserveProportions, + const Justification& justificationType = Justification::centred) const; /** Creates a version of this path where all sharp corners have been replaced by curves. Wherever two lines meet at an angle, this will replace the corner with a curve of the given radius. */ - const Path createPathWithRoundedCorners (const float cornerRadius) const throw(); + const Path createPathWithRoundedCorners (float cornerRadius) const; //============================================================================== /** Changes the winding-rule to be used when filling the path. @@ -525,7 +515,7 @@ public: @see isUsingNonZeroWinding */ - void setUsingNonZeroWinding (const bool isNonZeroWinding) throw(); + void setUsingNonZeroWinding (bool isNonZeroWinding) throw(); /** Returns the flag that indicates whether the path should use a non-zero winding rule. @@ -574,7 +564,7 @@ public: //============================================================================== private: const Path& path; - int index; + size_t index; Iterator (const Iterator&); Iterator& operator= (const Iterator&); @@ -600,8 +590,7 @@ public: @see loadPathFromStream, writePathToStream */ - void loadPathFromData (const unsigned char* const data, - const int numberOfBytes) throw(); + void loadPathFromData (const void* data, int numberOfBytes); /** Stores the path by writing it out to a stream. @@ -630,7 +619,7 @@ private: friend class PathFlatteningIterator; friend class Path::Iterator; ArrayAllocationBase data; - int numElements; + size_t numElements; float pathXMin, pathXMax, pathYMin, pathYMax; bool useNonZeroWinding; diff --git a/src/gui/graphics/geometry/juce_PathIterator.cpp b/src/gui/graphics/geometry/juce_PathIterator.cpp index f943408ada..69a0042700 100644 --- a/src/gui/graphics/geometry/juce_PathIterator.cpp +++ b/src/gui/graphics/geometry/juce_PathIterator.cpp @@ -37,7 +37,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== PathFlatteningIterator::PathFlatteningIterator (const Path& path_, const AffineTransform& transform_, - float tolerence_) throw() + float tolerence_) : x2 (0), y2 (0), closesSubPath (false), @@ -48,19 +48,19 @@ PathFlatteningIterator::PathFlatteningIterator (const Path& path_, tolerence (tolerence_ * tolerence_), subPathCloseX (0), subPathCloseY (0), + isIdentityTransform (transform_.isIdentity()), stackBase (32), index (0), stackSize (32) { - isIdentityTransform = transform.isIdentity(); stackPos = stackBase; } -PathFlatteningIterator::~PathFlatteningIterator() throw() +PathFlatteningIterator::~PathFlatteningIterator() { } -bool PathFlatteningIterator::next() throw() +bool PathFlatteningIterator::next() { x1 = x2; y1 = y2; @@ -153,7 +153,7 @@ bool PathFlatteningIterator::next() throw() } else if (type == Path::quadMarker) { - const int offset = (int) (stackPos - stackBase); + const size_t offset = (size_t) (stackPos - stackBase); if (offset >= stackSize - 10) { @@ -203,7 +203,7 @@ bool PathFlatteningIterator::next() throw() } else if (type == Path::cubicMarker) { - const int offset = (int) (stackPos - stackBase); + const size_t offset = (size_t) (stackPos - stackBase); if (offset >= stackSize - 16) { diff --git a/src/gui/graphics/geometry/juce_PathIterator.h b/src/gui/graphics/geometry/juce_PathIterator.h index 3aa3d14cc7..fc3a42625f 100644 --- a/src/gui/graphics/geometry/juce_PathIterator.h +++ b/src/gui/graphics/geometry/juce_PathIterator.h @@ -56,10 +56,10 @@ public: */ PathFlatteningIterator (const Path& path, const AffineTransform& transform = AffineTransform::identity, - float tolerence = 6.0f) throw(); + float tolerence = 6.0f); /** Destructor. */ - ~PathFlatteningIterator() throw(); + ~PathFlatteningIterator(); //============================================================================== /** Fetches the next line segment from the path. @@ -69,7 +69,7 @@ public: @returns false when there are no more lines to fetch. */ - bool next() throw(); + bool next(); /** The x position of the start of the current line segment. */ float x1; @@ -108,11 +108,11 @@ private: const AffineTransform transform; float* points; float tolerence, subPathCloseX, subPathCloseY; - bool isIdentityTransform; + const bool isIdentityTransform; HeapBlock stackBase; float* stackPos; - int index, stackSize; + size_t index, stackSize; PathFlatteningIterator (const PathFlatteningIterator&); PathFlatteningIterator& operator= (const PathFlatteningIterator&); diff --git a/src/gui/graphics/geometry/juce_Rectangle.h b/src/gui/graphics/geometry/juce_Rectangle.h index 296c7c25fa..dce50171a5 100644 --- a/src/gui/graphics/geometry/juce_Rectangle.h +++ b/src/gui/graphics/geometry/juce_Rectangle.h @@ -204,6 +204,12 @@ public: return Rectangle (x + deltaX, y + deltaY, w, h); } + /** Returns a rectangle which is the same as this one moved by a given amount. */ + const Rectangle operator+ (const Point& deltaPosition) const throw() + { + return Rectangle (x + deltaPosition.getX(), y + deltaPosition.getY(), w, h); + } + /** Expands the rectangle by a given amount. Effectively, its new size is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2). @@ -274,7 +280,7 @@ public: } /** Returns true if this co-ordinate is inside the rectangle. */ - bool contains (const Point point) const throw() + bool contains (const Point& point) const throw() { return point.getX() >= x && point.getY() >= y && point.getX() < x + w && point.getY() < y + h; } diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index 13b9e94cee..37197faafb 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -61,91 +61,115 @@ void CriticalSection::exit() const throw() //============================================================================== -struct EventStruct +class WaitableEventImpl { +public: + WaitableEventImpl() + : triggered (false) + { + pthread_cond_init (&condition, 0); + pthread_mutex_init (&mutex, 0); + } + + ~WaitableEventImpl() + { + pthread_cond_destroy (&condition); + pthread_mutex_destroy (&mutex); + } + + bool wait (const int timeOutMillisecs) throw() + { + pthread_mutex_lock (&mutex); + + if (! triggered) + { + if (timeOutMillisecs < 0) + { + do + { + pthread_cond_wait (&condition, &mutex); + } + while (! triggered); + } + else + { + struct timeval now; + gettimeofday (&now, 0); + + struct timespec time; + time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000); + time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000; + + if (time.tv_nsec >= 1000000000) + { + time.tv_nsec -= 1000000000; + time.tv_sec++; + } + + do + { + if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT) + { + pthread_mutex_unlock (&mutex); + return false; + } + } + while (! triggered); + } + } + + triggered = false; + pthread_mutex_unlock (&mutex); + return true; + } + + void signal() throw() + { + pthread_mutex_lock (&mutex); + triggered = true; + pthread_cond_broadcast (&condition); + pthread_mutex_unlock (&mutex); + } + + void reset() throw() + { + pthread_mutex_lock (&mutex); + triggered = false; + pthread_mutex_unlock (&mutex); + } + +private: pthread_cond_t condition; pthread_mutex_t mutex; bool triggered; + + WaitableEventImpl (const WaitableEventImpl&); + WaitableEventImpl& operator= (const WaitableEventImpl&); }; WaitableEvent::WaitableEvent() throw() + : internal (new WaitableEventImpl()) { - EventStruct* const es = new EventStruct(); - es->triggered = false; - - pthread_cond_init (&es->condition, 0); - pthread_mutex_init (&es->mutex, 0); - - internal = es; } WaitableEvent::~WaitableEvent() throw() { - EventStruct* const es = (EventStruct*) internal; - - pthread_cond_destroy (&es->condition); - pthread_mutex_destroy (&es->mutex); - - delete es; + delete static_cast (internal); } bool WaitableEvent::wait (const int timeOutMillisecs) const throw() { - EventStruct* const es = (EventStruct*) internal; - pthread_mutex_lock (&es->mutex); - - if (timeOutMillisecs < 0) - { - while (! es->triggered) - pthread_cond_wait (&es->condition, &es->mutex); - } - else - { - while (! es->triggered) - { - struct timeval t; - gettimeofday (&t, 0); - - struct timespec time; - time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000); - time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000; - - if (time.tv_nsec >= 1000000000) - { - time.tv_nsec -= 1000000000; - time.tv_sec++; - } - - if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT) - { - pthread_mutex_unlock (&es->mutex); - return false; - } - } - } - - es->triggered = false; - pthread_mutex_unlock (&es->mutex); - return true; + return static_cast (internal)->wait (timeOutMillisecs); } void WaitableEvent::signal() const throw() { - EventStruct* const es = (EventStruct*) internal; - - pthread_mutex_lock (&es->mutex); - es->triggered = true; - pthread_cond_broadcast (&es->condition); - pthread_mutex_unlock (&es->mutex); + static_cast (internal)->signal(); } void WaitableEvent::reset() const throw() { - EventStruct* const es = (EventStruct*) internal; - - pthread_mutex_lock (&es->mutex); - es->triggered = false; - pthread_mutex_unlock (&es->mutex); + static_cast (internal)->reset(); } //============================================================================== @@ -239,9 +263,9 @@ bool juce_canWriteToFile (const String& fileName) bool juce_deleteFile (const String& fileName) { if (juce_isDirectory (fileName)) - return rmdir ((const char*) fileName.toUTF8()) == 0; + return rmdir (fileName.toUTF8()) == 0; else - return remove ((const char*) fileName.toUTF8()) == 0; + return remove (fileName.toUTF8()) == 0; } bool juce_moveFile (const String& source, const String& dest) @@ -274,7 +298,7 @@ void* juce_fileOpen (const String& fileName, bool forWriting) { if (juce_fileExists (fileName, false)) { - const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644); + const int f = open (fileName.toUTF8(), O_RDWR, 00644); if (f != -1) lseek (f, 0, SEEK_END); @@ -287,7 +311,7 @@ void* juce_fileOpen (const String& fileName, bool forWriting) } } - return (void*) open ((const char*) fileName.toUTF8(), flags, 00644); + return (void*) open (fileName.toUTF8(), flags, 00644); } void juce_fileClose (void* handle) @@ -398,7 +422,7 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, for (;;) { - if (getattrlist ((const char*) f.getFullPathName().toUTF8(), + if (getattrlist (f.getFullPathName().toUTF8(), &attrList, &attrBuf, sizeof(attrBuf), 0) == 0) { return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset, @@ -421,7 +445,7 @@ const String juce_getVolumeLabel (const String& filenameOnVolume, //============================================================================== void juce_runSystemCommand (const String& command) { - int result = system ((const char*) command.toUTF8()); + int result = system (command.toUTF8()); (void) result; } diff --git a/src/native/linux/juce_linux_FileChooser.cpp b/src/native/linux/juce_linux_FileChooser.cpp index e31bd6aed3..e8bcdebdf1 100644 --- a/src/native/linux/juce_linux_FileChooser.cpp +++ b/src/native/linux/juce_linux_FileChooser.cpp @@ -61,7 +61,7 @@ void FileChooser::showPlatformDialog (Array& results, MemoryOutputStream result; int status = -1; - FILE* stream = popen ((const char*) command.toUTF8(), "r"); + FILE* stream = popen (command.toUTF8(), "r"); if (stream != 0) { diff --git a/src/native/linux/juce_linux_Files.cpp b/src/native/linux/juce_linux_Files.cpp index b175c99b6d..f840d36418 100644 --- a/src/native/linux/juce_linux_Files.cpp +++ b/src/native/linux/juce_linux_Files.cpp @@ -417,7 +417,7 @@ bool juce_launchFile (const String& fileName, cmdString = cmdLines.joinIntoString (T(" || ")); } - const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 }; + const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 }; const int cpid = fork(); diff --git a/src/native/linux/juce_linux_Network.cpp b/src/native/linux/juce_linux_Network.cpp index b07b92e074..1208cbec34 100644 --- a/src/native/linux/juce_linux_Network.cpp +++ b/src/native/linux/juce_linux_Network.cpp @@ -136,12 +136,12 @@ public: if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort)) return false; - host = gethostbyname ((const char*) proxyName.toUTF8()); + host = gethostbyname (proxyName.toUTF8()); port = proxyPort; } else { - host = gethostbyname ((const char*) hostName.toUTF8()); + host = gethostbyname (hostName.toUTF8()); port = hostPort; } diff --git a/src/native/linux/juce_linux_Threads.cpp b/src/native/linux/juce_linux_Threads.cpp index 195d7fea0d..9e36d293cb 100644 --- a/src/native/linux/juce_linux_Threads.cpp +++ b/src/native/linux/juce_linux_Threads.cpp @@ -237,7 +237,7 @@ void Process::lowerPrivilege() void* PlatformUtilities::loadDynamicLibrary (const String& name) { - return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW); + return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW); } void PlatformUtilities::freeDynamicLibrary (void* handle) diff --git a/src/native/mac/juce_mac_CameraDevice.mm b/src/native/mac/juce_mac_CameraDevice.mm index a1babd60e6..26162b9e40 100644 --- a/src/native/mac/juce_mac_CameraDevice.mm +++ b/src/native/mac/juce_mac_CameraDevice.mm @@ -246,7 +246,6 @@ END_JUCE_NAMESPACE fromConnection: (QTCaptureConnection*) connection { const Time now (Time::getCurrentTime()); - int64 presentationTime = ([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute]; @@ -254,10 +253,11 @@ END_JUCE_NAMESPACE NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"]; #endif - if (hosttime != nil) - presentationTime = (int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000; + int64 presentationTime = (hosttime != nil) + ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40) + : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50); - const int64 timeDiff = now.toMilliseconds() - presentationTime - 50; + const int64 timeDiff = now.toMilliseconds() - presentationTime; if (firstPresentationTime == 0) { @@ -302,20 +302,19 @@ CameraDevice::CameraDevice (const String& name_, int index) : name (name_) { isRecording = false; - QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index); - internal = d; + internal = new QTCameraDeviceInteral (this, index); } CameraDevice::~CameraDevice() { stopRecording(); - delete (QTCameraDeviceInteral*) internal; + delete static_cast (internal); internal = 0; } Component* CameraDevice::createViewerComponent() { - return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal); + return new QTCaptureViewerComp (this, static_cast (internal)); } const String CameraDevice::getFileExtension() @@ -327,7 +326,7 @@ void CameraDevice::startRecordingToFile (const File& file, int quality) { stopRecording(); - QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal; + QTCameraDeviceInteral* const d = static_cast (internal); d->callbackDelegate->firstPresentationTime = 0; file.deleteFile(); @@ -364,7 +363,7 @@ void CameraDevice::startRecordingToFile (const File& file, int quality) const Time CameraDevice::getTimeOfFirstRecordedFrame() const { - QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal; + QTCameraDeviceInteral* const d = static_cast (internal); if (d->callbackDelegate->firstPresentationTime != 0) return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset); @@ -375,26 +374,21 @@ void CameraDevice::stopRecording() { if (isRecording) { - QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal; - d->resetFile(); + static_cast (internal)->resetFile(); isRecording = false; } } void CameraDevice::addListener (CameraImageListener* listenerToAdd) { - QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal; - if (listenerToAdd != 0) - d->addListener (listenerToAdd); + static_cast (internal)->addListener (listenerToAdd); } void CameraDevice::removeListener (CameraImageListener* listenerToRemove) { - QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal; - if (listenerToRemove != 0) - d->removeListener (listenerToRemove); + static_cast (internal)->removeListener (listenerToRemove); } //============================================================================== @@ -420,7 +414,7 @@ CameraDevice* CameraDevice::openDevice (int index, { ScopedPointer d (new CameraDevice (getAvailableDevices() [index], index)); - if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty()) + if (static_cast (d->internal)->openingError.isEmpty()) return d.release(); return 0;