fix mistaken "do not roll" conclusion in TransportFSM::compute_should_roll()
[ardour.git] / session_utils / new_empty_session.cc
1 /*
2  * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include <iostream>
20 #include <cstdlib>
21 #include <getopt.h>
22
23 #include <glibmm.h>
24
25 #include "common.h"
26
27 using namespace std;
28 using namespace ARDOUR;
29 using namespace SessionUtils;
30
31
32 static void usage ()
33 {
34         // help2man compatible format (standard GNU help-text)
35         printf (UTILNAME " - create a new empty session from the commandline.\n\n");
36         printf ("Usage: " UTILNAME " [ OPTIONS ] <session-dir> [session-name]\n\n");
37         printf ("Options:\n\
38   -h, --help                 display this help and exit\n\
39   -s, --samplerate <rate>    samplerate to use (default 48000)\n\
40   -V, --version              print version information and exit\n\
41 \n");
42
43         printf ("\n\
44 This tool creates a new empty Ardour session.\n\
45 \n\
46 If the session-name is unspecified, the sesion-dir-name is used.\n\
47 If specified, the tool expects a session-name without .ardour\n\
48 file-name extension.\n\
49 \n");
50
51         printf ("\n\
52 Examples:\n\
53 " UTILNAME " -s 44100 /tmp/TestSession TestSession\n\
54 \n");
55
56         printf ("Report bugs to <http://tracker.ardour.org/>\n"
57                 "Website: <http://ardour.org/>\n");
58         ::exit (EXIT_SUCCESS);
59 }
60
61 int main (int argc, char* argv[])
62 {
63         int sample_rate = 48000;
64
65         const char *optstring = "hs:V";
66
67         const struct option longopts[] = {
68                 { "help",       0, 0, 'h' },
69                 { "samplerate", 1, 0, 's' },
70                 { "version",    0, 0, 'V' },
71         };
72
73         int c = 0;
74         while (EOF != (c = getopt_long (argc, argv,
75                                         optstring, longopts, (int *) 0))) {
76                 switch (c) {
77                         case 's':
78                                 {
79                                         const int sr = atoi (optarg);
80                                         if (sr >= 8000 && sr <= 192000) {
81                                                 sample_rate = sr;
82                                         } else {
83                                                 fprintf(stderr, "Invalid Samplerate\n");
84                                         }
85                                 }
86                                 break;
87
88                         case 'V':
89                                 printf ("ardour-utils version %s\n\n", VERSIONSTRING);
90                                 printf ("Copyright (C) GPL 2017 Robin Gareus <robin@gareus.org>\n");
91                                 exit (EXIT_SUCCESS);
92                                 break;
93
94                         case 'h':
95                                 usage ();
96                                 break;
97
98                         default:
99                                 cerr << "Error: unrecognized option. See --help for usage information.\n";
100                                 ::exit (EXIT_FAILURE);
101                                 break;
102                 }
103         }
104
105         std::string snapshot_name;
106
107         if (optind + 2 == argc) {
108                 snapshot_name = argv[optind+1];
109         } else if (optind + 1 == argc) {
110                 snapshot_name = Glib::path_get_basename (argv[optind]);
111         } else  {
112                 cerr << "Error: Missing parameter. See --help for usage information.\n";
113                 ::exit (EXIT_FAILURE);
114         }
115
116         if (snapshot_name.empty ()) {
117                 cerr << "Error: Invalid empty session/snapshot name.\n";
118                 ::exit (EXIT_FAILURE);
119         }
120
121         /* all systems go */
122
123         SessionUtils::init();
124         Session* s = 0;
125
126         s = SessionUtils::create_session (argv[optind], snapshot_name, sample_rate);
127
128         /* save is implicit when creating a new session */
129
130         if (s) {
131                 std::cout << "Created session in '" << s->path () <<"'" << std::endl;
132         }
133
134         SessionUtils::unload_session (s);
135         SessionUtils::cleanup();
136
137         return 0;
138 }