add haupauge-1657 dual usb capture support, add deinterlace to recordmonitor, asset...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / batch.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "asset.h"
23 #include "batch.h"
24 #include "channel.h"
25 #include "channeldb.h"
26 #include "edl.h"
27 #include "filesystem.h"
28 #include "record.h"
29 #include "recordlabel.h"
30 #include <string.h>
31
32 Batch::Batch(MWindow *mwindow, Record *record)
33 {
34         this->mwindow = mwindow;
35         this->record = record;
36         asset = new Asset;
37         labels = new RecordLabels;
38         record_mode = RECORD_UNTIMED;
39         recorded = 0;
40         channel = 0;
41         enabled = 1;
42         file_exists = 0;
43         start_time = last_start_time = 0.;
44         duration = record_duration = 0.;
45         start_day = 0; last_start_day = -1;
46         time_start = 0;
47         time_end = 0;
48         notice = 0;
49         news[0] = 0;
50 }
51
52 Batch::~Batch()
53 {
54         asset->Garbage::remove_user();
55         delete labels;
56 }
57
58 void Batch::create_objects()
59 {
60 }
61
62 void Batch::clear_labels()
63 {
64         while(labels->last) delete labels->last;
65 }
66
67 void Batch::start_over()
68 {
69         clear_labels();
70 }
71
72 void Batch::copy_from(Batch *batch)
73 {
74         record_mode = batch->record_mode;
75         channel = batch->channel;
76         enabled = batch->enabled;
77         start_time = batch->start_time;
78         duration = batch->duration;
79         record_duration = batch->record_duration;
80         start_day = batch->start_day;
81         last_start_day = -1;
82 }
83
84
85 void Batch::calculate_news()
86 {
87         if( notice ) sprintf(news, "%s", notice);
88         else if( record && record->get_current_batch() == this ) {
89                 FileSystem fs;  char text[BCTEXTLEN];
90                 int64_t bytes = fs.get_size(asset->path);
91                 if( bytes >= 0 ) {
92                         Units::size_totext(bytes, text);
93                         const char *stat = record->file ?  _("Open") :
94                                 !this->enabled ? _("Done") : _("Ok");
95                         sprintf(news,"%s %s", text, stat);
96                 }
97                 else
98                         sprintf(news,"%s", _("New file"));
99         }
100         else {
101                 sprintf(news, "%s", !access(asset->path, F_OK) ?
102                          _("Exists") : _("New file"));
103         }
104 }
105
106 void Batch::create_default_path()
107 {
108         char string[BCTEXTLEN];
109         strcpy(string, record->default_asset->path);
110         char *path = asset->path;
111         strcpy(path, record->default_asset->path);
112         int i = 0, k = 0;
113         while( path[i] ) {
114                 int ch = path[i++];
115                 if( ch == '/' ) k = i;
116         }
117         i = k;
118         while( path[i] && (path[i]<'0' || path[i]>'9') ) ++i;
119         int j = i;
120         while( path[i] && (path[i]>='0' || path[i]<='9') ) ++i;
121         int l = i;
122
123         sprintf(&path[j], "%d", record->record_batches.total());
124         strcat(path, &string[l]);
125 }
126
127
128 int Batch::text_to_mode(const char *text)
129 {
130         if(!strcasecmp(mode_to_text(RECORD_UNTIMED), text)) return RECORD_UNTIMED;
131         if(!strcasecmp(mode_to_text(RECORD_TIMED), text)) return RECORD_TIMED;
132         return RECORD_UNTIMED;
133 }
134
135 const char* Batch::mode_to_text(int record_mode)
136 {
137         switch( record_mode ) {
138         case RECORD_UNTIMED: return _("Untimed");
139         case RECORD_TIMED:   return _("Timed");
140         }
141         return _("Unknown");
142 }
143
144 Channel* Batch::get_current_channel()
145 {
146         return channel;
147 }
148
149
150 const char* Batch::get_source_text()
151 {
152         Channel *channel = get_current_channel();
153         return channel ? channel->title : "";
154 }
155
156 void Batch::toggle_label(double position)
157 {
158         labels->toggle_label(position);
159 }
160
161 void Batch::update_times()
162 {
163         if( start_time != last_start_time ||
164                 start_day != last_start_day ) {
165                 last_start_day = start_day;
166                 last_start_time = start_time;
167                 int64_t seconds = start_time;
168                 int hour = seconds/3600;
169                 int minute = seconds/60 - hour*60;
170                 int second = seconds - (hour*3600 + minute*60);
171                 struct timeval tv;  struct timezone tz;
172                 gettimeofday(&tv, &tz);  time_t t = tv.tv_sec;
173                 if( !strcmp(tzname[0],"UTC") ) t -= tz.tz_minuteswest*60;
174                 struct tm tm;  localtime_r(&t, &tm);
175                 if( start_day < 7 && start_day != tm.tm_wday ) {
176                         int days = start_day - tm.tm_wday;
177                         if( days < 0 ) days += 7;
178                         t += days * 7*24*3600;
179                         localtime_r(&t, &tm);
180                 }
181                 tm.tm_hour = hour;
182                 tm.tm_min = minute;
183                 tm.tm_sec = second;
184                 time_start = mktime(&tm);
185         }
186         time_end = time_start + (int)duration;
187 }
188