Test cases for audio/midi_region full region export test
Signed-off-by: Robert Panovics <robert.panovics@gmail.com>
---
ext/midilib/MIDIFiles/loop0_ref.mid | Bin 0 -> 127 bytes
ext/midilib/MIDIFiles/loop1_ref.mid | Bin 0 -> 103 bytes
ext/midilib/MIDIFiles/loop2_ref.mid | Bin 0 -> 112 bytes
ext/midilib/MIDIFiles/loop3_ref.mid | Bin 0 -> 104 bytes
ext/midilib/MIDIFiles/loop4_ref.mid | Bin 0 -> 94 bytes
ext/midilib/MIDIFiles/loopbase.mid | Bin 0 -> 112 bytes
tests/audio/midi_region.c | 155 ++++++++++++++++++++++++++++
7 files changed, 155 insertions(+)
create mode 100644 ext/midilib/MIDIFiles/loop0_ref.mid
create mode 100644 ext/midilib/MIDIFiles/loop1_ref.mid
create mode 100644 ext/midilib/MIDIFiles/loop2_ref.mid
create mode 100644 ext/midilib/MIDIFiles/loop3_ref.mid
create mode 100644 ext/midilib/MIDIFiles/loop4_ref.mid
create mode 100644 ext/midilib/MIDIFiles/loopbase.mid
diff --git a/ext/midilib/MIDIFiles/loop0_ref.mid b/ext/midilib/MIDIFiles/loop0_ref.mid
new file mode 100644
index 0000000000000000000000000000000000000000..972b4fc7370c5354a9aa54bf66a6fd70b373a47a
GIT binary patch
literal 127
zcmeYb$w*;fU|<7cM&<*)Aw}6hRwl#$KxVcsX@>t1EG!HX91Q=NxqLlcJQYHU5|gvr
b9VS>uF-)+HYIkS=G8#Y(azq&Z>oWiVdZ#5O
literal 0
HcmV?d00001
diff --git a/ext/midilib/MIDIFiles/loop1_ref.mid b/ext/midilib/MIDIFiles/loop1_ref.mid
new file mode 100644
index 0000000000000000000000000000000000000000..f52d1282bf56e34e7bc03c237c829c8baeb19f09
GIT binary patch
literal 103
zcmeYb$w*;fU|<7cM&<*)Aw}6hRv^RwKxVcsX@>t1EG!HX91Q=NxqLlcJQYHU5|gvr
o9VS>t0SR*;(EujET+66_h6XUpI*MU}El3i`Xt0f9_^;0Z0CX`P3;+NC
literal 0
HcmV?d00001
diff --git a/ext/midilib/MIDIFiles/loop2_ref.mid b/ext/midilib/MIDIFiles/loop2_ref.mid
new file mode 100644
index 0000000000000000000000000000000000000000..daad3c0204ab07e8117cbbfbe7e958a784f9564a
GIT binary patch
literal 112
zcmeYb$w*;fU|<7cM&<*)Aw}6hRusekKxVcsX@>t1EG!HX91Q=NxqLlcJQYHU5|gvr
q9VS>t0SR*;(EujET<a)?3AP|1YmlU66hi}u2T=v$nFCGLX8-`1w;@IV
literal 0
HcmV?d00001
diff --git a/ext/midilib/MIDIFiles/loop3_ref.mid b/ext/midilib/MIDIFiles/loop3_ref.mid
new file mode 100644
index 0000000000000000000000000000000000000000..fa0a305ec91cea81306b7a3bff106cf61162f3e0
GIT binary patch
literal 104
zcmeYb$w*;fU|<7cM&<*)Aw}6hRuIGgKxVcsX@>t1EG!HX91Q=NxqLlcJQYHU5|gvr
d9VS>t0SR*;(EuWVEQSV<5R8Y$V)(Dm005O^9`pbJ
literal 0
HcmV?d00001
diff --git a/ext/midilib/MIDIFiles/loop4_ref.mid b/ext/midilib/MIDIFiles/loop4_ref.mid
new file mode 100644
index 0000000000000000000000000000000000000000..b1121b4a94955713882e45db30b33ab30557ef0a
GIT binary patch
literal 94
zcmeYb$w*;fU|<7cM&<*)Aw}6hmIuTCKxVcsX@>t1EG!HX91Q=NxqLlcJQYHU5|gvr
d9VS>t0SR*;(EujET&NgB1Bd|>XZWwr003?L8!i9<
literal 0
HcmV?d00001
diff --git a/ext/midilib/MIDIFiles/loopbase.mid b/ext/midilib/MIDIFiles/loopbase.mid
new file mode 100644
index 0000000000000000000000000000000000000000..c332453c712a96d2d782edcec1bda4a69530a216
GIT binary patch
literal 112
zcmeYb$w*;fU|<7cM&<*)Aw}6hRusekKxVcsX@>t1EG!HX91Q=NxqLlcJQYHU5|gvr
v9VS>uF-)+HYIkU`1`-o2qZk@Myb0zYAuwSH5$|W1U<Z^0@fv`P|N0C7g~1^l
literal 0
HcmV?d00001
diff --git a/tests/audio/midi_region.c b/tests/audio/midi_region.c
index 53f7c2952..626dd4952 100644
--- a/tests/audio/midi_region.c
+++ b/tests/audio/midi_region.c
@@ -25,6 +25,7 @@
#include "audio/transport.h"
#include "project.h"
#include "utils/flags.h"
+#include "utils/hash.h"
#include "utils/io.h"
#include "zrythm.h"
@@ -95,6 +96,156 @@ test_export (void)
io_rmdir (export_dir, true);
}
+static const double full_export_test_loop_positions[] = {
+ /* loop before clip start pos */
+ 0.0, 1920.0,
+ /* clip start pos inside loop */
+ 0.0, 8640.0,
+ /* clip start pos inside loop with cuting end of note */
+ 0.0, 5760.0,
+ /* loop after clip start pos with note start before loop start */
+ 3840.0, 5760.0,
+ /* loop after clip start pos with cuting end of note */
+ 3840.0, 7680.0
+};
+
+static void
+compare_files_hash (
+ const char * filepath1,
+ const char * filepath2)
+{
+ g_message ("Comparing: %s - %s", filepath1, filepath2);
+
+ g_assert_true (g_file_test (
+ filepath1,
+ G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
+ g_assert_true (g_file_test (
+ filepath2,
+ G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
+ uint32_t file1_hash =
+ hash_get_from_file_simple (filepath1);
+ uint32_t file2_hash =
+ hash_get_from_file_simple (filepath2);
+
+ g_assert_true (file1_hash == file2_hash);
+}
+
+static void
+setup_region_for_full_export (ZRegion * region)
+{
+ Position clip_start_pos;
+ position_init (&clip_start_pos);
+ position_from_ticks (&clip_start_pos, 1920.0);
+
+ position_add_ticks (
+ &((ArrangerObject *) region)->pos, 1920.0);
+ position_add_ticks (
+ &((ArrangerObject *) region)->end_pos, 960.0);
+ arranger_object_clip_start_pos_setter (
+ (ArrangerObject *) region, &clip_start_pos);
+}
+
+static void
+test_full_export (void)
+{
+ const int number_of_loop_tests =
+ sizeof (full_export_test_loop_positions)
+ / sizeof (double) / 2;
+
+ char * base_midi_file = g_build_filename (
+ MIDILIB_TEST_MIDI_FILES_PATH, "loopbase.mid",
+ NULL);
+
+ g_assert_true (g_file_test (
+ base_midi_file,
+ G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
+
+ char * export_dir = g_dir_make_tmp (
+ "test_midi_full_export_XXXXXX", NULL);
+
+ test_helper_zrythm_init ();
+
+ SupportedFile * file =
+ supported_file_new_from_path (base_midi_file);
+ track_create_with_action (
+ TRACK_TYPE_MIDI, NULL, file, PLAYHEAD,
+ TRACKLIST->num_tracks, 1, NULL);
+ supported_file_free (file);
+
+ Track * track = tracklist_get_last_track (
+ TRACKLIST, TRACKLIST_PIN_OPTION_BOTH, true);
+
+ g_assert_cmpint (track->num_lanes, >, 0);
+ g_assert_cmpint (
+ track->lanes[0]->num_regions, >, 0);
+ ZRegion * region = track->lanes[0]->regions[0];
+ g_assert_true (IS_REGION (region));
+
+ setup_region_for_full_export (region);
+
+ for (int iter = 0; iter < number_of_loop_tests;
+ ++iter)
+ {
+ POSITION_INIT_ON_STACK (loop_start_pos);
+ POSITION_INIT_ON_STACK (loop_end_pos);
+ position_from_ticks (
+ &loop_start_pos,
+ full_export_test_loop_positions[iter * 2]);
+ position_from_ticks (
+ &loop_end_pos,
+ full_export_test_loop_positions[iter * 2 + 1]);
+
+ g_message (
+ "testing loop %lf, %lf",
+ loop_start_pos.ticks, loop_end_pos.ticks);
+
+ arranger_object_loop_start_pos_setter (
+ (ArrangerObject *) region, &loop_start_pos);
+ arranger_object_loop_end_pos_setter (
+ (ArrangerObject *) region, &loop_end_pos);
+
+ char export_file_name[20];
+ sprintf (
+ export_file_name, "loopbase%d.mid", iter);
+ char * export_filepath = g_build_filename (
+ export_dir, export_file_name, NULL);
+
+ midi_region_export_to_midi_file (
+ region, export_filepath, 0, false);
+
+ compare_files_hash (
+ base_midi_file, export_filepath);
+
+ io_remove (export_filepath);
+ g_free (export_filepath);
+
+ sprintf (export_file_name, "loop%d.mid", iter);
+ export_filepath = g_build_filename (
+ export_dir, export_file_name, NULL);
+
+ char reference_file_name[20];
+ sprintf (
+ reference_file_name, "loop%d_ref.mid", iter);
+ char * reference_filepath = g_build_filename (
+ MIDILIB_TEST_MIDI_FILES_PATH,
+ reference_file_name, NULL);
+
+ midi_region_export_to_midi_file (
+ region, export_filepath, 0, true);
+
+ compare_files_hash (
+ reference_filepath, export_filepath);
+ io_remove (export_filepath);
+
+ g_free (reference_filepath);
+ g_free (export_filepath);
+ }
+
+ test_helper_zrythm_cleanup ();
+ io_rmdir (export_dir, true);
+ g_free (base_midi_file);
+}
+
int
main (int argc, char * argv[])
{
@@ -106,5 +257,9 @@ main (int argc, char * argv[])
TEST_PREFIX "test export",
(GTestFunc) test_export);
+ g_test_add_func (
+ TEST_PREFIX "test full export",
+ (GTestFunc) test_full_export);
+
return g_test_run ();
}
--
2.35.1
Thanks! Applied as f2a8249be with the following changes:
- added your copyright notice and switched to the new header style
- moved the files to tests directory (`ext` is only used for external
projects so the only changes going there should be our own meson build
scripts or fixing bugs)
diff --git a/tests/audio/midi_region.c b/tests/audio/midi_region.c
index 626dd4952..a382a87e9 100644
--- a/tests/audio/midi_region.c
+++ b/tests/audio/midi_region.c
@@ -1,21 +1,6 @@
-/*
- * Copyright (C) 2020-2022 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/>.
- */
+// SPDX-FileCopyrightText: © 2020-2022 Alexandros Theodotou
<alex@zrythm.org>
+// SPDX-FileCopyrightText: © 2022 Robert Panovics
<robert.panovics@gmail.com>
+// SPDX-License-Identifier: LicenseRef-ZrythmLicense
#include "zrythm-test-config.h"
@@ -114,8 +99,9 @@ compare_files_hash (
const char * filepath1,
const char * filepath2)
{
- g_message ("Comparing: %s - %s", filepath1, filepath2);
-
+ g_message (
+ "Comparing: %s - %s", filepath1, filepath2);
+
g_assert_true (g_file_test (
filepath1,
G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
@@ -126,7 +112,7 @@ compare_files_hash (
hash_get_from_file_simple (filepath1);
uint32_t file2_hash =
hash_get_from_file_simple (filepath2);
-
+
g_assert_true (file1_hash == file2_hash);
}
@@ -153,8 +139,7 @@ test_full_export (void)
/ sizeof (double) / 2;
char * base_midi_file = g_build_filename (
- MIDILIB_TEST_MIDI_FILES_PATH, "loopbase.mid",
- NULL);
+ TESTS_SRCDIR, "loopbase.mid", NULL);
g_assert_true (g_file_test (
base_midi_file,
@@ -227,8 +212,7 @@ test_full_export (void)
sprintf (
reference_file_name, "loop%d_ref.mid", iter);
char * reference_filepath = g_build_filename (
- MIDILIB_TEST_MIDI_FILES_PATH,
- reference_file_name, NULL);
+ TESTS_SRCDIR, reference_file_name, NULL);
midi_region_export_to_midi_file (
region, export_filepath, 0, true);
@@ -253,13 +237,12 @@ main (int argc, char * argv[])
#define TEST_PREFIX "/audio/midi_region/"
- g_test_add_func (
- TEST_PREFIX "test export",
- (GTestFunc) test_export);
-
g_test_add_func (
TEST_PREFIX "test full export",
(GTestFunc) test_full_export);
+ g_test_add_func (
+ TEST_PREFIX "test export",
+ (GTestFunc) test_export);
return g_test_run ();
}
diff --git a/ext/midilib/MIDIFiles/loop0_ref.mid b/tests/loop0_ref.mid
similarity index 100%
rename from ext/midilib/MIDIFiles/loop0_ref.mid
rename to tests/loop0_ref.mid
diff --git a/ext/midilib/MIDIFiles/loop1_ref.mid b/tests/loop1_ref.mid
similarity index 100%
rename from ext/midilib/MIDIFiles/loop1_ref.mid
rename to tests/loop1_ref.mid
diff --git a/ext/midilib/MIDIFiles/loop2_ref.mid b/tests/loop2_ref.mid
similarity index 100%
rename from ext/midilib/MIDIFiles/loop2_ref.mid
rename to tests/loop2_ref.mid
diff --git a/ext/midilib/MIDIFiles/loop3_ref.mid b/tests/loop3_ref.mid
similarity index 100%
rename from ext/midilib/MIDIFiles/loop3_ref.mid
rename to tests/loop3_ref.mid
diff --git a/ext/midilib/MIDIFiles/loop4_ref.mid b/tests/loop4_ref.mid
similarity index 100%
rename from ext/midilib/MIDIFiles/loop4_ref.mid
rename to tests/loop4_ref.mid
diff --git a/ext/midilib/MIDIFiles/loopbase.mid b/tests/loopbase.mid
similarity index 100%
rename from ext/midilib/MIDIFiles/loopbase.mid
rename to tests/loopbase.mid