Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
NoteTrack Class Referencefinal

A Track that is used for Midi notes. (Somewhat old code). More...

#include <NoteTrack.h>

Inheritance diagram for NoteTrack:
[legend]
Collaboration diagram for NoteTrack:
[legend]

Classes

struct  Interval
 

Public Types

using Attachments = NoteTrackAttachments
 
using Holder = std::shared_ptr< NoteTrack >
 
- Public Types inherited from Track
using AttachedObjects = ::AttachedTrackObjects
 Alias for my base type. More...
 
using Holder = std::shared_ptr< Track >
 
- Public Types inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
using DataType = ClientData
 
using DataPointer = Pointer< ClientData >
 
using DataFactory = std::function< DataPointer(Host &) >
 Type of function from which RegisteredFactory is constructed; it builds attachments. More...
 
- Public Types inherited from ChannelGroup
enum class  LinkType : int { None = 0 , Group = 2 , Aligned }
 For two tracks describes the type of the linkage. More...
 
using Attachments = ClientData::Site< ChannelGroupData, ClientData::Cloneable<>, ClientData::DeepCopying >
 
using Interval = WideChannelGroupInterval
 
- Public Types inherited from Channel
using Interval = ChannelInterval
 

Public Member Functions

 NoteTrack ()
 
 NoteTrack (const NoteTrack &orig)=delete
 Copy construction hasn't been necessary yet. More...
 
 NoteTrack (const NoteTrack &orig, ProtectedCreationArg &&)=delete
 
virtual ~NoteTrack ()
 
void MoveTo (double origin) override
 Change start time to given time point. More...
 
Alg_seq & GetSeq () const
 
void WarpAndTransposeNotes (double t0, double t1, const TimeWarper &warper, double semitones)
 
void SetSequence (std::unique_ptr< Alg_seq > &&seq)
 
void PrintSequence ()
 
Alg_seq * MakeExportableSeq (std::unique_ptr< Alg_seq > &cleanup) const
 
bool ExportMIDI (const wxString &f) const
 
bool ExportAllegro (const wxString &f) const
 
TrackListHolder Cut (double t0, double t1) override
 Create tracks and modify this track. More...
 
TrackListHolder Copy (double t0, double t1, bool forClipboard=true) const override
 Create new tracks and don't modify this track. More...
 
bool Trim (double t0, double t1)
 
void Clear (double t0, double t1) override
 
void Paste (double t, const Track &src) override
 Weak precondition allows overrides to replicate one channel into many. More...
 
void Silence (double t0, double t1, ProgressReporter reportProgress={}) override
 
void InsertSilence (double t, double len) override
 
bool Shift (double t)
 
QuantizedTimeAndBeat NearestBeatTime (double time) const
 
bool StretchRegion (QuantizedTimeAndBeat t0, QuantizedTimeAndBeat t1, double newDur)
 
bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs) override
 
XMLTagHandlerHandleXMLChild (const std::string_view &tag) override
 
void WriteXML (XMLWriter &xmlFile) const override
 
unsigned GetVisibleChannels () const
 
void SetVisibleChannels (unsigned value)
 
bool IsVisibleChan (int c) const
 
void SetVisibleChan (int c)
 
void ClearVisibleChan (int c)
 
void ToggleVisibleChan (int c)
 
void SoloVisibleChan (int c)
 
const TypeInfoGetTypeInfo () const override
 
Track::Holder PasteInto (AudacityProject &project, TrackList &list) const override
 
size_t NIntervals () const override
 Report the number of intervals. More...
 
- Public Member Functions inherited from UniqueChannelTrack< NoteTrackBase >
size_t NChannels () const override
 Report the number of channels. More...
 
std::shared_ptr< ChannelDoGetChannel (size_t iChannel) override
 Retrieve a channel. More...
 
- Public Member Functions inherited from AudioTrack
 AudioTrack ()
 
 AudioTrack (const Track &orig, ProtectedCreationArg &&a)
 
void WriteXMLAttributes (XMLWriter &WXUNUSED(xmlFile)) const
 
bool HandleXMLAttribute (const std::string_view &, const XMLAttributeValueView &)
 
- Public Member Functions inherited from Track
TrackId GetId () const
 
template<typename Subclass = Track>
std::shared_ptr< Subclass > SharedPointer ()
 
template<typename Subclass = const Track>
auto SharedPointer () const -> std::enable_if_t< std::is_const_v< Subclass >, std::shared_ptr< Subclass > >
 
std::shared_ptr< TrackSubstitutePendingChangedTrack ()
 
std::shared_ptr< const TrackSubstitutePendingChangedTrack () const
 
std::shared_ptr< const TrackSubstituteOriginalTrack () const
 
virtual const TypeInfoGetTypeInfo () const =0
 
virtual const TypeNamesGetTypeNames () const
 
virtual bool SupportsBasicEditing () const
 Whether this track type implements cut-copy-paste; by default, true. More...
 
virtual Holder PasteInto (AudacityProject &project, TrackList &list) const =0
 
virtual bool LinkConsistencyFix (bool doFix=true)
 Check consistency of channel groups, and maybe fix it. More...
 
bool LinkConsistencyCheck ()
 Do the non-mutating part of consistency fix only and return status. More...
 
bool HasOwner () const
 
std::shared_ptr< TrackListGetOwner () const
 
TrackListGetHolder () const
 
LinkType GetLinkType () const noexcept
 
ChannelGroupDataGetGroupData ()
 
const ChannelGroupDataGetGroupData () const
 May make group data on demand, but consider that logically const. More...
 
 Track ()
 
 Track (const Track &orig, ProtectedCreationArg &&)
 
Trackoperator= (const Track &orig)=delete
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual TrackListHolder Duplicate () const
 public nonvirtual duplication function that invokes Clone() More...
 
const wxString & GetName () const
 Name is always the same for all channels of a group. More...
 
void SetName (const wxString &n)
 
bool GetSelected () const
 Selectedness is always the same for all channels of a group. More...
 
virtual void SetSelected (bool s)
 
void OnProjectTempoChange (double newTempo)
 method to set project tempo on track More...
 
virtual TrackListHolder Cut (double t0, double t1)=0
 Create tracks and modify this track. More...
 
virtual TrackListHolder Copy (double t0, double t1, bool forClipboard=true) const =0
 Create new tracks and don't modify this track. More...
 
virtual void Clear (double t0, double t1)=0
 
virtual void Paste (double t, const Track &src)=0
 Weak precondition allows overrides to replicate one channel into many. More...
 
void Paste (double t, const TrackList &src)
 
virtual void SyncLockAdjust (double oldT1, double newT1)
 
virtual void Silence (double t0, double t1, ProgressReporter reportProgress={})=0
 
virtual void InsertSilence (double t, double len)=0
 
bool SameKindAs (const Track &track) const
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions)
 
template<typename R = void, typename ... Functions>
TypeSwitch (const Functions &...functions) const
 
virtual void WriteXML (XMLWriter &xmlFile) const =0
 
virtual std::optional< TranslatableStringGetErrorOpening () const
 
void Notify (bool allChannels, int code=-1)
 
bool Any () const
 
bool IsSelected () const
 
bool IsLeader () const override
 
bool IsSelectedLeader () const
 
void AdjustPositions ()
 
void WriteCommonXMLAttributes (XMLWriter &xmlFile, bool includeNameAndSelected=true) const
 
bool HandleCommonXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
const std::optional< double > & GetProjectTempo () const
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual bool HandleXMLTag (const std::string_view &tag, const AttributesList &attrs)=0
 
virtual void HandleXMLEndTag (const std::string_view &WXUNUSED(tag))
 
virtual void HandleXMLContent (const std::string_view &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const std::string_view &tag)=0
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 
- Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
 ~Site ()
 
 Site ()
 
 Site (const Site &other)
 
Siteoperator= (const Site &other)
 
 Site (Site &&other)
 
Siteoperator= (Site &&other)
 
size_t size () const
 How many attachment pointers are in the Site. More...
 
template<typename Subclass = ClientData>
Subclass & Get (const RegisteredFactory &key)
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = const ClientData>
auto Get (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass & >
 Get reference to an attachment, creating on demand if not present, down-cast it to Subclass. More...
 
template<typename Subclass = ClientData>
Subclass * Find (const RegisteredFactory &key)
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
template<typename Subclass = const ClientData>
auto Find (const RegisteredFactory &key) const -> std::enable_if_t< std::is_const< Subclass >::value, Subclass * >
 Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand. More...
 
template<typename ReplacementPointer >
void Assign (const RegisteredFactory &key, ReplacementPointer &&replacement)
 Reassign Site's pointer to ClientData. More...
 
- Public Member Functions inherited from ChannelGroup
virtual ~ChannelGroup ()
 
double GetStartTime () const
 Get the minimum of Start() values of intervals, or 0 when none. More...
 
double GetEndTime () const
 Get the maximum of End() values of intervals, or 0 when none. More...
 
void ShiftBy (double t)
 Change start time by given duration. More...
 
virtual void MoveTo (double o)=0
 Change start time to given time point. More...
 
virtual bool IsLeader () const =0
 
ChannelGroupDataGetGroupData ()
 Make attachment site on demand as needed. More...
 
const ChannelGroupDataGetGroupData () const
 
ChannelGroupDataFindGroupData ()
 Do not make attachment site on demand if absent. More...
 
const ChannelGroupDataFindGroupData () const
 Do not make attachment site on demand if absent. More...
 
void Init (const ChannelGroup &other)
 Copy, including cloning of attached objects. More...
 
void DestroyGroupData ()
 Leave all attachments null. More...
 
std::unique_ptr< ChannelGroupDataDetachGroupData ()
 Move attachments out. More...
 
void AssignGroupData (std::unique_ptr< ChannelGroupData > pGroupData)
 Replace any previous attachments. More...
 
template<typename ChannelType = Channel>
std::shared_ptr< ChannelType > GetChannel (size_t iChannel)
 Retrieve a channel, cast to the given type. More...
 
template<typename ChannelType = const Channel>
auto GetChannel (size_t iChannel) const -> std::enable_if_t< std::is_const_v< ChannelType >, std::shared_ptr< ChannelType > >
 
template<typename ChannelType = Channel>
IteratorRange< ChannelIterator< ChannelType > > Channels ()
 Get range of channels with mutative access. More...
 
template<typename ChannelType = const Channel>
auto Channels () const -> std::enable_if_t< std::is_const_v< ChannelType >, IteratorRange< ChannelIterator< ChannelType > > >
 Get range of channels with read-only access. More...
 
template<typename IntervalType = Interval>
std::shared_ptr< IntervalType > GetInterval (size_t iInterval)
 Retrieve an interval, cast to the given type. More...
 
template<typename IntervalType = const Interval>
auto GetInterval (size_t iInterval) const -> std::enable_if_t< std::is_const_v< IntervalType >, std::shared_ptr< IntervalType > >
 
template<typename IntervalType = Interval>
IteratorRange< IntervalIterator< IntervalType > > Intervals ()
 Get range of intervals with mutative access. More...
 
template<typename IntervalType = const Interval>
auto Intervals () const -> std::enable_if_t< std::is_const_v< IntervalType >, IteratorRange< IntervalIterator< IntervalType > > >
 Get range of intervals with read-only access. More...
 
- Public Member Functions inherited from Channel
virtual ~Channel ()
 
ChannelGroupGetChannelGroup ()
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
const ChannelGroupGetChannelGroup () const
 Channel object's lifetime is assumed to be nested in its Track's. More...
 
size_t GetChannelIndex () const
 
size_t ReallyGetChannelIndex () const
 
size_t NIntervals () const
 Report the number of intervals. More...
 
template<typename IntervalType = Interval>
std::shared_ptr< IntervalType > GetInterval (size_t iInterval)
 Retrieve an interval, cast to the given type. More...
 
template<typename IntervalType = const Interval>
auto GetInterval (size_t iInterval) const -> std::enable_if_t< std::is_const_v< IntervalType >, std::shared_ptr< IntervalType > >
 
template<typename IntervalType = Interval>
IteratorRange< IntervalIterator< IntervalType > > Intervals ()
 Get range of intervals with mutative access. More...
 
template<typename IntervalType = const Interval>
auto Intervals () const -> std::enable_if_t< std::is_const_v< IntervalType >, IteratorRange< IntervalIterator< IntervalType > > >
 Get range of intervals with read-only access. More...
 
- Public Member Functions inherited from OtherPlayableSequence
virtual ~OtherPlayableSequence ()
 

Static Public Member Functions

static NoteTrackNew (AudacityProject &project)
 
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from AudioTrack
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from Track
template<typename Subclass = Track>
static std::shared_ptr< Subclass > SharedPointer (Track *pTrack)
 
template<typename Subclass = const Track>
static std::shared_ptr< Subclass > SharedPointer (const Track *pTrack)
 
static const TypeInfoClassTypeInfo ()
 
- Static Public Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
static size_t numFactories ()
 How many static factories have been registered with this specialization of Site. More...
 

Static Public Attributes

static EnumSetting< bool > AllegroStyleSetting
 

Private Member Functions

TrackListHolder Clone () const override
 
std::shared_ptr< WideChannelGroupIntervalDoGetInterval (size_t iInterval) override
 Retrieve an interval. More...
 
void AddToDuration (double delta)
 
void DoOnProjectTempoChange (const std::optional< double > &oldTempo, double newTempo) override
 

Private Attributes

std::unique_ptr< Alg_seq > mSeq
 
std::unique_ptr< char[]> mSerializationBuffer
 
long mSerializationLength
 
std::atomic< unsigned > mVisibleChannels { ALL_CHANNELS }
 A bit set; atomic because it may be read by worker threads in playback. More...
 
double mOrigin { 0.0 }
 

Additional Inherited Members

- Protected Member Functions inherited from UniqueChannelTrack< NoteTrackBase >
ChannelGroupDoGetChannelGroup () const override
 Subclass must override. More...
 
- Protected Member Functions inherited from Track
void SetLinkType (LinkType linkType, bool completeList=true)
 
virtual void DoOnProjectTempoChange (const std::optional< double > &oldTempo, double newTempo)=0
 
- Protected Member Functions inherited from ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >
template<typename Function >
void ForEach (const Function &function)
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
void ForEach (const Function &function) const
 Invoke function on each ClientData object that has been created in this. More...
 
template<typename Function >
ClientData * FindIf (const Function &function)
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
template<typename Function >
const ClientData * FindIf (const Function &function) const
 Return pointer to first attachment in this that is not null and satisfies a predicate, or nullptr. More...
 
void BuildAll ()
 For each RegisteredFactory, if the corresponding attachment is absent in this, build and store it. More...
 
virtual std::shared_ptr< ChannelDoGetChannel (size_t iChannel)=0
 Retrieve a channel. More...
 
virtual std::shared_ptr< IntervalDoGetInterval (size_t iInterval)=0
 Retrieve an interval. More...
 
- Protected Member Functions inherited from Channel
virtual ChannelGroupDoGetChannelGroup () const =0
 Subclass must override. More...
 
virtual ChannelGroupReallyDoGetChannelGroup () const
 This is temporary! It defaults to call the above. More...
 
- Protected Attributes inherited from Track
std::weak_ptr< TrackListmList
 
TrackNodePointer mNode {}
 Holds iterator to self, so that TrackList::Find can be constant-time. More...
 
int mIndex
 0-based position of this track in its TrackList More...
 

Detailed Description

A Track that is used for Midi notes. (Somewhat old code).

Definition at line 82 of file NoteTrack.h.

Member Typedef Documentation

◆ Attachments

Definition at line 88 of file NoteTrack.h.

◆ Holder

using NoteTrack::Holder = std::shared_ptr<NoteTrack>

Definition at line 100 of file NoteTrack.h.

Constructor & Destructor Documentation

◆ NoteTrack() [1/3]

NoteTrack::NoteTrack ( )

Definition at line 133 of file NoteTrack.cpp.

135{
136 SetName(_("Note Track"));
137
138 mSeq = NULL;
140}
#define _(s)
Definition: Internat.h:73
std::unique_ptr< Alg_seq > mSeq
Definition: NoteTrack.h:215
long mSerializationLength
Definition: NoteTrack.h:217
void SetName(const wxString &n)
Definition: Track.cpp:61
Generates overrides of channel-related functions.
Definition: Track.h:490

References _, mSeq, mSerializationLength, and Track::SetName().

Here is the call graph for this function:

◆ NoteTrack() [2/3]

NoteTrack::NoteTrack ( const NoteTrack orig)
delete

Copy construction hasn't been necessary yet.

◆ NoteTrack() [3/3]

NoteTrack::NoteTrack ( const NoteTrack orig,
ProtectedCreationArg &&   
)
delete

◆ ~NoteTrack()

NoteTrack::~NoteTrack ( )
virtual

Definition at line 142 of file NoteTrack.cpp.

143{
144}

Member Function Documentation

◆ AddToDuration()

void NoteTrack::AddToDuration ( double  delta)
private

Definition at line 619 of file NoteTrack.cpp.

620{
621 auto &seq = GetSeq();
622#if 0
623 // PRL: Would this be better ?
624 seq.set_real_dur( seq.get_real_dur() + delta );
625#else
626 seq.convert_to_seconds();
627 seq.set_dur( seq.get_dur() + delta );
628#endif
629}
Alg_seq & GetSeq() const
Definition: NoteTrack.cpp:146

References GetSeq().

Referenced by Paste(), and StretchRegion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClassTypeInfo()

auto NoteTrack::ClassTypeInfo ( )
static

Definition at line 587 of file NoteTrack.cpp.

588{
589 return typeInfo();
590}
static const Track::TypeInfo & typeInfo()
Definition: NoteTrack.cpp:574

References typeInfo().

Here is the call graph for this function:

◆ Clear()

void NoteTrack::Clear ( double  t0,
double  t1 
)
overridevirtual

May assume precondition: t0 <= t1

Precondition
IsLeader()

Implements Track.

Definition at line 405 of file NoteTrack.cpp.

406{
407 assert(IsLeader());
408 if (t1 < t0)
410
411 double len = t1-t0;
412
413 auto &seq = GetSeq();
414
415 auto offset = mOrigin;
416 auto start = t0 - offset;
417 if (start < 0.0) {
418 // AlgSeq::clear will shift the cleared interval, not changing len, if
419 // start is negative. That's not what we want to happen.
420 if (len > -start) {
421 seq.clear(0, len + start, false);
422 MoveTo(t0);
423 }
424 else
425 MoveTo(offset - len);
426 }
427 else {
428 //auto delta = -(
429 //( std::min( t1, GetEndTime() ) ) - ( std::max( t0, GetStartTime() ) )
430 //);
431 seq.clear(start, len, false);
432
433 // Not needed
434 // Alg_seq::clear seems to handle this
435 // AddToDuration( delta );
436 }
437}
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
void MoveTo(double origin) override
Change start time to given time point.
Definition: NoteTrack.h:106
double mOrigin
Definition: NoteTrack.h:226
bool IsLeader() const override
Definition: Track.cpp:291

References GetSeq(), Track::IsLeader(), mOrigin, MoveTo(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by anonymous_namespace{EditMenus.cpp}::OnCut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ClearVisibleChan()

void NoteTrack::ClearVisibleChan ( int  c)
inline

Definition at line 170 of file NoteTrack.h.

170 {
171 mVisibleChannels.fetch_and(~CHANNEL_BIT(c), std::memory_order_relaxed); }
#define CHANNEL_BIT(c)
Definition: NoteTrack.h:158
std::atomic< unsigned > mVisibleChannels
A bit set; atomic because it may be read by worker threads in playback.
Definition: NoteTrack.h:225

References CHANNEL_BIT.

◆ Clone()

TrackListHolder NoteTrack::Clone ( ) const
overrideprivatevirtual

Subclass responsibility implements only a part of Duplicate(), copying the track data proper (not associated data such as for groups and views)

Parameters
unstretchIntervalIf set, this time interval's stretching must be applied.
Precondition
!unstretchInterval.has_value() || unstretchInterval->first < unstretchInterval->second
IsLeader()
Postcondition
result: NChannels() == result->NChannels()

Implements Track.

Definition at line 168 of file NoteTrack.cpp.

169{
170 auto duplicate = std::make_shared<NoteTrack>();
171 duplicate->Init(*this);
172 // The duplicate begins life in serialized state. Often the duplicate is
173 // pushed on the Undo stack. Then we want to un-serialize it (or a further
174 // copy) only on demand after an Undo.
175 if (mSeq) {
177 wxASSERT(!mSerializationBuffer);
178 // serialize from this to duplicate's mSerializationBuffer
179 void *buffer;
180 mSeq->serialize(&buffer,
181 &duplicate->mSerializationLength);
182 duplicate->mSerializationBuffer.reset( (char*)buffer );
184 }
185 else if (mSerializationBuffer) {
186 // Copy already serialized data.
187 wxASSERT(!mSeq);
188 duplicate->mSerializationLength = this->mSerializationLength;
189 duplicate->mSerializationBuffer.reset
190 ( safenew char[ this->mSerializationLength ] );
191 memcpy( duplicate->mSerializationBuffer.get(),
192 this->mSerializationBuffer.get(), this->mSerializationLength );
193 }
194 else {
195 // We are duplicating a default-constructed NoteTrack, and that's okay
196 }
197
198 // copy some other fields here
199 Attachments &attachments = *duplicate;
200 attachments = *this;
201
202 duplicate->SetVisibleChannels(GetVisibleChannels());
203 duplicate->MoveTo(mOrigin);
204#ifdef EXPERIMENTAL_MIDI_OUT
205 duplicate->SetVelocity(GetVelocity());
206#endif
207 return TrackList::Temporary(nullptr, duplicate, nullptr);
208}
#define safenew
Definition: MemoryX.h:10
#define SonifyEndSerialize()
Definition: NoteTrack.h:248
#define SonifyBeginSerialize()
Definition: NoteTrack.h:247
NoteTrackAttachments Attachments
Definition: NoteTrack.h:88
std::unique_ptr< char[]> mSerializationBuffer
Definition: NoteTrack.h:216
unsigned GetVisibleChannels() const
Definition: NoteTrack.h:159
static TrackListHolder Temporary(AudacityProject *pProject, const Track::Holder &left={}, const Track::Holder &right={})
Definition: Track.cpp:1418

References GetVisibleChannels(), mOrigin, mSeq, mSerializationBuffer, mSerializationLength, safenew, SonifyBeginSerialize, SonifyEndSerialize, and TrackList::Temporary().

Here is the call graph for this function:

◆ Copy()

TrackListHolder NoteTrack::Copy ( double  t0,
double  t1,
bool  forClipboard = true 
) const
overridevirtual

Create new tracks and don't modify this track.

Returns
non-NULL or else throw Note that subclasses may want to distinguish tracks stored in a clipboard from those stored in a project May assume precondition: t0 <= t1 Should invoke Track::Init
Precondition
IsLeader
Postcondition
result: result->NChannels() == NChannels()

Implements Track.

Definition at line 358 of file NoteTrack.cpp.

359{
360 if (t1 < t0)
362
363 double len = t1-t0;
364
365 auto newTrack = std::make_shared<NoteTrack>();
366
367 newTrack->Init(*this);
368
369 auto &seq = GetSeq();
370 seq.convert_to_seconds();
371 newTrack->mSeq.reset(seq.copy(t0 - mOrigin, len, false));
372 newTrack->MoveTo(0);
373
374 // What should be done with the rest of newTrack's members?
375 // (mBottomNote, mSerializationBuffer,
376 // mSerializationLength, mVisibleChannels)
377
378 return TrackList::Temporary(nullptr, newTrack, nullptr);
379}

References GetSeq(), mOrigin, TrackList::Temporary(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by anonymous_namespace{EditMenus.cpp}::OnCut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Cut()

TrackListHolder NoteTrack::Cut ( double  t0,
double  t1 
)
overridevirtual

Create tracks and modify this track.

Returns
non-NULL or else throw May assume precondition: t0 <= t1
Precondition
IsLeader()
Postcondition
result: result->NChannels() == NChannels()

Implements Track.

Definition at line 327 of file NoteTrack.cpp.

328{
329 assert(IsLeader());
330 if (t1 < t0)
332
333 double len = t1-t0;
334 //auto delta = -(
335 //( std::min( t1, GetEndTime() ) ) - ( std::max( t0, GetStartTime() ) )
336 //);
337
338 auto newTrack = std::make_shared<NoteTrack>();
339
340 newTrack->Init(*this);
341
342 auto &seq = GetSeq();
343 seq.convert_to_seconds();
344 newTrack->mSeq.reset(seq.cut(t0 - mOrigin, len, false));
345 newTrack->MoveTo(0);
346
347 // Not needed
348 // Alg_seq::cut seems to handle this
349 //AddToDuration( delta );
350
351 // What should be done with the rest of newTrack's members?
352 //(mBottomNote,
353 // mSerializationBuffer, mSerializationLength, mVisibleChannels)
354
355 return TrackList::Temporary(nullptr, newTrack, nullptr);
356}

References GetSeq(), Track::IsLeader(), mOrigin, TrackList::Temporary(), and THROW_INCONSISTENCY_EXCEPTION.

Referenced by anonymous_namespace{EditMenus.cpp}::OnCut().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoGetInterval()

std::shared_ptr< WideChannelGroupInterval > NoteTrack::DoGetInterval ( size_t  iInterval)
overrideprivatevirtual

Retrieve an interval.

Postcondition
result: !(iInterval < NIntervals()) || result

Implements ChannelGroup.

Definition at line 608 of file NoteTrack.cpp.

609{
610 if (iInterval == 0) {
611 // Just one, and no extra info in it!
612 const auto start = mOrigin;
613 const auto end = start + GetSeq().get_real_dur();
614 return std::make_shared<Interval>(*this, start, end);
615 }
616 return {};
617}
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References PackedArray::end(), GetSeq(), and mOrigin.

Here is the call graph for this function:

◆ DoOnProjectTempoChange()

void NoteTrack::DoOnProjectTempoChange ( const std::optional< double > &  oldTempo,
double  newTempo 
)
overrideprivatevirtual
Precondition
IsLeader()

Implements Track.

Definition at line 211 of file NoteTrack.cpp.

213{
214 assert(IsLeader());
215 if (!oldTempo.has_value())
216 return;
217 const auto ratio = *oldTempo / newTempo;
218 auto& seq = GetSeq();
219 seq.convert_to_beats();
220 const auto b1 = seq.get_dur();
221 seq.convert_to_seconds();
222 const auto newDuration = seq.get_dur() * ratio;
223 seq.stretch_region(0, b1, newDuration);
224 seq.set_real_dur(newDuration);
225}

References GetSeq(), and Track::IsLeader().

Here is the call graph for this function:

◆ ExportAllegro()

bool NoteTrack::ExportAllegro ( const wxString &  f) const

Definition at line 800 of file NoteTrack.cpp.

801{
802 double offset = mOrigin;
803 auto in_seconds = AllegroStyleSetting.ReadEnum();
804 auto &seq = GetSeq();
805 if (in_seconds) {
806 seq.convert_to_seconds();
807 } else {
808 seq.convert_to_beats();
809 }
810 return seq.write(f.mb_str(), offset);
811}
Enum ReadEnum() const
Definition: Prefs.h:532
static EnumSetting< bool > AllegroStyleSetting
Definition: NoteTrack.h:89

References AllegroStyleSetting, GetSeq(), mOrigin, and EnumSetting< Enum >::ReadEnum().

Here is the call graph for this function:

◆ ExportMIDI()

bool NoteTrack::ExportMIDI ( const wxString &  f) const

Definition at line 776 of file NoteTrack.cpp.

777{
778 std::unique_ptr<Alg_seq> cleanup;
779 auto seq = MakeExportableSeq(cleanup);
780 bool rslt = seq->smf_write(f.mb_str());
781 return rslt;
782}
Alg_seq * MakeExportableSeq(std::unique_ptr< Alg_seq > &cleanup) const
Definition: NoteTrack.cpp:653

References MakeExportableSeq().

Here is the call graph for this function:

◆ GetSeq()

Alg_seq & NoteTrack::GetSeq ( ) const

Definition at line 146 of file NoteTrack.cpp.

147{
148 if (!mSeq) {
150 mSeq = std::make_unique<Alg_seq>();
151 else {
152 std::unique_ptr<Alg_track> alg_track
153 { Alg_seq::unserialize
155 wxASSERT(alg_track->get_type() == 's');
156 mSeq.reset( static_cast<Alg_seq*>(alg_track.release()) );
157
158 // Preserve the invariant that at most one of the representations is
159 // valid
160 mSerializationBuffer.reset();
162 }
163 }
164 wxASSERT(mSeq);
165 return *mSeq;
166}

References mSeq, mSerializationBuffer, and mSerializationLength.

Referenced by AddToDuration(), Clear(), Copy(), Cut(), DoGetInterval(), DoOnProjectTempoChange(), anonymous_namespace{NoteTrackView.cpp}::DrawNoteBackground(), anonymous_namespace{NoteTrackView.cpp}::DrawNoteTrack(), ExportAllegro(), anonymous_namespace{ImportMIDI.cpp}::ImportMIDI(), InsertSilence(), MakeExportableSeq(), NearestBeatTime(), Paste(), Shift(), Silence(), StretchRegion(), Trim(), WarpAndTransposeNotes(), and WriteXML().

Here is the caller graph for this function:

◆ GetTypeInfo()

auto NoteTrack::GetTypeInfo ( ) const
overridevirtual

Implements Track.

Definition at line 582 of file NoteTrack.cpp.

583{
584 return typeInfo();
585}

References typeInfo().

Here is the call graph for this function:

◆ GetVisibleChannels()

unsigned NoteTrack::GetVisibleChannels ( ) const
inline

Definition at line 159 of file NoteTrack.h.

159 {
160 return mVisibleChannels.load(std::memory_order_relaxed);
161 }

Referenced by Clone(), and WriteXML().

Here is the caller graph for this function:

◆ HandleXMLChild()

XMLTagHandler * NoteTrack::HandleXMLChild ( const std::string_view &  tag)
overridevirtual

Implements XMLTagHandler.

Definition at line 862 of file NoteTrack.cpp.

863{
864 return NULL;
865}

◆ HandleXMLTag()

bool NoteTrack::HandleXMLTag ( const std::string_view &  tag,
const AttributesList attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 821 of file NoteTrack.cpp.

822{
823 if (tag == "notetrack") {
824 for (auto pair : attrs)
825 {
826 auto attr = pair.first;
827 auto value = pair.second;
828
829 long nValue;
830 double dblValue;
831 if (this->Track::HandleCommonXMLAttribute(attr, value))
832 ;
833 else if (this->Attachments::FindIf([&](auto &attachment){
834 return attachment.HandleAttribute(pair);
835 }))
836 ;
837 else if (this->NoteTrackBase::HandleXMLAttribute(attr, value))
838 {}
839 else if (attr == "offset" && value.TryGet(dblValue))
840 MoveTo(dblValue);
841 else if (attr == "visiblechannels") {
842 if (!value.TryGet(nValue) ||
843 !IsValidVisibleChannels(nValue))
844 return false;
845 SetVisibleChannels(nValue);
846 }
847#ifdef EXPERIMENTAL_MIDI_OUT
848 else if (attr == "velocity" && value.TryGet(dblValue))
849 DoSetVelocity(static_cast<float>(dblValue));
850#endif
851 else if (attr == "data") {
852 std::string s(value.ToWString());
853 std::istringstream data(s);
854 mSeq = std::make_unique<Alg_seq>(data, false);
855 }
856 } // while
857 return true;
858 }
859 return false;
860}
bool HandleXMLAttribute(const std::string_view &, const XMLAttributeValueView &)
Definition: PlayableTrack.h:32
ClientData * FindIf(const Function &function)
Return pointer to first attachment in this that is not null and satisfies a predicate,...
Definition: ClientData.h:420
void SetVisibleChannels(unsigned value)
Definition: NoteTrack.h:162
bool HandleCommonXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView)
Definition: Track.cpp:1235
bool IsValidVisibleChannels(const int nValue)
Definition: NoteTrack.cpp:815

References ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::FindIf(), Track::HandleCommonXMLAttribute(), AudioTrack::HandleXMLAttribute(), anonymous_namespace{NoteTrack.cpp}::IsValidVisibleChannels(), MoveTo(), mSeq, and SetVisibleChannels().

Here is the call graph for this function:

◆ InsertSilence()

void NoteTrack::InsertSilence ( double  t,
double  len 
)
overridevirtual

May assume precondition: t0 <= t1

Precondition
IsLeader()

Implements Track.

Definition at line 505 of file NoteTrack.cpp.

506{
507 assert(IsLeader());
508 if (len < 0)
510
511 auto &seq = GetSeq();
512 seq.convert_to_seconds();
513 seq.insert_silence(t - mOrigin, len);
514
515 // is this needed?
516 // AddToDuration( len );
517}

References GetSeq(), Track::IsLeader(), mOrigin, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by Paste().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsVisibleChan()

bool NoteTrack::IsVisibleChan ( int  c) const
inline

Definition at line 165 of file NoteTrack.h.

165 {
166 return (GetVisibleChannels() & CHANNEL_BIT(c)) != 0;
167 }

References CHANNEL_BIT.

Referenced by anonymous_namespace{NoteTrackControls.cpp}::DrawLabelControls(), anonymous_namespace{NoteTrackView.cpp}::DrawNoteTrack(), and anonymous_namespace{MIDIPlay.h}::Iterator::Unmuted().

Here is the caller graph for this function:

◆ MakeExportableSeq()

Alg_seq * NoteTrack::MakeExportableSeq ( std::unique_ptr< Alg_seq > &  cleanup) const

Definition at line 653 of file NoteTrack.cpp.

654{
655 cleanup.reset();
656 double offset = mOrigin;
657 if (offset == 0)
658 return &GetSeq();
659 // make a copy, deleting events that are shifted before time 0
660 double start = -offset;
661 if (start < 0) start = 0;
662 // notes that begin before "start" are not included even if they
663 // extend past "start" (because "all" parameter is set to false)
664 cleanup.reset( GetSeq().copy(start, GetSeq().get_dur() - start, false) );
665 auto seq = cleanup.get();
666 if (offset > 0) {
667 {
668 // swap cleanup and mSeq so that Shift operates on the NEW copy
669 swap( this->mSeq, cleanup );
670 auto cleanup2 = finally( [&] { swap( this->mSeq, cleanup ); } );
671
672 const_cast< NoteTrack *>( this )->Shift(offset);
673 }
674#ifdef OLD_CODE
675 // now shift events by offset. This must be done with an integer
676 // number of measures, so first, find the beats-per-measure
677 double beats_per_measure = 4.0;
678 Alg_time_sig_ptr tsp = NULL;
679 if (seq->time_sig.length() > 0 && seq->time_sig[0].beat < ALG_EPS) {
680 // there is an initial time signature
681 tsp = &(seq->time_sig[0]);
682 beats_per_measure = (tsp->num * 4) / tsp->den;
683 }
684 // also need the initial tempo
685 double bps = ALG_DEFAULT_BPM / 60;
686 Alg_time_map_ptr map = seq->get_time_map();
687 Alg_beat_ptr bp = &(map->beats[0]);
688 if (bp->time < ALG_EPS) { // tempo change at time 0
689 if (map->beats.len > 1) { // compute slope to get tempo
690 bps = (map->beats[1].beat - map->beats[0].beat) /
691 (map->beats[1].time - map->beats[0].time);
692 } else if (seq->get_time_map()->last_tempo_flag) {
693 bps = seq->get_time_map()->last_tempo;
694 }
695 }
696 // find closest number of measures to fit in the gap
697 // number of measures is offset / measure_time
698 double measure_time = beats_per_measure / bps; // seconds per measure
699 int n = ROUND(offset / measure_time);
700 if (n == 0) n = 1;
701 // we will insert n measures. Compute the desired duration of each.
702 measure_time = offset / n;
703 bps = beats_per_measure / measure_time;
704 // insert integer multiple of measures at beginning
705 seq->convert_to_beats();
706 seq->insert_silence(0, beats_per_measure * n);
707 // make sure time signature at 0 is correct
708 if (tsp) {
709 seq->set_time_sig(0, tsp->num, tsp->den);
710 }
711 // adjust tempo to match offset
712 seq->set_tempo(bps * 60.0, 0, beats_per_measure * n);
713#endif
714 } else {
715 auto &mySeq = GetSeq();
716 // if offset is negative, it might not be a multiple of beats, but
717 // we want to preserve the relative positions of measures. I.e. we
718 // should shift barlines and time signatures as well as notes.
719 // Insert a time signature at the first bar-line if necessary.
720
721 // Translate start from seconds to beats and call it beat:
722 double beat = mySeq.get_time_map()->time_to_beat(start);
723 // Find the time signature in mySeq in effect at start (beat):
724 int i = mySeq.time_sig.find_beat(beat);
725 // i is where you would insert a NEW time sig at beat,
726 // Case 1: beat coincides with a time sig at i. Time signature
727 // at beat means that there is a barline at beat, so when beat
728 // is shifted to 0, the relative barline positions are preserved
729 if (mySeq.time_sig.length() > 0 &&
730 within(beat, mySeq.time_sig[i].beat, ALG_EPS)) {
731 // beat coincides with time signature change, so offset must
732 // be a multiple of beats
733 /* do nothing */ ;
734 // Case 2: there is no time signature before beat.
735 } else if (i == 0 && (mySeq.time_sig.length() == 0 ||
736 mySeq.time_sig[i].beat > beat)) {
737 // If beat does not fall on an implied barline, we need to
738 // insert a time signature.
739 double measures = beat / 4.0;
740 double imeasures = ROUND(measures);
741 if (!within(measures, imeasures, ALG_EPS)) {
742 double bar_offset = ((int)(measures) + 1) * 4.0 - beat;
743 seq->set_time_sig(bar_offset, 4, 4);
744 }
745 // This case should never be true because if i == 0, either there
746 // are no time signatures before beat (Case 2),
747 // or there is one time signature at beat (Case 1)
748 } else if (i == 0) {
749 /* do nothing (might be good to assert(false)) */ ;
750 // Case 3: i-1 must be the effective time sig position
751 } else {
752 i -= 1; // index the time signature in effect at beat
753 Alg_time_sig_ptr tsp = &(mySeq.time_sig[i]);
754 double beats_per_measure = (tsp->num * 4) / tsp->den;
755 double measures = (beat - tsp->beat) / beats_per_measure;
756 int imeasures = ROUND(measures);
757 if (!within(measures, imeasures, ALG_EPS)) {
758 // beat is not on a measure, so we need to insert a time sig
759 // to force a bar line at the first measure location after
760 // beat
761 double bar = tsp->beat + beats_per_measure * ((int)(measures) + 1);
762 double bar_offset = bar - beat;
763 // insert NEW time signature at bar_offset in NEW sequence
764 // It will have the same time signature, but the position will
765 // force a barline to match the barlines in mSeq
766 seq->set_time_sig(bar_offset, tsp->num, tsp->den);
767 }
768 // else beat coincides with a barline, so no need for an extra
769 // time signature to force barline alignment
770 }
771 }
772 return seq;
773}
#define ROUND(x)
Definition: NoteTrack.cpp:29
bool within(A a, B b, DIST d)
Definition: TrackPanel.cpp:169
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:86
bool Shift(double t)
Definition: NoteTrack.cpp:536
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:645
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::vo::copy(), GetSeq(), mOrigin, mSeq, ROUND, Shift(), anonymous_namespace{NoteTrack.cpp}::swap(), and within().

Referenced by ExportMIDI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MoveTo()

void NoteTrack::MoveTo ( double  o)
inlineoverridevirtual

Change start time to given time point.

Implements ChannelGroup.

Definition at line 106 of file NoteTrack.h.

106{ mOrigin = origin; }

Referenced by Clear(), HandleXMLTag(), anonymous_namespace{ImportMIDI.cpp}::ImportMIDI(), Paste(), and Trim().

Here is the caller graph for this function:

◆ NearestBeatTime()

QuantizedTimeAndBeat NoteTrack::NearestBeatTime ( double  time) const

Definition at line 563 of file NoteTrack.cpp.

564{
565 // Alg_seq knows nothing about offset, so remove offset time
566 double seq_time = time - mOrigin;
567 double beat;
568 auto &seq = GetSeq();
569 seq_time = seq.nearest_beat_time(seq_time, &beat);
570 // add the offset back in to get "actual" audacity track time
571 return { seq_time + mOrigin, beat };
572}

References GetSeq(), and mOrigin.

Here is the call graph for this function:

◆ New()

NoteTrack * NoteTrack::New ( AudacityProject project)
static

Definition at line 125 of file NoteTrack.cpp.

126{
127 auto &tracks = TrackList::Get( project );
128 auto result = tracks.Add( std::make_shared<NoteTrack>());
129 result->AttachedTrackObjects::BuildAll();
130 return result;
131}
const auto tracks
const auto project
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:347

References TrackList::Get(), project, and tracks.

Here is the call graph for this function:

◆ NIntervals()

size_t NoteTrack::NIntervals ( ) const
overridevirtual

Report the number of intervals.

Implements ChannelGroup.

Definition at line 602 of file NoteTrack.cpp.

603{
604 return 1;
605}

◆ Paste()

void NoteTrack::Paste ( double  t,
const Track src 
)
overridevirtual

Weak precondition allows overrides to replicate one channel into many.

Precondition
IsLeader()
SameKindAs(src)
src.NChannels() == 1 || src.NChannels() == NChannels()

Implements Track.

Definition at line 439 of file NoteTrack.cpp.

440{
441 // Paste inserts src at time t. If src has a positive offset,
442 // the offset is treated as silence which is also inserted. If
443 // the offset is negative, the offset is ignored and the ENTIRE
444 // src is inserted (otherwise, we would either lose data from
445 // src by not inserting things at negative times, or inserting
446 // things at negative times could overlap things already in
447 // the destination track).
448
449 //Check that src is a non-NULL NoteTrack
450 bool bOk = src.TypeSwitch<bool>( [&](const NoteTrack &other) {
451
452 auto myOffset = this->mOrigin;
453 if (t < myOffset) {
454 // workaround strange behavior described at
455 // http://bugzilla.audacityteam.org/show_bug.cgi?id=1735#c3
456 MoveTo(t);
457 InsertSilence(t, myOffset - t);
458 }
459
460 double delta = 0.0;
461 auto &seq = GetSeq();
462 auto offset = other.mOrigin;
463 if (offset > 0) {
464 seq.convert_to_seconds();
465 seq.insert_silence(t - mOrigin, offset);
466 t += offset;
467 // Is this needed or does Alg_seq::insert_silence take care of it?
468 //delta += offset;
469 }
470
471 // This seems to be needed:
472 delta += std::max(0.0, t - GetEndTime());
473
474 // This, not:
475 //delta += other.GetSeq().get_real_dur();
476
477 seq.paste(t - mOrigin, &other.GetSeq());
478
479 AddToDuration(delta);
480
481 return true;
482 });
483
484 if (!bOk)
485 // THROW_INCONSISTENCY_EXCEPTION; // ?
486 (void)0;// intentionally do nothing
487}
double GetEndTime() const
Get the maximum of End() values of intervals, or 0 when none.
Definition: Channel.cpp:135
void AddToDuration(double delta)
Definition: NoteTrack.cpp:619
void InsertSilence(double t, double len) override
Definition: NoteTrack.cpp:505
R TypeSwitch(const Functions &...functions)
Definition: Track.h:418

References AddToDuration(), ChannelGroup::GetEndTime(), GetSeq(), InsertSilence(), mOrigin, MoveTo(), and Track::TypeSwitch().

Here is the call graph for this function:

◆ PasteInto()

Track::Holder NoteTrack::PasteInto ( AudacityProject project,
TrackList list 
) const
overridevirtual

Find or create the destination track for a paste, maybe in a different project

Precondition
IsLeader()
Parameters
listto which any newly created tracks are added; but left unchanged if an existing track is found in the project instead
Returns
A smart pointer to a leader track

Implements Track.

Definition at line 592 of file NoteTrack.cpp.

593{
594 assert(IsLeader());
595 auto pNewTrack = std::make_shared<NoteTrack>();
596 pNewTrack->Init(*this);
597 pNewTrack->Paste(0.0, *this);
598 list.Add(pNewTrack);
599 return pNewTrack;
600}
TrackKind * Add(const std::shared_ptr< TrackKind > &t)
Definition: Track.h:1183

References TrackList::Add(), and Track::IsLeader().

Here is the call graph for this function:

◆ PrintSequence()

void NoteTrack::PrintSequence ( )

Definition at line 268 of file NoteTrack.cpp.

269{
270 FILE *debugOutput;
271
272 debugOutput = fopen("debugOutput.txt", "wt");
273 wxFprintf(debugOutput, "Importing MIDI...\n");
274
275 // This is called for debugging purposes. Do not compute mSeq on demand
276 // with GetSeq()
277 if (mSeq) {
278 int i = 0;
279
280 while(i < mSeq->length()) {
281 wxFprintf(debugOutput, "--\n");
282 wxFprintf(debugOutput, "type: %c\n",
283 ((Alg_event_ptr)mSeq->track_list.tracks[i])->get_type());
284 wxFprintf(debugOutput, "time: %f\n",
285 ((Alg_event_ptr)mSeq->track_list.tracks[i])->time);
286 wxFprintf(debugOutput, "channel: %li\n",
287 ((Alg_event_ptr)mSeq->track_list.tracks[i])->chan);
288
289 if(((Alg_event_ptr)mSeq->track_list.tracks[i])->get_type() == wxT('n'))
290 {
291 wxFprintf(debugOutput, "pitch: %f\n",
292 ((Alg_note_ptr)mSeq->track_list.tracks[i])->pitch);
293 wxFprintf(debugOutput, "duration: %f\n",
294 ((Alg_note_ptr)mSeq->track_list.tracks[i])->dur);
295 wxFprintf(debugOutput, "velocity: %f\n",
296 ((Alg_note_ptr)mSeq->track_list.tracks[i])->loud);
297 }
298 else if(((Alg_event_ptr)mSeq->track_list.tracks[i])->get_type() == wxT('n'))
299 {
300 wxFprintf(debugOutput, "key: %li\n", ((Alg_update_ptr)mSeq->track_list.tracks[i])->get_identifier());
301 wxFprintf(debugOutput, "attribute type: %c\n", ((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.attr_type());
302 wxFprintf(debugOutput, "attribute: %s\n", ((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.attr_name());
303
304 if(((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.attr_type() == wxT('r'))
305 {
306 wxFprintf(debugOutput, "value: %f\n", ((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.r);
307 }
308 else if(((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.attr_type() == wxT('i')) {
309 wxFprintf(debugOutput, "value: %li\n", ((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.i);
310 }
311 else if(((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.attr_type() == wxT('s')) {
312 wxFprintf(debugOutput, "value: %s\n", ((Alg_update_ptr)mSeq->track_list.tracks[i])->parameter.s);
313 }
314 else {}
315 }
316
317 i++;
318 }
319 }
320 else {
321 wxFprintf(debugOutput, "No sequence defined!\n");
322 }
323
324 fclose(debugOutput);
325}
wxT("CloseDown"))

References mSeq, and wxT().

Here is the call graph for this function:

◆ SetSequence()

void NoteTrack::SetSequence ( std::unique_ptr< Alg_seq > &&  seq)

Definition at line 263 of file NoteTrack.cpp.

264{
265 mSeq = std::move(seq);
266}

References mSeq.

Referenced by anonymous_namespace{ImportMIDI.cpp}::ImportMIDI().

Here is the caller graph for this function:

◆ SetVisibleChan()

void NoteTrack::SetVisibleChan ( int  c)
inline

Definition at line 168 of file NoteTrack.h.

168 {
169 mVisibleChannels.fetch_or(CHANNEL_BIT(c), std::memory_order_relaxed); }

References CHANNEL_BIT.

◆ SetVisibleChannels()

void NoteTrack::SetVisibleChannels ( unsigned  value)
inline

Definition at line 162 of file NoteTrack.h.

162 {
163 mVisibleChannels.store(value, std::memory_order_relaxed);
164 }

Referenced by HandleXMLTag().

Here is the caller graph for this function:

◆ Shift()

bool NoteTrack::Shift ( double  t)

Definition at line 536 of file NoteTrack.cpp.

537{
538 if (t > 0) {
539 auto &seq = GetSeq();
540 // insert an even number of measures
541 seq.convert_to_beats();
542 // get initial tempo
543 double tempo = seq.get_tempo(0.0);
544 double beats_per_measure = seq.get_bar_len(0.0);
545 int m = ROUND(t * tempo / beats_per_measure);
546 // need at least 1 measure, so if we rounded down to zero, fix it
547 if (m == 0) m = 1;
548 // compute NEW tempo so that m measures at NEW tempo take t seconds
549 tempo = beats_per_measure * m / t; // in beats per second
550 seq.insert_silence(0.0, beats_per_measure * m);
551 seq.set_tempo(tempo * 60.0 /* bpm */, 0.0, beats_per_measure * m);
552 seq.write("afterShift.gro");
553 } else if (t < 0) {
554 auto &seq = GetSeq();
555 seq.convert_to_seconds();
556 seq.clear(0, t, true);
557 } else { // offset is zero, no modifications
558 return false;
559 }
560 return true;
561}

References GetSeq(), and ROUND.

Referenced by MakeExportableSeq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Silence()

void NoteTrack::Silence ( double  t0,
double  t1,
ProgressReporter  reportProgress = {} 
)
overridevirtual
Precondition
IsLeader()

Implements Track.

Definition at line 489 of file NoteTrack.cpp.

490{
491 assert(IsLeader());
492 if (t1 < t0)
494
495 auto len = t1 - t0;
496
497 auto &seq = GetSeq();
498 seq.convert_to_seconds();
499 // XXX: do we want to set the all param?
500 // If it's set, then it seems like notes are silenced if they start or end in the range,
501 // otherwise only if they start in the range. --Poke
502 seq.silence(t0 - mOrigin, len, false);
503}

References GetSeq(), Track::IsLeader(), mOrigin, and THROW_INCONSISTENCY_EXCEPTION.

Here is the call graph for this function:

◆ SoloVisibleChan()

void NoteTrack::SoloVisibleChan ( int  c)
inline

Definition at line 176 of file NoteTrack.h.

176 {
177 auto visibleChannels = 0u;
179 visibleChannels = ALL_CHANNELS;
180 else
181 visibleChannels = CHANNEL_BIT(c);
182 mVisibleChannels.store(visibleChannels, std::memory_order_relaxed);
183 }
#define ALL_CHANNELS
Definition: NoteTrack.h:157

References ALL_CHANNELS, and CHANNEL_BIT.

Referenced by LabelClick().

Here is the caller graph for this function:

◆ StretchRegion()

bool NoteTrack::StretchRegion ( QuantizedTimeAndBeat  t0,
QuantizedTimeAndBeat  t1,
double  newDur 
)

Definition at line 631 of file NoteTrack.cpp.

633{
634 auto &seq = GetSeq();
635 bool result = seq.stretch_region( t0.second, t1.second, newDur );
636 if (result) {
637 const auto oldDur = t1.first - t0.first;
638 AddToDuration( newDur - oldDur );
639 }
640 return result;
641}

References AddToDuration(), and GetSeq().

Referenced by StretchHandle::Stretch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToggleVisibleChan()

void NoteTrack::ToggleVisibleChan ( int  c)
inline

Definition at line 172 of file NoteTrack.h.

172 {
173 mVisibleChannels.fetch_xor(CHANNEL_BIT(c), std::memory_order_relaxed); }

References CHANNEL_BIT.

Referenced by LabelClick().

Here is the caller graph for this function:

◆ Trim()

bool NoteTrack::Trim ( double  t0,
double  t1 
)

Definition at line 381 of file NoteTrack.cpp.

382{
383 if (t1 < t0)
384 return false;
385 auto &seq = GetSeq();
386 //auto delta = -(
387 //( GetEndTime() - std::min( GetEndTime(), t1 ) ) +
388 //( std::max(t0, GetStartTime()) - GetStartTime() )
389 //);
390 seq.convert_to_seconds();
391 // DELETE way beyond duration just in case something is out there:
392 seq.clear(t1 - mOrigin, seq.get_dur() + 10000.0, false);
393 // Now that stuff beyond selection is cleared, clear before selection:
394 seq.clear(0.0, t0 - mOrigin, false);
395 // want starting time to be t0
396 MoveTo(t0);
397
398 // Not needed
399 // Alg_seq::clear seems to handle this
400 //AddToDuration( delta );
401
402 return true;
403}

References GetSeq(), mOrigin, and MoveTo().

Here is the call graph for this function:

◆ WarpAndTransposeNotes()

void NoteTrack::WarpAndTransposeNotes ( double  t0,
double  t1,
const TimeWarper warper,
double  semitones 
)

Definition at line 227 of file NoteTrack.cpp.

230{
231 double offset = this->mOrigin; // track is shifted this amount
232 auto &seq = GetSeq();
233 seq.convert_to_seconds(); // make sure time units are right
234 t1 -= offset; // adjust time range to compensate for track offset
235 t0 -= offset;
236 if (t1 > seq.get_dur()) { // make sure t0, t1 are within sequence
237 t1 = seq.get_dur();
238 if (t0 >= t1) return;
239 }
240 Alg_iterator iter(mSeq.get(), false);
241 iter.begin();
242 Alg_event_ptr event;
243 while (0 != (event = iter.next()) && event->time < t1) {
244 if (event->is_note() && event->time >= t0) {
245 event->set_pitch(event->get_pitch() + semitones);
246 }
247 }
248 iter.end();
249 // now, use warper to warp the tempo map
250 seq.convert_to_beats(); // beats remain the same
251 Alg_time_map_ptr map = seq.get_time_map();
252 map->insert_beat(t0, map->time_to_beat(t0));
253 map->insert_beat(t1, map->time_to_beat(t1));
254 int i, len = map->length();
255 for (i = 0; i < len; i++) {
256 Alg_beat &beat = map->beats[i];
257 beat.time = warper.Warp(beat.time + offset) - offset;
258 }
259 // about to redisplay, so might as well convert back to time now
260 seq.convert_to_seconds();
261}
virtual double Warp(double originalTime) const =0

References GetSeq(), mOrigin, mSeq, and TimeWarper::Warp().

Here is the call graph for this function:

◆ WriteXML()

void NoteTrack::WriteXML ( XMLWriter xmlFile) const
overridevirtual

Implements Track.

Definition at line 867 of file NoteTrack.cpp.

869{
870 assert(IsLeader());
871 std::ostringstream data;
872 Track::Holder holder;
873 const NoteTrack *saveme = this;
874 if (!mSeq) {
875 // replace saveme with an (unserialized) duplicate, which is
876 // destroyed at end of function.
877 holder = (*Clone()->begin())->SharedPointer();
878 saveme = static_cast<NoteTrack*>(holder.get());
879 }
880 saveme->GetSeq().write(data, true);
881 xmlFile.StartTag(wxT("notetrack"));
882 saveme->Track::WriteCommonXMLAttributes( xmlFile );
884 xmlFile.WriteAttr(wxT("offset"), saveme->mOrigin);
885 xmlFile.WriteAttr(wxT("visiblechannels"),
886 static_cast<int>(saveme->GetVisibleChannels()));
887
888#ifdef EXPERIMENTAL_MIDI_OUT
889 xmlFile.WriteAttr(wxT("velocity"),
890 static_cast<double>(saveme->GetVelocity()));
891#endif
892 saveme->Attachments::ForEach([&](auto &attachment){
893 attachment.WriteXML(xmlFile);
894 });
895 xmlFile.WriteAttr(wxT("data"), wxString(data.str().c_str(), wxConvUTF8));
896 xmlFile.EndTag(wxT("notetrack"));
897}
void WriteXMLAttributes(XMLWriter &WXUNUSED(xmlFile)) const
Definition: PlayableTrack.h:29
TrackListHolder Clone() const override
Definition: NoteTrack.cpp:168
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:160
std::shared_ptr< Track > Holder
Definition: Track.h:225
virtual void StartTag(const wxString &name)
Definition: XMLWriter.cpp:79
void WriteAttr(const wxString &name, const Identifier &value)
Definition: XMLWriter.h:36
virtual void EndTag(const wxString &name)
Definition: XMLWriter.cpp:102

References GetSeq(), GetVisibleChannels(), mOrigin, AudioTrack::WriteXMLAttributes(), and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ AllegroStyleSetting

EnumSetting< bool > NoteTrack::AllegroStyleSetting
static
Initial value:
{
wxT("/FileFormats/AllegroStyleChoice"),
{
EnumValueSymbol{ wxT("Seconds"), XXO("&Seconds") },
EnumValueSymbol{ wxT("Beats"), XXO("&Beats") },
},
0,
{
true, false,
},
wxT("/FileFormats/AllegroStyle"),
}
XXO("&Cut/Copy/Paste Toolbar")
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...

Definition at line 89 of file NoteTrack.h.

Referenced by anonymous_namespace{ExportMIDI.cpp}::AddControls(), and ExportAllegro().

◆ mOrigin

double NoteTrack::mOrigin { 0.0 }
private

◆ mSeq

std::unique_ptr<Alg_seq> NoteTrack::mSeq
mutableprivate

◆ mSerializationBuffer

std::unique_ptr<char[]> NoteTrack::mSerializationBuffer
mutableprivate

Definition at line 216 of file NoteTrack.h.

Referenced by Clone(), and GetSeq().

◆ mSerializationLength

long NoteTrack::mSerializationLength
mutableprivate

Definition at line 217 of file NoteTrack.h.

Referenced by Clone(), GetSeq(), and NoteTrack().

◆ mVisibleChannels

std::atomic<unsigned> NoteTrack::mVisibleChannels { ALL_CHANNELS }
private

A bit set; atomic because it may be read by worker threads in playback.

Definition at line 225 of file NoteTrack.h.


The documentation for this class was generated from the following files: