12#ifndef __AUDIO_POSITION_H__
13#define __AUDIO_POSITION_H__
26#define POSITION_SCHEMA_VERSION 1
28#define TICKS_PER_QUARTER_NOTE 960
29#define TICKS_PER_SIXTEENTH_NOTE 240
30#define TICKS_PER_QUARTER_NOTE_DBL 960.0
31#define TICKS_PER_SIXTEENTH_NOTE_DBL 240.0
32#define TICKS_PER_NINETYSIXTH_NOTE_DBL 40.0
33#define position_add_sixteenths(_pos, _s) \
34 position_add_ticks ((_pos), (_s) * TICKS_PER_SIXTEENTH_NOTE)
35#define position_add_beats(_pos, _b) \
36 g_warn_if_fail (TRANSPORT->ticks_per_beat > 0); \
37 position_add_ticks ((_pos), (_b) * TRANSPORT->ticks_per_beat)
38#define position_add_bars(_pos, _b) \
39 g_warn_if_fail (TRANSPORT->ticks_per_bar > 0); \
40 position_add_ticks ((_pos), (_b) * TRANSPORT->ticks_per_bar)
41#define position_snap_simple(pos, sg) position_snap (NULL, pos, NULL, NULL, sg)
43#define POSITION_MAX_BAR 160000
49#define position_between_frames_excl2(pos, f1, f2) \
50 ((pos)->frames >= f1 && (pos)->frames < f2)
59#define position_compare_frames(p1, p2) ((p1)->frames - (p2)->frames)
62#define position_is_before(_pos, _cmp) \
63 (position_compare_frames (_pos, _cmp) < 0)
66#define position_is_before_or_equal(_pos, _cmp) \
67 (position_compare_frames (_pos, _cmp) <= 0)
70#define position_is_equal(_pos, _cmp) \
71 (position_compare_frames (_pos, _cmp) == 0)
74#define position_is_after(_pos, _cmp) (position_compare_frames (_pos, _cmp) > 0)
77#define position_is_after_or_equal(_pos, _cmp) \
78 (position_compare_frames (_pos, _cmp) >= 0)
80#define position_is_positive(pos) ((pos)->frames >= 0 && (pos)->ticks >= 0)
89#define position_compare_ticks(p1, p2) ((p1)->ticks - (p2)->ticks)
91#define position_is_equal_ticks(p1, p2) \
92 (fabs (position_compare_ticks (p1, p2)) <= DBL_EPSILON)
96#define position_is_between(_pos, _start, _end) \
97 (position_is_after_or_equal (_pos, _start) && position_is_before (_pos, _end))
101#define position_is_between_excl_start(_pos, _start, _end) \
102 (position_is_after (_pos, _start) && position_is_before (_pos, _end))
105#define position_min(p1, p2) (position_compare_frames (p1, p2) < 0 ? p1 : p2)
108#define position_max(p1, p2) (position_compare_frames (p1, p2) > 0 ? p1 : p2)
111#define POSITION_INIT_ON_STACK(name) Position name = POSITION_START;
118#define position_init(__pos) *(__pos) = POSITION_START
154static const cyaml_schema_field_t position_fields_schema[] = {
155 YAML_FIELD_INT (
Position, schema_version), YAML_FIELD_FLOAT (
Position, ticks),
161static const cyaml_schema_value_t position_schema = {
166static const Position POSITION_START = {
167 .schema_version = POSITION_SCHEMA_VERSION,
173position_cmp_func (
const void * _a,
const void * _b)
205#define position_set_to_pos(_pos, _target) *(_pos) = *(_target)
216#define position_to_frames(x) ((x)->frames)
217#define position_to_ticks(x) ((x)->ticks)
239position_from_bars (
Position * pos,
int bars);
242position_add_ticks (
Position * self,
double ticks);
251position_ms_to_frames (
const double ms);
254position_ms_to_ticks (
const double ms);
257position_add_ms (
Position * pos,
const double ms);
260position_add_minutes (
Position * pos,
int mins);
344position_update (
Position * self,
bool from_ticks,
double ratio)
387position_to_string_full (
const Position * pos,
char * buf,
int decimal_places);
401NONNULL WARN_UNUSED_RESULT
bool
492position_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.
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.
void position_snap(const Position *start_pos, Position *pos, Track *track, ZRegion *region, const SnapGrid *sg)
Snaps position using given options.
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.
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
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).
Track to be inserted into the Project's Tracklist.
A region (clip) is an object on the timeline that contains either MidiNote's or AudioClip's.