Add session-util to create a new empty session
[ardour.git] / session_utils / new_empty_session.cc
1 #include <iostream>
2 #include <cstdlib>
3 #include <getopt.h>
4
5 #include "common.h"
6
7 using namespace std;
8 using namespace ARDOUR;
9 using namespace SessionUtils;
10
11
12 static void usage (int status)
13 {
14         // help2man compatible format (standard GNU help-text)
15         printf (UTILNAME " - create a new empty session from the commandline.\n\n");
16         printf ("Usage: " UTILNAME " [ OPTIONS ] <session-dir> <session/snapshot-name>\n\n");
17         printf ("Options:\n\
18   -h, --help                 display this help and exit\n\
19   -s, --samplerate <rate>    samplerate to use (default 48000)\n\
20   -V, --version              print version information and exit\n\
21 \n");
22         printf ("\n\
23 This tool creates a new empty Ardour session.\n\
24 \n\
25 Note: the tool expects a session-name without .ardour file-name extension.\n\
26 \n\
27 Examples:\n\
28 "UTILNAME " -s 44100 /tmp/TestSession TestSession\n\
29 \n");
30
31         printf ("Report bugs to <http://tracker.ardour.org/>\n"
32                 "Website: <http://ardour.org/>\n");
33         ::exit (status);
34 }
35
36 int main (int argc, char* argv[])
37 {
38         int sample_rate = 48000;
39
40         const char *optstring = "hs:V";
41
42         const struct option longopts[] = {
43                 { "help",       0, 0, 'h' },
44                 { "samplerate", 1, 0, 's' },
45                 { "version",    0, 0, 'V' },
46         };
47
48         int c = 0;
49         while (EOF != (c = getopt_long (argc, argv,
50                                         optstring, longopts, (int *) 0))) {
51                 switch (c) {
52                         case 's':
53                                 {
54                                         const int sr = atoi (optarg);
55                                         if (sr >= 8000 && sr <= 192000) {
56                                                 sample_rate = sr;
57                                         } else {
58                                                 fprintf(stderr, "Invalid Samplerate\n");
59                                         }
60                                 }
61                                 break;
62
63                         case 'V':
64                                 printf ("ardour-utils version %s\n\n", VERSIONSTRING);
65                                 printf ("Copyright (C) GPL 2017 Robin Gareus <robin@gareus.org>\n");
66                                 exit (0);
67                                 break;
68
69                         case 'h':
70                                 usage (0);
71                                 break;
72
73                         default:
74                                 usage (EXIT_FAILURE);
75                                 break;
76                 }
77         }
78
79         // XXX perhaps allow to infer the session-name from the dir-name
80         if (optind + 2 > argc) {
81                 usage (EXIT_FAILURE);
82         }
83
84         /* all systems go */
85
86         SessionUtils::init();
87         Session* s = 0;
88
89         s = SessionUtils::create_session (argv[optind], argv[optind+1], sample_rate);
90
91         /* save is implicit when creating a new session */
92
93         SessionUtils::unload_session(s);
94         SessionUtils::cleanup();
95
96         return 0;
97 }