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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_ProjectItemID.cpp
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
14ProjectItemID::ProjectItemID (const juce::String& asString) noexcept
15{
16 int mid = 0;
17 int pid = 0;
18 int* number = &pid;
19
20 for (auto p = asString.getCharPointer();; ++p)
21 {
22 auto c = *p;
24
25 if (c == 0)
26 {
27 break; // End of string
28 }
29 else if (hex >= 0)
30 {
31 *number = ((*number) << 4) | hex;
32 }
33 else if ((c == '/' || c == '_') && number == &pid)
34 {
35 number = &mid;
36 }
37 else
38 {
39 // Invalid character encountered
40 mid = 0;
41 pid = 0;
42 break;
43 }
44 }
45
46 *this = ProjectItemID (mid, pid);
47}
48
49ProjectItemID::ProjectItemID (int itemID, int projectID) noexcept
50 : combinedID ((((int64_t) projectID) << 32) | itemID)
51{
52}
53
54int ProjectItemID::getProjectID() const { return (int) (combinedID >> 32); }
55int ProjectItemID::getItemID() const { return (int) combinedID; }
56
57juce::String ProjectItemID::toString() const
58{
60}
61
62juce::String ProjectItemID::toStringSuitableForFilename() const
63{
65}
66
68{
69 return ProjectItemID (juce::Random::getSystemRandom().nextInt (0x3ffffff), projectID);
70}
71
72ProjectItemID ProjectItemID::fromProperty (const juce::ValueTree& v, const juce::Identifier& prop)
73{
74 return ProjectItemID (v.getProperty (prop).toString());
75}
76
77ProjectItemID ProjectItemID::withNewProjectID (int newProjectID) const
78{
79 return { getItemID(), newProjectID };
80}
81
82}} // namespace tracktion { inline namespace engine
static int getHexDigitValue(juce_wchar digit) noexcept
String::CharPointerType getCharPointer() const noexcept
const String & toString() const noexcept
static Random & getSystemRandom() noexcept
static String toHexString(IntegerType number)
An ID representing one of the items in a Project.
static ProjectItemID createNewID(int projectID) noexcept
Generates a new ID for a given project.
int getItemID() const
Returns the ID of the item within the project.
int getProjectID() const
Returns the ID of the project this item belongs to.