Beatmup
Beatmup::Fragments::Sequence::Pointer Class Reference

Points to a position within a sequence. More...

#include <sequence.h>

Public Member Functions

void moveTo (dtime time)
 Sets pointer to a specific time. More...
 
void step ()
 Moves the pointer forward an arbitrary number of samples. More...
 
void watch ()
 Enables "watching mode", i.e., if the sequence is modified, the pointer will follow the modifications and remain valid. More...
 
void jump (dtime by)
 Moves the pointer by a given number of samples relatively to the current position. More...
 
dtime getTime () const
 
bool hasData () const
 
int samplesAvailable () const
 

Protected Member Functions

 Pointer (Sequence &sequence, dtime time, bool writing)
 
 ~Pointer ()
 

Protected Attributes

Sequencesequence
 
FragmentPtr pointer
 pointed fragment More...
 

Private Attributes

bool writing
 if true, the pointer is used to modify the data More...
 
bool watching
 if true, the pointer will remain valid even if the sequence is being modified More...
 
dtime currentTime
 
int fragmentIdx
 

Detailed Description

Points to a position within a sequence.

Definition at line 38 of file sequence.h.

Constructor & Destructor Documentation

◆ Pointer()

Sequence::Pointer::Pointer ( Sequence sequence,
dtime  time,
bool  writing 
)
protected

Definition at line 339 of file sequence.cpp.

339  : writing(writing), watching(false), sequence(sequence) {
340  if (0 <= time && time < sequence.cumTimes[1]) {
341  // an heuristic to start quickly
342  if (writing)
343  sequence.fragments[0].editData();
344  currentTime = time;
346  pointer.offset += time;
347  pointer.length -= time;
348  fragmentIdx = 0;
349  }
350  else
351  moveTo(time);
352 }
void moveTo(dtime time)
Sets pointer to a specific time.
Definition: sequence.cpp:361
FragmentPtr pointer
pointed fragment
Definition: sequence.h:47
bool writing
if true, the pointer is used to modify the data
Definition: sequence.h:40
bool watching
if true, the pointer will remain valid even if the sequence is being modified
Definition: sequence.h:41
std::vector< dtime > cumTimes
cumulative sum of fragment lengths, starts from 0, of N+1 entries (N = num. of fragments)
Definition: sequence.h:80
std::vector< FragmentPtr > fragments
the content
Definition: sequence.h:79
int offset
offset in samples inside the fragment since its beginning
Definition: fragment.h:70
int length
number of samples to use from the fragment
Definition: fragment.h:71
jlong jlong jint time

◆ ~Pointer()

Sequence::Pointer::~Pointer ( )
protected

Definition at line 355 of file sequence.cpp.

355  {
356  if (watching)
357  sequence.pointers.erase(std::find(sequence.pointers.begin(), sequence.pointers.end(), this));
358 }
std::vector< Pointer * > pointers
pointers currently accessing the sequence
Definition: sequence.h:81

Member Function Documentation

◆ moveTo()

void Sequence::Pointer::moveTo ( dtime  time)

Sets pointer to a specific time.

Parameters
timeThe time (in samples) to set the pointer to

Definition at line 361 of file sequence.cpp.

361  {
362  currentTime = time;
365  if (writing)
366  sequence.fragments[fragmentIdx].editData();
369  pointer.offset += dt;
370  pointer.length -= dt;
371  }
372  else
373  pointer.nullify();
374 }
int findFragment(dtime time) const
Log search for a fragment containing given time moment.
static const int VOID_RIGHT
returned by getFragment() when the entire sequence is on the left of the given time moment
Definition: sequence.h:98
static const int VOID_LEFT
returned by getFragment() when the entire sequence is on the right of the given time moment
Definition: sequence.h:97
int dtime
discrete time
Definition: basic_types.h:37

◆ step()

void Sequence::Pointer::step ( )

Moves the pointer forward an arbitrary number of samples.

Definition at line 377 of file sequence.cpp.

377  {
378  if (0 <= fragmentIdx && fragmentIdx < sequence.fragments.size()-1) {
379  fragmentIdx++;
382  }
383  else {
385  pointer.nullify();
387  }
388 }
const dtime getDuration() const
Returns sequence duration in number of samples.
Definition: sequence.h:123

◆ watch()

void Sequence::Pointer::watch ( )

Enables "watching mode", i.e., if the sequence is modified, the pointer will follow the modifications and remain valid.

Definition at line 391 of file sequence.cpp.

391  {
392  if (!watching) {
393  watching = true;
394  sequence.pointers.push_back(this);
395  }
396 }

◆ jump()

void Beatmup::Fragments::Sequence::Pointer::jump ( dtime  by)
inline

Moves the pointer by a given number of samples relatively to the current position.

Definition at line 71 of file sequence.h.

71 { moveTo(currentTime + by); }

◆ getTime()

dtime Beatmup::Fragments::Sequence::Pointer::getTime ( ) const
inline

Definition at line 73 of file sequence.h.

73 { return currentTime; }

◆ hasData()

bool Beatmup::Fragments::Sequence::Pointer::hasData ( ) const
inline

Definition at line 74 of file sequence.h.

74 { return !pointer.isNull(); }

◆ samplesAvailable()

int Beatmup::Fragments::Sequence::Pointer::samplesAvailable ( ) const
inline

Definition at line 75 of file sequence.h.

75 { return pointer.length; }

Member Data Documentation

◆ writing

bool Beatmup::Fragments::Sequence::Pointer::writing
private

if true, the pointer is used to modify the data

Definition at line 40 of file sequence.h.

◆ watching

bool Beatmup::Fragments::Sequence::Pointer::watching
private

if true, the pointer will remain valid even if the sequence is being modified

Definition at line 41 of file sequence.h.

◆ currentTime

dtime Beatmup::Fragments::Sequence::Pointer::currentTime
private

Definition at line 42 of file sequence.h.

◆ fragmentIdx

int Beatmup::Fragments::Sequence::Pointer::fragmentIdx
private

Definition at line 43 of file sequence.h.

◆ sequence

Sequence& Beatmup::Fragments::Sequence::Pointer::sequence
protected

Definition at line 46 of file sequence.h.

◆ pointer

FragmentPtr Beatmup::Fragments::Sequence::Pointer::pointer
protected

pointed fragment

Definition at line 47 of file sequence.h.


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