fix compose mess, and a number of 64 bit printf specs
[ardour.git] / libs / ardour / audiofilter.cc
1 /*
2     Copyright (C) 2004 Paul Davis 
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18     $Id$
19 */
20
21 #include <time.h>
22 #include <cerrno>
23
24 #include <pbd/basename.h>
25 #include <ardour/filesource.h>
26 #include <ardour/session.h>
27 #include <ardour/audioregion.h>
28 #include <ardour/audiofilter.h>
29
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33
34 int
35 AudioFilter::make_new_sources (AudioRegion& region, AudioRegion::SourceList& nsrcs)
36 {
37         vector<string> names = region.master_source_names();
38
39         for (uint32_t i = 0; i < region.n_channels(); ++i) {
40
41                 string path = session.path_from_region_name (PBD::basename_nosuffix (names[i]), string (""));
42
43                 if (path.length() == 0) {
44                         error << string_compose (_("audiofilter: error creating name for new audio file based on %1"), region.name()) 
45                               << endmsg;
46                         return -1;
47                 }
48
49                 try {
50                         nsrcs.push_back (new FileSource (path, session.frame_rate()));
51                 } 
52
53                 catch (failed_constructor& err) {
54                         error << string_compose (_("audiofilter: error creating new audio file %1 (%2)"), path, strerror (errno)) << endmsg;
55                         return -1;
56                 }
57         }
58
59         return 0;
60 }
61
62 int
63 AudioFilter::finish (AudioRegion& region, AudioRegion::SourceList& nsrcs)
64 {
65         string region_name;
66
67         /* update headers on new sources */
68
69         time_t xnow;
70         struct tm* now;
71
72         time (&xnow);
73         now = localtime (&xnow);
74
75         for (AudioRegion::SourceList::iterator si = nsrcs.begin(); si != nsrcs.end(); ++si) {
76                 dynamic_cast<FileSource*>((*si))->update_header (session.transport_frame(), *now, xnow);
77         }
78
79         /* create a new region */
80
81         region_name = session.new_region_name (region.name());
82         results.clear ();
83         results.push_back (new AudioRegion (nsrcs, 0, region.length(), region_name, 0, 
84                                             Region::Flag (Region::WholeFile|Region::DefaultFlags)));
85
86         return 0;
87 }