/
arranger_selections.c
96 lines (79 loc) · 2.41 KB
/
arranger_selections.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 2021 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
#include "zrythm-test-config.h"
#include <math.h>
#include "audio/midi_region.h"
#include "gui/backend/arranger_selections.h"
#include "project.h"
#include "utils/flags.h"
#include "zrythm.h"
#include "tests/helpers/zrythm.h"
#include <glib.h>
#include <locale.h>
static void
test_region_length_in_ticks (
Track * track,
int bar_start,
int bar_end)
{
Position p1, p2;
position_set_to_bar (&p1, bar_start);
position_set_to_bar (&p2, bar_end);
ZRegion * r =
midi_region_new (
&p1, &p2, track->pos, 0, 0);
ArrangerObject * r_obj = (ArrangerObject *) r;
track_add_region (
track, r, NULL, 0, F_GEN_NAME,
F_NO_PUBLISH_EVENTS);
arranger_object_select (
r_obj, F_SELECT, F_NO_APPEND);
double length =
arranger_selections_get_length_in_ticks (
(ArrangerSelections *) TL_SELECTIONS);
g_assert_cmpfloat_with_epsilon (
length,
TRANSPORT->ticks_per_bar * (bar_end - bar_start),
0.00001);
}
static void
test_get_length_in_ticks ()
{
test_helper_zrythm_init ();
UndoableAction * ua =
tracklist_selections_action_new_create_midi (
TRACKLIST->num_tracks, 1);
undo_manager_perform (UNDO_MANAGER, ua);
Track * track =
TRACKLIST->tracks[TRACKLIST->num_tracks - 1];
test_region_length_in_ticks (track, 3, 4);
test_region_length_in_ticks (track, 100, 102);
test_region_length_in_ticks (track, 1000, 1010);
test_helper_zrythm_cleanup ();
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
#define TEST_PREFIX "/gui/backend/arranger selections/"
g_test_add_func (
TEST_PREFIX "test get length in ticks",
(GTestFunc) test_get_length_in_ticks);
return g_test_run ();
}