r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / batch.C
blob3a20b5da503c0ff8a2381e52c80d45817cf7d11e
1 #include "asset.h"
2 #include "batch.h"
3 #include "channel.h"
4 #include "edl.h"
5 #include "record.h"
6 #include "recordlabel.h"
8 #include <string.h>
13 Batch::Batch(MWindow *mwindow, Record *record)
15         this->mwindow = mwindow;
16         this->record = record;
17         channel = 0;
18         start_type = RECORD_START;
19         duration = 0;
20         enabled = 1;
21         file_exists = 0;
22         start_time = 0;
23         start_day = 0;
24         record_mode = RECORD_INFINITE;
25         news[0] = 0;
26 // Create default asset
27         current_asset = 0;
28         recorded = 0;
29         file_offset = 0;
30         waiting = 0;
31         total_samples = 0;
32         total_frames = 0;
33         current_sample = 0;
34         current_frame = 0;
35         session_samples = 0;
36         session_frames = 0;
37         assets.append(new Asset);
38         labels = new RecordLabels;
39         edl = 0;
42 Batch::~Batch()
44         for(int i = 0; i < assets.total; i++)
45                 delete assets.values[i];
46         assets.remove_all();
47         delete labels;
48         if(edl) delete edl;
51 int Batch::create_objects()
53         return 0;
56 void Batch::start_over()
58         file_offset = 0;
59         calculate_news();
61         while(labels->last) delete labels->last;
62         total_frames = 0;
63         total_samples = 0;
64         current_frame = 0;
65         current_sample = 0;
68 void Batch::copy_from(Batch *batch)
70         enabled = batch->enabled;
71         channel = batch->channel;
72         start_type = batch->start_type;
73         duration = batch->duration;
74         start_time = batch->start_time;
75         start_day = batch->start_day;
76         record_mode = batch->record_mode;
80 void Batch::calculate_news()
82 // File open
83         if(record->get_current_batch() == this && record->file)
84         {
85                 sprintf(news, "Open");
86         }
87         else
88         {
89 // Test file existance
90                 FILE *test = fopen(get_current_asset()->path, "r");
92                 if(test)
93                 {
94                         sprintf(news, "File exists");
95                         fclose(test);
96                 }
97                 else
98                         sprintf(news, "OK");
99         }
102 void Batch::create_default_path()
104         char *path = get_current_asset()->path;
105         char string[BCTEXTLEN];
106         int i, j = -1, k = -1;
107         int number = record->batches.total;
109         strcpy(string, record->default_asset->path);
110         strcpy(path, record->default_asset->path);
112 // Find first number in path
113         for(i = 0; i < strlen(path); i++)
114         {
115                 if(path[i] >= '0' && path[i] <= '9') j = i;
116                 if((path[i] < '0' || path[i] > '9') && j >= 0 && k < 0) k = i;
117         }
119         if(j < 0)
120         {
121                 j = strlen(path);
122         }
123         
124         if(k < 0)
125         {
126                 k = strlen(path);
127         }
129         
130         sprintf(&path[j], "%d", record->batches.total);
131         strcat(path, &string[k]);
135 int Batch::text_to_mode(char *text)
137         if(!strcasecmp(mode_to_text(RECORD_INFINITE), text)) return RECORD_INFINITE;
138         if(!strcasecmp(mode_to_text(RECORD_TIMED), text)) return RECORD_TIMED;
139 //      if(!strcasecmp(mode_to_text(RECORD_LOOP), text)) return RECORD_LOOP;
140 //      if(!strcasecmp(mode_to_text(RECORD_SCENETOSCENE), text)) return RECORD_SCENETOSCENE;
141         return RECORD_INFINITE;
144 char* Batch::mode_to_text(int record_mode)
146         switch(record_mode)
147         {
148                 case RECORD_INFINITE:
149                         return "Untimed";
150                         break;
151                 case RECORD_TIMED:
152                         return "Timed";
153                         break;
154 //              case RECORD_LOOP:
155 //                      return "Loop";
156 //                      break;
157 //              case RECORD_SCENETOSCENE:
158 //                      return "Scene to scene";
159 //                      break;
160         }
161         return "Unknown";
164 Asset* Batch::get_current_asset()
166         return assets.values[current_asset];
170 Channel* Batch::get_current_channel_struct()
172         if(record->current_channeldb())
173         {
174                 if(channel >= 0 && channel < record->current_channeldb()->total)
175                 {
176                         return record->current_channeldb()->values[channel];
177                 }
178         }
179         return 0;
183 char* Batch::get_source_text()
185         // Driver sensitive
186         Channel *channel = get_current_channel_struct();
187         if(channel)
188                 return channel->title;
189         else
190                 return "";
193 void Batch::toggle_label(double position)
195         labels->toggle_label(position);