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 = ChannelGroupAttachments
 
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...
 
void ShiftBy (double t0, double delta) override
 Shift all intervals that starts after t0 by delta seconds. 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
 
Track::Holder Cut (double t0, double t1) override
 Create tracks and modify this track. More...
 
Track::Holder 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)
 
float GetVelocity () const
 
void SetVelocity (float velocity)
 
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< PlayableTrack >
size_t NChannels () const override
 Report the number of channels. More...
 
std::shared_ptr< ChannelDoGetChannel (size_t iChannel) override
 
- Public Member Functions inherited from PlayableTrack
 PlayableTrack ()
 
 PlayableTrack (const PlayableTrack &orig, ProtectedCreationArg &&)
 
bool GetMute () const
 
bool GetSolo () const
 
bool GetNotMute () const
 
bool GetNotSolo () const
 
void SetMute (bool m)
 
void SetSolo (bool s)
 
void WriteXMLAttributes (XMLWriter &xmlFile) const
 
bool HandleXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &value)
 
- 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 > >
 
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
 
LinkType GetLinkType () const noexcept
 
 Track ()
 
 Track (const Track &orig, ProtectedCreationArg &&)
 
Trackoperator= (const Track &orig)=delete
 
virtual ~Track ()
 
void Init (const Track &orig)
 
virtual Holder Duplicate (DuplicateOptions={}) const
 public nonvirtual duplication function that invokes Clone() More...
 
void ReparentAllAttachments ()
 
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)
 
virtual Holder Cut (double t0, double t1)=0
 Create tracks and modify this track. More...
 
virtual Holder 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...
 
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
 
void AdjustPositions ()
 
void WriteCommonXMLAttributes (XMLWriter &xmlFile, bool includeNameAndSelected=true) const
 
bool HandleCommonXMLAttribute (const std::string_view &attr, const XMLAttributeValueView &valueView)
 
- 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 ShiftBy (double t0, double delta)=0
 Shift all intervals that starts after t0 by delta seconds. More...
 
virtual void MoveTo (double o)=0
 Change start time to given time point. 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...
 
std::shared_ptr< ChannelNthChannel (size_t nChannel)
 
std::shared_ptr< const ChannelNthChannel (size_t nChannel) const
 
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 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 PlayableTrack
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 void CopyAttachments (Track &dst, const Track &src, bool deep)
 Copy (deep) or just share (!deep) AttachedTrackObjects. More...
 
- 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

Track::Holder Clone (bool backup) const override
 
std::shared_ptr< WideChannelGroupIntervalDoGetInterval (size_t iInterval) override
 Retrieve an interval. More...
 
void DoSetVelocity (float velocity)
 
void AddToDuration (double delta)
 

Private Attributes

std::unique_ptr< Alg_seq > mSeq
 
std::unique_ptr< char[]> mSerializationBuffer
 
long mSerializationLength
 
std::atomic< float > mVelocity { 0.0f }
 Atomic because it may be read by worker threads in playback. More...
 
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< PlayableTrack >
ChannelGroupDoGetChannelGroup () const override
 Subclass must override. More...
 
- Protected Member Functions inherited from PlayableTrack
bool DoGetMute () const
 
void DoSetMute (bool value)
 
bool DoGetSolo () const
 
void DoSetSolo (bool value)
 
- Protected Member Functions inherited from Track
void SetLinkType (LinkType linkType, bool completeList=true)
 
- 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 >
void ForCorresponding (Site &other, const Function &function, bool create=true)
 
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...
 
template<typename Function >
void EraseIf (const Function &function)
 Erase attached objects satisfying a predicate. 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
 
virtual std::shared_ptr< IntervalDoGetInterval (size_t iInterval)=0
 Retrieve an interval. More...
 
virtual ChannelGroupDoGetChannelGroup () const =0
 Subclass must override. 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...
 

Detailed Description

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

Definition at line 74 of file NoteTrack.h.

Member Typedef Documentation

◆ Attachments

Definition at line 80 of file NoteTrack.h.

◆ Holder

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

Definition at line 92 of file NoteTrack.h.

Constructor & Destructor Documentation

◆ NoteTrack() [1/3]

NoteTrack::NoteTrack ( )

Definition at line 145 of file NoteTrack.cpp.

147{
148 SetName(_("Note Track"));
149
150 mSeq = NULL;
152}
#define _(s)
Definition: Internat.h:73
std::unique_ptr< Alg_seq > mSeq
Definition: NoteTrack.h:208
long mSerializationLength
Definition: NoteTrack.h:210
void SetName(const wxString &n)
Definition: Track.cpp:69
Generates overrides of channel-related functions.
Definition: Track.h:450

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 154 of file NoteTrack.cpp.

155{
156}

Member Function Documentation

◆ AddToDuration()

void NoteTrack::AddToDuration ( double  delta)
private

Definition at line 608 of file NoteTrack.cpp.

609{
610 auto &seq = GetSeq();
611#if 0
612 // PRL: Would this be better ?
613 seq.set_real_dur( seq.get_real_dur() + delta );
614#else
615 seq.convert_to_seconds();
616 seq.set_dur( seq.get_dur() + delta );
617#endif
618}
Alg_seq & GetSeq() const
Definition: NoteTrack.cpp:158

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 580 of file NoteTrack.cpp.

581{
582 return typeInfo();
583}
static const Track::TypeInfo & typeInfo()
Definition: NoteTrack.cpp:567

References typeInfo().

Here is the call graph for this function:

◆ Clear()

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

May assume precondition: t0 <= t1

Implements Track.

Definition at line 403 of file NoteTrack.cpp.

404{
405 if (t1 < t0)
407
408 double len = t1-t0;
409
410 auto &seq = GetSeq();
411
412 auto offset = mOrigin;
413 auto start = t0 - offset;
414 if (start < 0.0) {
415 // AlgSeq::clear will shift the cleared interval, not changing len, if
416 // start is negative. That's not what we want to happen.
417 if (len > -start) {
418 seq.clear(0, len + start, false);
419 MoveTo(t0);
420 }
421 else
422 MoveTo(offset - len);
423 }
424 else {
425 //auto delta = -(
426 //( std::min( t1, GetEndTime() ) ) - ( std::max( t0, GetStartTime() ) )
427 //);
428 seq.clear(start, len, false);
429
430 // Not needed
431 // Alg_seq::clear seems to handle this
432 // AddToDuration( delta );
433 }
434}
#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:98
double mOrigin
Definition: NoteTrack.h:217

References GetSeq(), 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 161 of file NoteTrack.h.

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

References CHANNEL_BIT.

◆ Clone()

Track::Holder NoteTrack::Clone ( bool  backup) const
overrideprivatevirtual

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

Parameters
backupwhether the duplication is for backup purposes while opening a project, instead of other editing operations
Postcondition
result tracks have same TrackIds as the channels of this

Implements Track.

Definition at line 180 of file NoteTrack.cpp.

181{
182 auto duplicate = std::make_shared<NoteTrack>();
183 duplicate->Init(*this);
184 // The duplicate begins life in serialized state. Often the duplicate is
185 // pushed on the Undo stack. Then we want to un-serialize it (or a further
186 // copy) only on demand after an Undo.
187 if (mSeq) {
189 wxASSERT(!mSerializationBuffer);
190 // serialize from this to duplicate's mSerializationBuffer
191 void *buffer;
192 mSeq->serialize(&buffer,
193 &duplicate->mSerializationLength);
194 duplicate->mSerializationBuffer.reset( (char*)buffer );
196 }
197 else if (mSerializationBuffer) {
198 // Copy already serialized data.
199 wxASSERT(!mSeq);
200 duplicate->mSerializationLength = this->mSerializationLength;
201 duplicate->mSerializationBuffer.reset
202 ( safenew char[ this->mSerializationLength ] );
203 memcpy( duplicate->mSerializationBuffer.get(),
204 this->mSerializationBuffer.get(), this->mSerializationLength );
205 }
206 else {
207 // We are duplicating a default-constructed NoteTrack, and that's okay
208 }
209
210 // copy some other fields here
211 Attachments &attachments = *duplicate;
212 attachments = *this;
213
214 duplicate->SetVisibleChannels(GetVisibleChannels());
215 duplicate->MoveTo(mOrigin);
216 duplicate->SetVelocity(GetVelocity());
217 return duplicate;
218}
#define safenew
Definition: MemoryX.h:10
#define SonifyEndSerialize()
Definition: NoteTrack.h:239
#define SonifyBeginSerialize()
Definition: NoteTrack.h:238
NoteTrackAttachments Attachments
Definition: NoteTrack.h:80
std::unique_ptr< char[]> mSerializationBuffer
Definition: NoteTrack.h:209
float GetVelocity() const
Definition: NoteTrack.h:125
unsigned GetVisibleChannels() const
Definition: NoteTrack.h:150

References GetVelocity(), GetVisibleChannels(), mOrigin, mSeq, mSerializationBuffer, mSerializationLength, safenew, SonifyBeginSerialize, and SonifyEndSerialize.

Here is the call graph for this function:

◆ Copy()

Track::Holder 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

Implements Track.

Definition at line 356 of file NoteTrack.cpp.

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

References GetSeq(), mOrigin, 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()

Track::Holder NoteTrack::Cut ( double  t0,
double  t1 
)
overridevirtual

Create tracks and modify this track.

Returns
non-NULL or else throw May assume precondition: t0 <= t1

Implements Track.

Definition at line 326 of file NoteTrack.cpp.

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

References GetSeq(), mOrigin, 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 600 of file NoteTrack.cpp.

601{
602 if (iInterval == 0)
603 // Just one, and no extra info in it!
604 return std::make_shared<Interval>(*this);
605 return {};
606}

◆ DoSetVelocity()

void NoteTrack::DoSetVelocity ( float  velocity)
private

Definition at line 522 of file NoteTrack.cpp.

523{
524 mVelocity.store(velocity, std::memory_order_relaxed);
525}
std::atomic< float > mVelocity
Atomic because it may be read by worker threads in playback.
Definition: NoteTrack.h:213

References mVelocity.

Referenced by HandleXMLTag(), and SetVelocity().

Here is the caller graph for this function:

◆ ExportAllegro()

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

Definition at line 789 of file NoteTrack.cpp.

790{
791 double offset = mOrigin;
792 auto in_seconds = AllegroStyleSetting.ReadEnum();
793 auto &seq = GetSeq();
794 if (in_seconds) {
795 seq.convert_to_seconds();
796 } else {
797 seq.convert_to_beats();
798 }
799 return seq.write(f.mb_str(), offset);
800}
Enum ReadEnum() const
Definition: Prefs.h:534
static EnumSetting< bool > AllegroStyleSetting
Definition: NoteTrack.h:81

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 765 of file NoteTrack.cpp.

766{
767 std::unique_ptr<Alg_seq> cleanup;
768 auto seq = MakeExportableSeq(cleanup);
769 bool rslt = seq->smf_write(f.mb_str());
770 return rslt;
771}
Alg_seq * MakeExportableSeq(std::unique_ptr< Alg_seq > &cleanup) const
Definition: NoteTrack.cpp:642

References MakeExportableSeq().

Here is the call graph for this function:

◆ GetSeq()

Alg_seq & NoteTrack::GetSeq ( ) const

Definition at line 158 of file NoteTrack.cpp.

159{
160 if (!mSeq) {
162 mSeq = std::make_unique<Alg_seq>();
163 else {
164 std::unique_ptr<Alg_track> alg_track
165 { Alg_seq::unserialize
167 wxASSERT(alg_track->get_type() == 's');
168 mSeq.reset( static_cast<Alg_seq*>(alg_track.release()) );
169
170 // Preserve the invariant that at most one of the representations is
171 // valid
172 mSerializationBuffer.reset();
174 }
175 }
176 wxASSERT(mSeq);
177 return *mSeq;
178}

References mSeq, mSerializationBuffer, and mSerializationLength.

Referenced by AddToDuration(), Clear(), Copy(), Cut(), DEFINE_ATTACHED_VIRTUAL_OVERRIDE(), 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 575 of file NoteTrack.cpp.

576{
577 return typeInfo();
578}

References typeInfo().

Here is the call graph for this function:

◆ GetVelocity()

float NoteTrack::GetVelocity ( ) const
inline

Definition at line 125 of file NoteTrack.h.

125 {
126 return mVelocity.load(std::memory_order_relaxed); }

Referenced by Clone(), anonymous_namespace{MIDIPlay.h}::Iterator::OutputEvent(), SetVelocity(), NoteTrackControls::VelocitySlider(), and WriteXML().

Here is the caller graph for this function:

◆ GetVisibleChannels()

unsigned NoteTrack::GetVisibleChannels ( ) const
inline

Definition at line 150 of file NoteTrack.h.

150 {
151 return mVisibleChannels.load(std::memory_order_relaxed);
152 }

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 849 of file NoteTrack.cpp.

850{
851 return NULL;
852}

◆ HandleXMLTag()

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

Implements XMLTagHandler.

Definition at line 810 of file NoteTrack.cpp.

811{
812 if (tag == "notetrack") {
813 for (auto pair : attrs)
814 {
815 auto attr = pair.first;
816 auto value = pair.second;
817
818 long nValue;
819 double dblValue;
820 if (this->Track::HandleCommonXMLAttribute(attr, value))
821 ;
822 else if (this->Attachments::FindIf([&](auto &attachment){
823 return attachment.HandleAttribute(pair);
824 }))
825 ;
826 else if (this->PlayableTrack::HandleXMLAttribute(attr, value))
827 {}
828 else if (attr == "offset" && value.TryGet(dblValue))
829 MoveTo(dblValue);
830 else if (attr == "visiblechannels") {
831 if (!value.TryGet(nValue) ||
832 !IsValidVisibleChannels(nValue))
833 return false;
834 SetVisibleChannels(nValue);
835 }
836 else if (attr == "velocity" && value.TryGet(dblValue))
837 DoSetVelocity(static_cast<float>(dblValue));
838 else if (attr == "data") {
839 std::string s(value.ToWString());
840 std::istringstream data(s);
841 mSeq = std::make_unique<Alg_seq>(data, false);
842 }
843 } // while
844 return true;
845 }
846 return false;
847}
ClientData * FindIf(const Function &function)
Return pointer to first attachment in this that is not null and satisfies a predicate,...
Definition: ClientData.h:497
void SetVisibleChannels(unsigned value)
Definition: NoteTrack.h:153
void DoSetVelocity(float velocity)
Definition: NoteTrack.cpp:522
bool HandleXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &value)
bool HandleCommonXMLAttribute(const std::string_view &attr, const XMLAttributeValueView &valueView)
Definition: Track.cpp:819
bool IsValidVisibleChannels(const int nValue)
Definition: NoteTrack.cpp:804

References DoSetVelocity(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::FindIf(), Track::HandleCommonXMLAttribute(), PlayableTrack::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

Implements Track.

Definition at line 501 of file NoteTrack.cpp.

502{
503 if (len < 0)
505
506 auto &seq = GetSeq();
507 seq.convert_to_seconds();
508 seq.insert_silence(t - mOrigin, len);
509
510 // is this needed?
511 // AddToDuration( len );
512}

References GetSeq(), 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 156 of file NoteTrack.h.

156 {
157 return (GetVisibleChannels() & CHANNEL_BIT(c)) != 0;
158 }

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 642 of file NoteTrack.cpp.

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

98{ 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 556 of file NoteTrack.cpp.

557{
558 // Alg_seq knows nothing about offset, so remove offset time
559 double seq_time = time - mOrigin;
560 double beat;
561 auto &seq = GetSeq();
562 seq_time = seq.nearest_beat_time(seq_time, &beat);
563 // add the offset back in to get "actual" audacity track time
564 return { seq_time + mOrigin, beat };
565}

References GetSeq(), and mOrigin.

Here is the call graph for this function:

◆ New()

NoteTrack * NoteTrack::New ( AudacityProject project)
static

Definition at line 137 of file NoteTrack.cpp.

138{
139 auto &tracks = TrackList::Get( project );
140 auto result = tracks.Add( std::make_shared<NoteTrack>());
141 result->AttachedTrackObjects::BuildAll();
142 return result;
143}
const auto tracks
const auto project
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314

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 594 of file NoteTrack.cpp.

595{
596 return 1;
597}

◆ Paste()

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

Weak precondition allows overrides to replicate one channel into many.

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

Implements Track.

Definition at line 436 of file NoteTrack.cpp.

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

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

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 track

Implements Track.

Definition at line 585 of file NoteTrack.cpp.

586{
587 auto pNewTrack = std::make_shared<NoteTrack>();
588 pNewTrack->Init(*this);
589 pNewTrack->Paste(0.0, *this);
590 list.Add(pNewTrack);
591 return pNewTrack;
592}
TrackKind * Add(const std::shared_ptr< TrackKind > &t, bool assignIds=true)
Definition: Track.h:1048

References TrackList::Add().

Here is the call graph for this function:

◆ PrintSequence()

void NoteTrack::PrintSequence ( )

Definition at line 267 of file NoteTrack.cpp.

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

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

References mSeq.

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

Here is the caller graph for this function:

◆ SetVelocity()

void NoteTrack::SetVelocity ( float  velocity)

Definition at line 514 of file NoteTrack.cpp.

515{
516 if (GetVelocity() != velocity) {
517 DoSetVelocity(velocity);
518 Notify(false);
519 }
520}
void Notify(bool allChannels, int code=-1)
Definition: Track.cpp:234

References DoSetVelocity(), GetVelocity(), and Track::Notify().

Referenced by MixerTrackCluster::HandleSliderVelocity().

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

◆ SetVisibleChan()

void NoteTrack::SetVisibleChan ( int  c)
inline

Definition at line 159 of file NoteTrack.h.

159 {
160 mVisibleChannels.fetch_or(CHANNEL_BIT(c), std::memory_order_relaxed); }

References CHANNEL_BIT.

◆ SetVisibleChannels()

void NoteTrack::SetVisibleChannels ( unsigned  value)
inline

Definition at line 153 of file NoteTrack.h.

153 {
154 mVisibleChannels.store(value, std::memory_order_relaxed);
155 }

Referenced by HandleXMLTag().

Here is the caller graph for this function:

◆ Shift()

bool NoteTrack::Shift ( double  t)

Definition at line 529 of file NoteTrack.cpp.

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

References GetSeq(), and ROUND.

Referenced by MakeExportableSeq().

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

◆ ShiftBy()

void NoteTrack::ShiftBy ( double  t0,
double  delta 
)
overridevirtual

Shift all intervals that starts after t0 by delta seconds.

Implements ChannelGroup.

Definition at line 220 of file NoteTrack.cpp.

221{
222 if(t0 <= mOrigin)
223 mOrigin += delta;
224}

References mOrigin.

◆ Silence()

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

Implements Track.

Definition at line 486 of file NoteTrack.cpp.

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

References GetSeq(), mOrigin, and THROW_INCONSISTENCY_EXCEPTION.

Here is the call graph for this function:

◆ SoloVisibleChan()

void NoteTrack::SoloVisibleChan ( int  c)
inline

Definition at line 167 of file NoteTrack.h.

167 {
168 auto visibleChannels = 0u;
170 visibleChannels = ALL_CHANNELS;
171 else
172 visibleChannels = CHANNEL_BIT(c);
173 mVisibleChannels.store(visibleChannels, std::memory_order_relaxed);
174 }
#define ALL_CHANNELS
Definition: NoteTrack.h:148

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 620 of file NoteTrack.cpp.

622{
623 auto &seq = GetSeq();
624 bool result = seq.stretch_region( t0.second, t1.second, newDur );
625 if (result) {
626 const auto oldDur = t1.first - t0.first;
627 AddToDuration( newDur - oldDur );
628 }
629 return result;
630}

References AddToDuration(), and GetSeq().

Here is the call graph for this function:

◆ ToggleVisibleChan()

void NoteTrack::ToggleVisibleChan ( int  c)
inline

Definition at line 163 of file NoteTrack.h.

163 {
164 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 379 of file NoteTrack.cpp.

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

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 226 of file NoteTrack.cpp.

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

856{
857 std::ostringstream data;
858 Track::Holder holder;
859 const NoteTrack *saveme = this;
860 if (!mSeq) {
861 // replace saveme with an (unserialized) duplicate, which is
862 // destroyed at end of function.
863 holder = Clone(false);
864 saveme = static_cast<NoteTrack*>(holder.get());
865 }
866 saveme->GetSeq().write(data, true);
867 xmlFile.StartTag(wxT("notetrack"));
868 saveme->Track::WriteCommonXMLAttributes( xmlFile );
870 xmlFile.WriteAttr(wxT("offset"), saveme->mOrigin);
871 xmlFile.WriteAttr(wxT("visiblechannels"),
872 static_cast<int>(saveme->GetVisibleChannels()));
873
874 xmlFile.WriteAttr(wxT("velocity"),
875 static_cast<double>(saveme->GetVelocity()));
876 saveme->Attachments::ForEach([&](auto &attachment){
877 attachment.WriteXML(xmlFile);
878 });
879 xmlFile.WriteAttr(wxT("data"), wxString(data.str().c_str(), wxConvUTF8));
880 xmlFile.EndTag(wxT("notetrack"));
881}
Track::Holder Clone(bool backup) const override
Definition: NoteTrack.cpp:180
void WriteXMLAttributes(XMLWriter &xmlFile) const
std::shared_ptr< Track > Holder
Definition: Track.h:202
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(), GetVelocity(), GetVisibleChannels(), mOrigin, PlayableTrack::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 81 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 209 of file NoteTrack.h.

Referenced by Clone(), and GetSeq().

◆ mSerializationLength

long NoteTrack::mSerializationLength
mutableprivate

Definition at line 210 of file NoteTrack.h.

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

◆ mVelocity

std::atomic<float> NoteTrack::mVelocity { 0.0f }
private

Atomic because it may be read by worker threads in playback.

Definition at line 213 of file NoteTrack.h.

Referenced by DoSetVelocity().

◆ 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 216 of file NoteTrack.h.


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