Audacity 3.2.0
RiffTestUtil.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 AcidizerTagUtilMain.cpp
7
8 Matthieu Hodgkinson
9
10 An command-line application to add the Acidizer tags to a WAV file, for the
11 purpose of testing.
12
13**********************************************************************/
14
15#include "AcidizerTags.h"
16#include "LibsndfileTagger.h"
17
18#include "sndfile.h"
19#include <fstream>
20#include <iostream>
21#include <optional>
22
23namespace
24{
25void PrintHelp(const char* const* argv)
26{
27 std::cout
28 << std::endl
29 << "Test utility to tag files either the SoundForge or the MuseHub way."
30 << std::endl;
31 std::cout
32 << "(SoundForge prioritizes number-of-beats over tempo, and the other way round for MuseHub.)"
33 << std::endl
34 << std::endl;
35 std::cout
36 << "Usage: " << argv[0]
37 << " <outputFile> <duration (s)> [ MuseHub [ one-shot | <tempo (bpm)> ] | SoundForge [ one-shot | loop <num. beats> ] ]"
38 << std::endl
39 << std::endl;
40 std::cout << "Examples:" << std::endl << std::endl;
41
42 std::cout
43 << "Create a 10-second file and add 60 BPM information (MuseHub style):"
44 << std::endl;
45 std::cout << "riff-test-util output.wav 10.0 MuseHub 60.0" << std::endl
46 << std::endl;
47
48 std::cout
49 << "Create a 10-second file and specify 16 beats (SoundForge style):"
50 << std::endl;
51 std::cout << "riff-test-util output.wav 10.0 SoundForge 16.0" << std::endl
52 << std::endl;
53
54 std::cout << "Create a 3-second one-shot file:" << std::endl;
55 std::cout << "riff-test-util output.wav 3.0 SoundForge one-shot" << std::endl
56 << std::endl;
57}
58} // namespace
59
60int main(int argc, char* const* argv)
61{
62 using namespace LibImportExport;
63
64 if (argc < 5)
65 {
67 return 1;
68 }
69
70 const std::string inputFile = argv[1];
71 auto duration = 0.;
72 try
73 {
74 duration = std::stod(argv[2]);
75 }
76 catch (std::invalid_argument& e)
77 {
78 std::cout << "Invalid duration: " << argv[2] << std::endl;
80 return 1;
81 }
82
83 Test::LibsndfileTagger tagger { duration, inputFile };
84 if (!tagger)
85 {
86 std::cout << "Failed to open file: " << inputFile << std::endl;
87 return 1;
88 }
89
90 enum class Mode
91 {
92 Unknown,
93 MuseHub,
94 SoundForge,
95 };
96 const Mode mode = std::string { "MuseHub" } == argv[3] ? Mode::MuseHub :
97 std::string { "SoundForge" } == argv[3] ?
98 Mode::SoundForge :
99 Mode::Unknown;
100 if (mode == Mode::Unknown)
101 {
102 std::cout << "Unknown mode: " << argv[3] << std::endl;
104 return 1;
105 }
106
107 const auto isOneShot = argc >= 5 && std::string { "one-shot" } == argv[4];
108 if (isOneShot)
109 tagger.AddAcidizerTags(Test::AcidizerTags::OneShot {});
110 else if (mode == Mode::MuseHub)
111 try
112 {
113 const auto bpm = std::stod(argv[4]);
114 tagger.AddAcidizerTags(Test::AcidizerTags::Loop { bpm });
115 tagger.AddDistributorInfo("Muse Hub");
116 }
117 catch (std::invalid_argument& e)
118 {
119 std::cout << "Invalid BPM: " << argv[4] << std::endl;
121 return 1;
122 }
123 else
124 try
125 {
126 const auto numBeats = std::stoi(argv[4]);
127 tagger.AddAcidizerTags(Test::AcidizerTags::Beats { numBeats });
128 }
129 catch (std::invalid_argument& e)
130 {
131 std::cout << "Invalid number of beats: " << argv[5] << std::endl;
133 return 1;
134 }
135
136 return 0;
137}
int main(int argc, char *const *argv)
When adding tags, the allocated memory must be preserved until the file is closed....
UTILITY_API const char *const * argv
A copy of argv; responsibility of application startup to assign it.
UTILITY_API int argc
A copy of argc; responsibility of application startup to assign it.
void PrintHelp(const char *const *argv)