r1026: Videoscope layout tweaks.
[cinelerra_cv/ct.git] / cinelerra / batch.C
blob7e6a2b3b9c82107e2a491e9bb5674e1f0a37f5d5
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.append(new Asset);
39         labels = new RecordLabels;
40         edl = 0;
43 Batch::~Batch()
45         for(int i = 0; i < assets.total; i++)
46                 Garbage::delete_object(assets.values[i]);
47         assets.remove_all();
48         delete labels;
49         if(edl) delete edl;
52 int Batch::create_objects()
54         return 0;
57 void Batch::start_over()
59         file_offset = 0;
60         calculate_news();
62         while(labels->last) delete labels->last;
63         total_frames = 0;
64         total_samples = 0;
65         current_frame = 0;
66         current_sample = 0;
69 void Batch::copy_from(Batch *batch)
71         enabled = batch->enabled;
72         channel = batch->channel;
73         start_type = batch->start_type;
74         duration = batch->duration;
75         start_time = batch->start_time;
76         start_day = batch->start_day;
77         record_mode = batch->record_mode;
81 void Batch::calculate_news()
83 // File open
84         if(record->get_current_batch() == this && record->file)
85         {
86                 sprintf(news, _("Open"));
87         }
88         else
89         {
90 // Test file existance
91                 FILE *test = fopen(get_current_asset()->path, "r");
93                 if(test)
94                 {
95                         sprintf(news, _("File exists"));
96                         fclose(test);
97                 }
98                 else
99                         sprintf(news, _("OK"));
100         }
103 void Batch::create_default_path()
105         char *path = get_current_asset()->path;
106         char string[BCTEXTLEN];
107         int i, j = -1, k = -1;
108         int number = record->batches.total;
110         strcpy(string, record->default_asset->path);
111         strcpy(path, record->default_asset->path);
113 // Find first number in path
114         for(i = 0; i < strlen(path); i++)
115         {
116                 if(path[i] >= '0' && path[i] <= '9') j = i;
117                 if((path[i] < '0' || path[i] > '9') && j >= 0 && k < 0) k = i;
118         }
120         if(j < 0)
121         {
122                 j = strlen(path);
123         }
124         
125         if(k < 0)
126         {
127                 k = strlen(path);
128         }
130         
131         sprintf(&path[j], "%d", record->batches.total);
132         strcat(path, &string[k]);
136 int Batch::text_to_mode(char *text)
138         if(!strcasecmp(mode_to_text(RECORD_INFINITE), text)) return RECORD_INFINITE;
139         if(!strcasecmp(mode_to_text(RECORD_TIMED), text)) return RECORD_TIMED;
140 //      if(!strcasecmp(mode_to_text(RECORD_LOOP), text)) return RECORD_LOOP;
141 //      if(!strcasecmp(mode_to_text(RECORD_SCENETOSCENE), text)) return RECORD_SCENETOSCENE;
142         return RECORD_INFINITE;
145 char* Batch::mode_to_text(int record_mode)
147         switch(record_mode)
148         {
149                 case RECORD_INFINITE:
150                         return _("Untimed");
151                         break;
152                 case RECORD_TIMED:
153                         return _("Timed");
154                         break;
155 //              case RECORD_LOOP:
156 //                      return "Loop";
157 //                      break;
158 //              case RECORD_SCENETOSCENE:
159 //                      return "Scene to scene";
160 //                      break;
161         }
162         return _("Unknown");
165 Asset* Batch::get_current_asset()
167         return assets.values[current_asset];
171 Channel* Batch::get_current_channel_struct()
173         if(channel >= 0 && channel < record->channeldb->size())
174         {
175                 return record->channeldb->get(channel);
176         }
177         return 0;
181 char* Batch::get_source_text()
183 // Driver sensitive
184         Channel *channel = get_current_channel_struct();
187         if(channel)
188         {
189 //printf("Batch::get_source_text 1 %s\n", channel->title);
190                 return channel->title;
191         }
192         else
193                 return "";
196 void Batch::toggle_label(double position)
198         labels->toggle_label(position);