12#ifndef __AUDIO_POSITION_H__
13#define __AUDIO_POSITION_H__
24#define TICKS_PER_QUARTER_NOTE 960
25#define TICKS_PER_SIXTEENTH_NOTE 240
26#define TICKS_PER_QUARTER_NOTE_DBL 960.0
27#define TICKS_PER_SIXTEENTH_NOTE_DBL 240.0
28#define TICKS_PER_NINETYSIXTH_NOTE_DBL 40.0
29#define position_add_sixteenths(_pos, _s) \
30 position_add_ticks ((_pos), (_s) * TICKS_PER_SIXTEENTH_NOTE)
31#define position_add_beats(_pos, _b) \
32 g_warn_if_fail (TRANSPORT->ticks_per_beat > 0); \
33 position_add_ticks ((_pos), (_b) * TRANSPORT->ticks_per_beat)
34#define position_add_bars(_pos, _b) \
35 g_warn_if_fail (TRANSPORT->ticks_per_bar > 0); \
36 position_add_ticks ((_pos), (_b) * TRANSPORT->ticks_per_bar)
37#define position_snap_simple(pos, sg) position_snap (NULL, pos, NULL, NULL, sg)
39#define POSITION_MAX_BAR 160000
45#define position_between_frames_excl2(pos, f1, f2) \
46 ((pos)->frames >= f1 && (pos)->frames < f2)
55#define position_compare_frames(p1, p2) ((p1)->frames - (p2)->frames)
58#define position_is_before(_pos, _cmp) \
59 (position_compare_frames (_pos, _cmp) < 0)
62#define position_is_before_or_equal(_pos, _cmp) \
63 (position_compare_frames (_pos, _cmp) <= 0)
66#define position_is_equal(_pos, _cmp) \
67 (position_compare_frames (_pos, _cmp) == 0)
70#define position_is_after(_pos, _cmp) (position_compare_frames (_pos, _cmp) > 0)
73#define position_is_after_or_equal(_pos, _cmp) \
74 (position_compare_frames (_pos, _cmp) >= 0)
76#define position_is_positive(pos) ((pos)->frames >= 0 && (pos)->ticks >= 0)
85#define position_compare_ticks(p1, p2) ((p1)->ticks - (p2)->ticks)
87#define position_is_equal_ticks(p1, p2) \
88 (fabs (position_compare_ticks (p1, p2)) <= DBL_EPSILON)
92#define position_is_between(_pos, _start, _end) \
93 (position_is_after_or_equal (_pos, _start) && position_is_before (_pos, _end))
97#define position_is_between_excl_start(_pos, _start, _end) \
98 (position_is_after (_pos, _start) && position_is_before (_pos, _end))
101#define position_min(p1, p2) (position_compare_frames (p1, p2) < 0 ? p1 : p2)
104#define position_max(p1, p2) (position_compare_frames (p1, p2) > 0 ? p1 : p2)
107#define POSITION_INIT_ON_STACK(name) Position name = POSITION_START;
114#define position_init(__pos) *(__pos) = POSITION_START
148static const Position POSITION_START = { .
ticks = 0.0, .frames = 0 };
151position_cmp_func (
const void * _a,
const void * _b)
183#define position_set_to_pos(_pos, _target) *(_pos) = *(_target)
194#define position_to_frames(x) ((x)->frames)
195#define position_to_ticks(x) ((x)->ticks)
217position_from_bars (
Position * pos,
int bars);
220position_add_ticks (
Position * self,
double ticks);
229position_ms_to_frames (
const double ms);
232position_ms_to_ticks (
const double ms);
235position_add_ms (
Position * pos,
const double ms);
238position_add_minutes (
Position * pos,
int mins);
322position_update (
Position * self,
bool from_ticks,
double ratio)
365position_to_string_full (
const Position * pos,
char * buf,
int decimal_places);
379NONNULL WARN_UNUSED_RESULT
bool
470position_validate (
const Position * pos);
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.
NONNULL int position_get_beats(const Position *pos, bool start_at_one)
Gets the beats of the position.
NONNULL int position_get_total_sixteenths(const Position *pos, bool include_current)
Returns the total number of sixteenths not including the current one.
NONNULL void position_print(const Position *pos)
Prints the Position in the "0.0.0.0" form.
HOT NONNULL void position_from_ticks(Position *pos, double ticks)
Sets position to the given total tick count.
HOT NONNULL void position_update_frames_from_ticks(Position *self, double frames_per_tick)
Updates frames.
signed_ms_t position_to_ms(const Position *pos)
Returns the Position in milliseconds.
NONNULL int position_get_sixteenths(const Position *pos, bool start_at_one)
Gets the sixteenths of the position.
signed_frame_t position_get_frames_from_ticks(double ticks, double frames_per_tick)
Converts ticks to frames.
NONNULL int position_get_bars(const Position *pos, bool start_at_one)
Gets the bars of the position.
void position_sort_array(Position *array, const size_t size)
Sorts an array of Position's.
void position_snap(const Position *start_pos, Position *pos, Track *track, Region *region, const SnapGrid *sg)
Snaps position using given options.
HOT void position_add_frames(Position *pos, const signed_frame_t frames)
Adds the frames to the position and updates the rest of the fields, and makes sure the frames are sti...
void position_set_min_size(const Position *start_pos, Position *end_pos, SnapGrid *snap)
Sets the end position to be 1 snap point away from the start pos.
void position_get_midway_pos(Position *start_pos, Position *end_pos, Position *pos)
Calculates the midway point between the two Positions and sets it on pos.
NONNULL void position_change_sign(Position *pos)
Changes the sign of the position.
NONNULL char * position_to_string_alloc(const Position *pos)
Creates a string in the form of "0.0.0.0" from the given position.
NONNULL double position_get_ticks(const Position *pos)
Gets the ticks of the position.
NONNULL WARN_UNUSED_RESULT bool position_parse(Position *pos, const char *str)
Parses a position from the given string.
void position_set_to_bar(Position *self, int bar)
Sets position to given bar.
#define position_compare_frames(p1, p2)
Compares 2 positions based on their frames.
double position_get_ticks_diff(const Position *end_pos, const Position *start_pos, const SnapGrid *sg)
Returns the difference in ticks between the two Position's, snapped based on the given SnapGrid (if a...
NONNULL int position_get_total_beats(const Position *pos, bool include_current)
Returns the total number of beats.
NONNULL int position_get_total_bars(const Position *pos, bool include_current)
Returns the total number of beats.
HOT NONNULL void position_update_ticks_from_frames(Position *position, double ticks_per_frame)
Updates ticks.
NONNULL void position_to_string(const Position *pos, char *buf)
Creates a string in the form of "0.0.0.0" from the given position.
void position_from_seconds(Position *position, double secs)
Converts seconds to position and puts the result in the given Position.
signed_frame_t signed_sec_t
Signed second index.
int_fast64_t signed_frame_t
Signed type for frame index.
signed_frame_t signed_ms_t
Signed millisecond index.
A Position is made up of bars.beats.sixteenths.ticks.
double ticks
Precise total number of ticks.
signed_frame_t frames
Position in frames (samples).
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.
Track to be inserted into the Project's Tracklist.