2 Copyright (C) 2008 Paul Davis
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.
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.
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.
21 #include <ardour/broadcast_info.h>
28 #include <ardour/svn_revision.h>
29 #include <ardour/ardour.h>
30 #include <ardour/session.h>
32 #include <pbd/convert.h>
39 BroadcastInfo::BroadcastInfo () :
42 info = new SF_BROADCAST_INFO;
43 memset (info, 0, sizeof (*info));
45 // Note: Set version to 1 when UMID is used, otherwise version should stay at 0
50 _time = *localtime (&rawtime);
53 BroadcastInfo::~BroadcastInfo ()
59 BroadcastInfo::set_from_session (Session const & session, int64_t time)
61 set_description (session.name());
62 set_time_reference (time);
63 set_origination_time ();
65 set_originator_ref ();
69 BroadcastInfo::load_from_file (string const & filename)
76 if (!(file = sf_open (filename.c_str(), SFM_READ, &info))) {
81 bool ret = load_from_file (file);
88 BroadcastInfo::load_from_file (SNDFILE* sf)
90 if (sf_command (sf, SFC_GET_BROADCAST_INFO, info, sizeof (*info)) != SF_TRUE) {
101 BroadcastInfo::get_description () const
103 return info->description;
107 BroadcastInfo::get_time_reference () const
113 int64_t ret = (uint32_t) info->time_reference_high;
115 ret |= (uint32_t) info->time_reference_low;
120 BroadcastInfo::get_origination_time () const
124 string date = info->origination_date;
125 ret.tm_year = atoi (date.substr (0, 4)) - 1900;
126 ret.tm_mon = atoi (date.substr (5, 2));
127 ret.tm_mday = atoi (date.substr (8, 2));
129 string time = info->origination_time;
130 ret.tm_hour = atoi (time.substr (0,2));
131 ret.tm_min = atoi (time.substr (3,2));
132 ret.tm_sec = atoi (time.substr (6,2));
138 BroadcastInfo::get_originator () const
140 return info->originator;
144 BroadcastInfo::get_originator_ref () const
146 return info->originator_reference;
150 BroadcastInfo::write_to_file (string const & filename)
157 if (!(file = sf_open (filename.c_str(), SFM_RDWR, &info))) {
162 bool ret = write_to_file (file);
169 BroadcastInfo::write_to_file (SNDFILE* sf)
171 if (sf_command (sf, SFC_SET_BROADCAST_INFO, info, sizeof (*info)) != SF_TRUE) {
180 BroadcastInfo::set_description (string const & desc)
184 snprintf (info->description, sizeof (info->description), desc.c_str());
188 BroadcastInfo::set_time_reference (int64_t when)
192 info->time_reference_high = (when >> 32);
193 info->time_reference_low = (when & 0xffffffff);
197 BroadcastInfo::set_origination_time (struct tm * now)
205 snprintf (info->origination_date, sizeof (info->origination_date), "%4d-%02d-%02d",
206 _time.tm_year + 1900,
210 snprintf (info->origination_time, sizeof (info->origination_time), "%02d:%02d:%02d",
217 BroadcastInfo::set_originator (string const & str)
222 snprintf (info->originator, sizeof (info->originator), str.c_str());
226 snprintf (info->originator, sizeof (info->originator), Glib::get_real_name().c_str());
230 BroadcastInfo::set_originator_ref (string const & str)
235 snprintf (info->originator_reference, sizeof (info->originator_reference), str.c_str());
239 /* random code is 9 digits */
241 int random_code = random() % 999999999;
243 /* Serial number is 12 chars */
245 std::ostringstream serial_number;
246 serial_number << "ARDOUR" << "r" << std::setfill('0') << std::right << std::setw(5) << svn_revision;
248 snprintf (info->originator_reference, sizeof (info->originator_reference), "%2s%3s%12s%02d%02d%02d%9d",
249 Config->get_bwf_country_code().c_str(),
250 Config->get_bwf_organization_code().c_str(),
251 serial_number.str().c_str(),
260 BroadcastInfo::update_error ()
263 sf_error_str (0, errbuf, sizeof (errbuf) - 1);
267 } // namespace ARDOUR