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