tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MiscUtilities.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
14inline void addSortedListToMenu (juce::PopupMenu& m, juce::StringArray names, int startID)
15{
16 struct ItemWithID
17 {
18 juce::String name;
19 int id;
20
21 bool operator< (const ItemWithID& other) const { return id < other.id; }
22 };
23
25
26 for (const auto& name : names)
27 items.add ({ name, startID++ });
28
29 items.sort();
30
31 for (const auto& i : items)
32 m.addItem (i.id, i.name);
33}
34
35inline juce::AffineTransform getScaleAroundCentre (juce::Rectangle<float> r, float numPixels)
36{
37 jassert (! r.isEmpty());
38 auto cx = r.getCentreX();
39 auto cy = r.getCentreY();
40 auto w = r.getWidth();
41 auto h = r.getHeight();
42
43 return juce::AffineTransform::scale ((w + numPixels) / w, (h + numPixels) / h, cx, cy);
44}
45
46inline void moveXMLAttributeToStart (juce::XmlElement& xml, juce::StringRef att)
47{
48 juce::StringArray names, values;
49 bool wasFound = false;
50
51 for (int i = 0; i < xml.getNumAttributes(); ++i)
52 {
53 auto name = xml.getAttributeName (i);
54 auto value = xml.getAttributeValue (i);
55
56 if (name == att)
57 {
58 wasFound = true;
59 names.insert (0, name);
60 values.insert (0, value);
61 }
62 else
63 {
64 names.add (name);
65 values.add (value);
66 }
67 }
68
69 if (wasFound)
70 {
72
73 for (int i = 0; i < names.size(); ++i)
74 xml.setAttribute (names[i], values[i]);
75 }
76}
77
78template <typename Vector, typename Predicate>
79inline bool removeIf (Vector& v, Predicate&& pred)
80{
81 auto oldEnd = std::end (v);
82 auto newEnd = std::remove_if (std::begin (v), oldEnd, pred);
83
84 if (newEnd == oldEnd)
85 return false;
86
87 v.erase (newEnd, oldEnd);
88 return true;
89}
90
91//==============================================================================
93template <typename FloatingPointType>
94inline bool almostEqual (FloatingPointType firstValue, FloatingPointType secondValue, FloatingPointType precision = (FloatingPointType) 0.00001)
95{
96 return std::abs (firstValue - secondValue) < precision;
97}
98
99//==============================================================================
100using HashCode = int64_t;
101
102//==============================================================================
103//==============================================================================
124
125enum class AuxPosition
126{
127 byBus,
128 byPosition,
129};
130
131}} // namespace tracktion { inline namespace engine
T begin(T... args)
static AffineTransform scale(float factorX, float factorY) noexcept
static JUCEApplicationBase * getInstance() noexcept
static void hideWaitCursor()
static void showWaitCursor()
ValueType getCentreX() const noexcept
ValueType getCentreY() const noexcept
ValueType getWidth() const noexcept
bool isEmpty() const noexcept
ValueType getHeight() const noexcept
void insert(int index, String stringToAdd)
int size() const noexcept
void add(String stringToAdd)
const String & getAttributeValue(int attributeIndex) const noexcept
void removeAllAttributes() noexcept
const String & getAttributeName(int attributeIndex) const noexcept
int getNumAttributes() const noexcept
void setAttribute(const Identifier &attributeName, const String &newValue)
Shows and hides the mouse wait cursor where appropriate.
T end(T... args)
#define jassert(expression)
bool almostEqual(FloatingPointType firstValue, FloatingPointType secondValue, FloatingPointType precision=(FloatingPointType) 0.00001)
Checks to see if two values are equal within a given precision.
T remove_if(T... args)
typedef int64_t