Fix bugs in BroadcastInfo, and use it in SndfileSource
[ardour.git] / libs / ardour / ardour / broadcast_info.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_broadcast_info_h__
22 #define __ardour_broadcast_info_h__
23
24 #include <string>
25 #include <ctime>
26
27 #include <sndfile.h>
28
29 #include <ardour/types.h>
30
31 using std::string;
32
33 namespace ARDOUR
34 {
35
36 class Session;
37
38 class BroadcastInfo
39 {
40   public:
41
42         /// Construct empty broadcast info
43         BroadcastInfo ();
44         ~BroadcastInfo ();
45         
46         /// Returns last error sring from libsndfile
47         string get_error () const { return error; }
48         
49         /* Convenience functions */
50         
51         void set_from_session (Session const & session, int64_t time_ref);
52         
53         /* Reading */
54         
55         bool load_from_file (string const & filename);
56         bool load_from_file (SNDFILE* sf);
57         
58         string get_description () const;
59         int64_t get_time_reference () const;
60         struct tm get_origination_time () const;
61         string get_originator () const;
62         string get_originator_ref () const;
63         
64         /* Writing */
65         
66         bool write_to_file (string const & filename);
67         bool write_to_file (SNDFILE* sf);
68         
69         void set_description (string const & desc);
70         void set_time_reference (int64_t when);
71         void set_origination_time (struct tm * now = 0); // if 0, use time generated at construction
72         void set_originator (string const & str = "");
73         void set_originator_ref (string const & str = "");
74         
75         /* State info */
76         
77         /// Returns true if a info has been succesfully loaded or anything has been manually set
78         bool has_info () const { return _has_info; }
79
80   private:
81
82         SF_BROADCAST_INFO * info;
83         struct tm _time;
84         
85         void update_error ();
86         string error;
87         
88         bool _has_info;
89 };
90
91
92
93 } // namespace ARDOUR
94
95 #endif /* __ardour_broadcast_info_h__ */