Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / batch.C
blob6cb240ec170b7b7f4d8e93fd8d0b323bc1e8e028
1 #include "asset.h"
2 #include "batch.h"
3 #include "channel.h"
4 #include "channeldb.h"
5 #include "edl.h"
6 #include "record.h"
7 #include "recordlabel.h"
9 #include <string.h>
14 Batch::Batch(MWindow *mwindow, Record *record)
16         this->mwindow = mwindow;
17         this->record = record;
18         channel = 0;
19         start_type = RECORD_START;
20         duration = 0;
21         enabled = 1;
22         file_exists = 0;
23         start_time = 0;
24         start_day = 0;
25         record_mode = RECORD_INFINITE;
26         news[0] = 0;
27 // Create default asset
28         current_asset = 0;
29         recorded = 0;
30         file_offset = 0;
31         waiting = 0;
32         total_samples = 0;
33         total_frames = 0;
34         current_sample = 0;
35         current_frame = 0;
36         session_samples = 0;
37         session_frames = 0;
38         assets.push_back(Asset_GC(new Asset));
39         labels = new RecordLabels;
40         edl = 0;
43 Batch::~Batch()
45         assets.clear();
46         delete labels;
47         if(edl) delete edl;
50 int Batch::create_objects()
52         return 0;
55 void Batch::start_over()
57         file_offset = 0;
58         calculate_news();
60         while(labels->last) delete labels->last;
61         total_frames = 0;
62         total_samples = 0;
63         current_frame = 0;
64         current_sample = 0;
67 void Batch::copy_from(Batch *batch)
69         enabled = batch->enabled;
70         channel = batch->channel;
71         start_type = batch->start_type;
72         duration = batch->duration;
73         start_time = batch->start_time;
74         start_day = batch->start_day;
75         record_mode = batch->record_mode;
79 void Batch::calculate_news()
81 // File open
82         if(record->get_current_batch() == this && record->file)
83         {
84                 sprintf(news, _("Open"));
85         }
86         else
87         {
88 // Test file existance
89                 FILE *test = fopen(get_current_asset()->path, "r");
91                 if(test)
92                 {
93                         sprintf(news, _("File exists"));
94                         fclose(test);
95                 }
96                 else
97                         sprintf(news, _("OK"));
98         }
101 void Batch::create_default_path()
103         char *path = get_current_asset()->path;
104         char string[BCTEXTLEN];
105         int i, j = -1, k = -1;
106         int number = record->batches.total;
108         strcpy(string, record->default_asset->path);
109         strcpy(path, record->default_asset->path);
111 // Find first number in path
112         for(i = 0; i < strlen(path); i++)
113         {
114                 if(path[i] >= '0' && path[i] <= '9') j = i;
115                 if((path[i] < '0' || path[i] > '9') && j >= 0 && k < 0) k = i;
116         }
118         if(j < 0)
119         {
120                 j = strlen(path);
121         }
122         
123         if(k < 0)
124         {
125                 k = strlen(path);
126         }
128         
129         sprintf(&path[j], "%d", record->batches.total);
130         strcat(path, &string[k]);
134 int Batch::text_to_mode(char *text)
136         if(!strcasecmp(mode_to_text(RECORD_INFINITE), text)) return RECORD_INFINITE;
137         if(!strcasecmp(mode_to_text(RECORD_TIMED), text)) return RECORD_TIMED;
138 //      if(!strcasecmp(mode_to_text(RECORD_LOOP), text)) return RECORD_LOOP;
139 //      if(!strcasecmp(mode_to_text(RECORD_SCENETOSCENE), text)) return RECORD_SCENETOSCENE;
140         return RECORD_INFINITE;
143 char* Batch::mode_to_text(int record_mode)
145         switch(record_mode)
146         {
147                 case RECORD_INFINITE:
148                         return _("Untimed");
149                         break;
150                 case RECORD_TIMED:
151                         return _("Timed");
152                         break;
153 //              case RECORD_LOOP:
154 //                      return "Loop";
155 //                      break;
156 //              case RECORD_SCENETOSCENE:
157 //                      return "Scene to scene";
158 //                      break;
159         }
160         return _("Unknown");
163 Asset_GC Batch::get_current_asset()
165         return assets[current_asset];
169 Channel* Batch::get_current_channel_struct()
171         if(channel >= 0 && channel < record->channeldb->size())
172         {
173                 return record->channeldb->get(channel);
174         }
175         return 0;
179 char* Batch::get_source_text()
181 // Driver sensitive
182         Channel *channel = get_current_channel_struct();
185         if(channel)
186         {
187 //printf("Batch::get_source_text 1 %s\n", channel->title);
188                 return channel->title;
189         }
190         else
191                 return "";
194 void Batch::toggle_label(double position)
196         labels->toggle_label(position);
199 //      Local Variables:
200 //      mode: C++
201 //      c-file-style: "linux"
202 //      End: