1 /*
2 * Copyright (C) 2021 Alexandros Theodotou <alex at zrythm dot org>
3 *
4 * This file is part of Zrythm
5 *
6 * Zrythm is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Zrythm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "zrythm-test-config.h"
21
22 #include "actions/tracklist_selections.h"
23 #include "audio/midi_region.h"
24 #include "audio/region.h"
25 #include "audio/transport.h"
26 #include "project.h"
27 #include "utils/flags.h"
28 #include "utils/io.h"
29 #include "zrythm.h"
30
31 #include "tests/helpers/project.h"
32 #include "tests/helpers/zrythm.h"
33
34 static void
test_get_chord_at_pos(void)35 test_get_chord_at_pos (void)
36 {
37 test_helper_zrythm_init ();
38
39 Position p1, p2, loop;
40
41 test_project_rebootstrap_timeline (&p1, &p2);
42
43 position_set_to_bar (&p1, 12);
44 position_set_to_bar (&p2, 24);
45 position_set_to_bar (&loop, 5);
46
47 ZRegion * r = P_CHORD_TRACK->chord_regions[0];
48 ChordObject * co1 = r->chord_objects[0];
49 ChordObject * co2 = r->chord_objects[1];
50 co1->chord_index = 0;
51 co2->chord_index = 2;
52 arranger_object_set_end_pos_full_size (
53 (ArrangerObject *) r, &p2);
54 arranger_object_set_start_pos_full_size (
55 (ArrangerObject *) r, &p1);
56 arranger_object_loop_end_pos_setter (
57 (ArrangerObject *) r, &loop);
58
59 region_print (r);
60
61 Position pos;
62 ChordObject * co;
63
64 position_init (&pos);
65 co =
66 chord_track_get_chord_at_pos (
67 P_CHORD_TRACK, &pos);
68 g_assert_null (co);
69
70 position_set_to_bar (&pos, 2);
71 co =
72 chord_track_get_chord_at_pos (
73 P_CHORD_TRACK, &pos);
74 g_assert_null (co);
75
76 position_set_to_bar (&pos, 3);
77 co =
78 chord_track_get_chord_at_pos (
79 P_CHORD_TRACK, &pos);
80 g_assert_null (co);
81
82 position_set_to_bar (&pos, 12);
83 co =
84 chord_track_get_chord_at_pos (
85 P_CHORD_TRACK, &pos);
86 g_assert_null (co);
87
88 position_set_to_bar (&pos, 13);
89 co =
90 chord_track_get_chord_at_pos (
91 P_CHORD_TRACK, &pos);
92 g_assert_true (co == co1);
93
94 position_set_to_bar (&pos, 14);
95 co =
96 chord_track_get_chord_at_pos (
97 P_CHORD_TRACK, &pos);
98 g_assert_true (co == co1);
99
100 position_set_to_bar (&pos, 15);
101 co =
102 chord_track_get_chord_at_pos (
103 P_CHORD_TRACK, &pos);
104 g_assert_true (co == co2);
105
106 position_set_to_bar (&pos, 16);
107 co =
108 chord_track_get_chord_at_pos (
109 P_CHORD_TRACK, &pos);
110 g_assert_null (co);
111
112 position_set_to_bar (&pos, 17);
113 co =
114 chord_track_get_chord_at_pos (
115 P_CHORD_TRACK, &pos);
116 g_assert_true (co == co1);
117
118 position_set_to_bar (&pos, 18);
119 co =
120 chord_track_get_chord_at_pos (
121 P_CHORD_TRACK, &pos);
122 g_assert_true (co == co1);
123
124 position_set_to_bar (&pos, 19);
125 co =
126 chord_track_get_chord_at_pos (
127 P_CHORD_TRACK, &pos);
128 g_assert_true (co == co2);
129
130 position_set_to_bar (&pos, 100);
131 co =
132 chord_track_get_chord_at_pos (
133 P_CHORD_TRACK, &pos);
134 g_assert_null (co);
135
136 test_helper_zrythm_cleanup ();
137 }
138
139 int
main(int argc,char * argv[])140 main (int argc, char *argv[])
141 {
142 g_test_init (&argc, &argv, NULL);
143
144 #define TEST_PREFIX "/audio/chord track/"
145
146 g_test_add_func (
147 TEST_PREFIX "test get chord at pos",
148 (GTestFunc) test_get_chord_at_pos);
149
150 return g_test_run ();
151 }
152