Skip to content

Commit

Permalink
Minor refinement of new session util
Browse files Browse the repository at this point in the history
  • Loading branch information
x42 committed Sep 27, 2017
1 parent 476952f commit e96fd26
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions session_utils/new_empty_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <cstdlib>
#include <getopt.h>

#include <glibmm.h>

#include "common.h"

using namespace std;
Expand All @@ -13,19 +15,24 @@ static void usage (int status)
{
// help2man compatible format (standard GNU help-text)
printf (UTILNAME " - create a new empty session from the commandline.\n\n");
printf ("Usage: " UTILNAME " [ OPTIONS ] <session-dir> <session/snapshot-name>\n\n");
printf ("Usage: " UTILNAME " [ OPTIONS ] <session-dir> [session-name]\n\n");
printf ("Options:\n\
-h, --help display this help and exit\n\
-s, --samplerate <rate> samplerate to use (default 48000)\n\
-V, --version print version information and exit\n\
\n");

printf ("\n\
This tool creates a new empty Ardour session.\n\
\n\
Note: the tool expects a session-name without .ardour file-name extension.\n\
\n\
If the session-name is unspecified, the sesion-dir-name is used.\n\
If specified, the tool expects a session-name without .ardour\n\
file-name extension.\n\
\n");

printf ("\n\
Examples:\n\
"UTILNAME " -s 44100 /tmp/TestSession TestSession\n\
" UTILNAME " -s 44100 /tmp/TestSession TestSession\n\
\n");

printf ("Report bugs to <http://tracker.ardour.org/>\n"
Expand Down Expand Up @@ -76,21 +83,35 @@ int main (int argc, char* argv[])
}
}

// XXX perhaps allow to infer the session-name from the dir-name
if (optind + 2 > argc) {
std::string snapshot_name;

if (optind + 2 == argc) {
snapshot_name = argv[optind+1];
} else if (optind + 1 == argc) {
snapshot_name = Glib::path_get_basename (argv[optind]);
} else {
usage (EXIT_FAILURE);
}

if (snapshot_name.empty ()) {
fprintf(stderr, "Error: Invalid empty session/snapshot name.\n");
::exit (EXIT_FAILURE);
}

/* all systems go */

SessionUtils::init();
Session* s = 0;

s = SessionUtils::create_session (argv[optind], argv[optind+1], sample_rate);
s = SessionUtils::create_session (argv[optind], snapshot_name, sample_rate);

/* save is implicit when creating a new session */

SessionUtils::unload_session(s);
if (s) {
std::cout << "Created session in '" << s->path () <<"'" << std::endl;
}

SessionUtils::unload_session (s);
SessionUtils::cleanup();

return 0;
Expand Down

0 comments on commit e96fd26

Please sign in to comment.