11namespace tracktion {
inline namespace engine
30 return v.hasType (IDs::PITCH);
36 t->incReferenceCount();
43 t->decReferenceCount();
46 void newObjectAdded (
PitchSetting*)
override { sendChange(); }
47 void objectRemoved (
PitchSetting*)
override { sendChange(); }
48 void objectOrderChanged()
override { sendChange(); }
53 if (! pitchSequence.getEdit().
isLoading())
57 void handleAsyncUpdate()
override
66PitchSequence::PitchSequence() {}
67PitchSequence::~PitchSequence() {}
69Edit& PitchSequence::getEdit()
const
80void PitchSequence::clear()
82 if (
auto first = getPitch (0))
84 auto pitch = first->getPitch();
86 insertPitch ({}, pitch);
101 if (getNumPitches() == 0)
102 insertPitch ({}, 60);
107void PitchSequence::freeResources()
112void PitchSequence::copyFrom (
const PitchSequence& other)
114 copyValueTree (state, other.state,
nullptr);
118int PitchSequence::getNumPitches()
const {
return list->objects.size(); }
119PitchSetting* PitchSequence::getPitch (
int index)
const {
return list->objects[index]; }
120PitchSetting& PitchSequence::getPitchAt (TimePosition time)
const {
return *list->objects[indexOfPitchAt (time)]; }
122PitchSetting& PitchSequence::getPitchAtBeat (BeatPosition beat)
const
124 for (
int i = list->objects.size(); --i > 0;)
126 auto p = list->objects.getUnchecked (i);
128 if (p->getStartBeatNumber() <= beat)
133 return *list->objects.getFirst();
136int PitchSequence::indexOfPitchAt (TimePosition t)
const
138 for (
int i = list->objects.size(); --i > 0;)
139 if (list->objects.getUnchecked (i)->getPosition().getStart() <= t)
146int PitchSequence::indexOfNextPitchAt (TimePosition t)
const
148 for (
int i = 0; i < list->objects.size(); ++i)
149 if (list->objects.getUnchecked (i)->getPosition().getStart() >= t)
153 return list->objects.size();
156int PitchSequence::indexOfPitch (
const PitchSetting* pitchSetting)
const
158 return list->objects.indexOf ((PitchSetting*) pitchSetting);
161PitchSetting::Ptr PitchSequence::insertPitch (TimePosition time)
166PitchSetting::Ptr PitchSequence::insertPitch (BeatPosition beatNum,
int pitch)
170 if (list->size() > 0)
172 auto&
prev = getPitchAtBeat (beatNum);
175 if (
prev.getStartBeatNumber() == beatNum)
178 prev.setPitch (pitch);
184 pitch =
prev.getPitch();
186 newIndex = indexOfPitch (&prev) + 1;
189 auto v = createValueTree (IDs::PITCH,
190 IDs::startBeat, beatNum.inBeats(),
194 newIndex = list->objects.size();
196 state.
addChild (v, newIndex, getUndoManager());
198 jassert (list->objects[newIndex]->state == v);
199 return list->objects[newIndex];
202void PitchSequence::movePitchStart (PitchSetting& p, BeatDuration deltaBeats,
bool snapToBeat)
204 auto index = indexOfPitch (&p);
206 if (index > 0 && deltaBeats != BeatDuration())
208 if (
auto t = getPitch (index))
210 t->startBeat.forceUpdateOfCachedValue();
211 auto newBeat = t->getStartBeat() + deltaBeats;
213 : newBeat.inBeats())));
221 time =
time - TimeDuration::fromSeconds (0.00001);
223 auto endIndex = indexOfNextPitchAt (
time);
225 for (
int i = getNumPitches(); --i >= endIndex;)
226 movePitchStart (*getPitch (i), BeatDuration::fromBeats (beatsToInsert), snapToBeat);
229void PitchSequence::sortEvents()
235 const double beat1 = p1[IDs::startBeat];
236 const double beat2 = p2[IDs::startBeat];
238 return beat1 < beat2 ? -1 : (beat1 > beat2 ? 1 : 0);
243 state.
sort (sorter, getUndoManager(),
true);
void triggerAsyncUpdate()
void removeAllChildren(UndoManager *undoManager)
void addChild(const ValueTree &child, int index, UndoManager *undoManager)
void sort(ElementComparator &comparator, UndoManager *undoManager, bool retainOrderOfEquivalentItems)
The Tracktion Edit class!
TempoSequence tempoSequence
The global TempoSequence of this Edit.
bool isLoading() const
Returns true if the Edit's not yet fully loaded.
juce::UndoManager & getUndoManager() noexcept
Returns the juce::UndoManager used for this Edit.
void insertSpaceIntoSequence(TimePosition, TimeDuration amountOfSpace, bool snapToBeat)
Inserts space in to a sequence, shifting all PitchSettings.
BeatPosition toBeats(TimePosition) const
Converts a time to a number of beats.
double getBeatsPerSecondAt(TimePosition, bool lengthOfOneBeatDependsOnTimeSignature=false) const
Returns the tempo at a given position.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
int roundToInt(const FloatType value) noexcept
Represents a duration in real-life time.
constexpr double inSeconds() const
Returns the TimeDuration as a number of seconds.
Represents a position in real-life time.