74717e504d58ea0b2524c7b9831d08090a921f26
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / convert.h
1 #ifndef __CONVERT_H__
2 #define __CONVERT_H__
3
4 /*
5  * CINELERRA
6  * Copyright (C) 2015 Adam Williams <broadcast at earthling dot net>
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  * 
22  */
23
24 #include "arraylist.h"
25 #include "audiodevice.inc"
26 #include "asset.h"
27 #include "bcdialog.h"
28 #include "bctimer.inc"
29 #include "convert.inc"
30 #include "file.inc"
31 #include "formattools.h"
32 #include "guicast.h"
33 #include "mainprogress.inc"
34 #include "mutex.inc"
35 #include "mwindow.inc"
36 #include "packagerenderer.h"
37 #include "render.inc"
38
39 class ConvertRender : public Thread
40 {
41 public:
42         ConvertRender(MWindow *mwindow);
43         ~ConvertRender();
44         void reset();
45         void to_convert_path(char *new_path, Indexable *idxbl);
46         int from_convert_path(char *new_path, Indexable *idxbl);
47
48         ArrayList<Indexable *> orig_idxbls;     // originals which match the convert assets
49         ArrayList<Asset *> orig_copies;         // convert assets
50         ArrayList<Indexable *> needed_idxbls;   // originals which match the needed_assets
51         ArrayList<Asset *> needed_copies;       // assets which must be created
52
53         double get_video_length(Indexable *idxbl);
54         double get_audio_length(Indexable *idxbl);
55         double get_length(Indexable *idxbl);
56         int match_format(Asset *asset);
57         EDL *convert_edl(EDL *edl, Indexable *idxbl);  // create render edl for this indexable
58         int add_original(EDL *edl, Indexable *idxbl);
59         void add_needed(Indexable *idxbl, Asset *convert);
60         int find_convertable_assets(EDL *edl);
61
62 // if user canceled progress bar
63         int is_canceled();
64         void set_format(Asset *asset, const char *suffix);
65         void start_convert(float beep, int remove_originals);
66         void run();
67         void create_copy(int i);
68         void start_progress();
69         void stop_progress(const char *msg);
70
71         MWindow *mwindow;
72         const char *suffix;
73         Asset *format_asset;
74         MainProgressBar *progress;
75         ConvertProgress *convert_progress;
76         Timer *progress_timer;
77
78         Mutex *counter_lock;
79         int total_rendered, remove_originals;
80         int failed, canceled, result;
81         float beep;
82 };
83
84 class ConvertMenuItem : public BC_MenuItem
85 {
86 public:
87         ConvertMenuItem(MWindow *mwindow);
88         ~ConvertMenuItem();
89
90         int handle_event();
91         void create_objects();
92
93         MWindow *mwindow;
94         ConvertDialog *dialog;
95 };
96
97 class ConvertFormatTools : public FormatTools
98 {
99 public:
100         ConvertFormatTools(MWindow *mwindow, ConvertWindow *gui, Asset *asset);
101
102         void update_format();
103         ConvertWindow *gui;
104 };
105
106 class ConvertSuffixText : public BC_TextBox
107 {
108 public:
109         ConvertSuffixText(ConvertWindow *gui, ConvertDialog *dialog, int x, int y);
110         ~ConvertSuffixText();
111         int handle_event();
112
113         ConvertWindow *gui;
114         ConvertDialog *dialog;
115 };
116
117 class ConvertRemoveOriginals : public BC_CheckBox
118 {
119 public:
120         ConvertRemoveOriginals(ConvertWindow *gui, int x, int y);
121         ~ConvertRemoveOriginals();
122
123         int handle_event();
124
125         ConvertWindow *gui;
126 };
127
128 class ConvertBeepOnDone : public BC_FPot
129 {
130 public:
131         ConvertBeepOnDone(ConvertWindow *gui, int x, int y);
132         void update();
133         int handle_event();
134
135         ConvertWindow *gui;
136 };
137
138 class ConvertPackageRenderer : public PackageRenderer
139 {
140 public:
141         ConvertPackageRenderer(ConvertRender *render);
142         ~ConvertPackageRenderer();
143
144         int get_master();
145         int get_result();
146         void set_result(int value);
147         void set_progress(int64_t value);
148         int progress_cancelled();
149
150         ConvertRender *render;
151 };
152
153 class ConvertProgress : public Thread
154 {
155 public:
156         ConvertProgress(MWindow *mwindow, ConvertRender *render);
157         ~ConvertProgress();
158
159         void run();
160
161         MWindow *mwindow;
162         ConvertRender *render;
163         int64_t last_value;
164 };
165
166 class ConvertWindow : public BC_Window
167 {
168 public:
169         ConvertWindow(MWindow *mwindow, ConvertDialog *dialog,
170                 int x, int y);
171         ~ConvertWindow();
172
173         void create_objects();
174
175         MWindow *mwindow;
176         ConvertDialog *dialog;
177
178         ConvertSuffixText *suffix_text;
179         ConvertFormatTools *format_tools;
180         ConvertRemoveOriginals *remove_originals;
181         ConvertBeepOnDone *beep_on_done;
182 };
183
184 class ConvertDialog : public BC_DialogThread
185 {
186 public:
187         ConvertDialog(MWindow *mwindow);
188         ~ConvertDialog();
189         BC_Window* new_gui();
190
191         void handle_close_event(int result);
192         void convert();
193
194         MWindow *mwindow;
195         ConvertWindow *gui;
196         Asset *asset;
197         char suffix[BCTEXTLEN];
198         ConvertRender *convert_render;
199
200         int orig_scale, new_scale;
201         int use_scaler, auto_scale;
202         int orig_w, orig_h;
203         int remove_originals;
204         float beep;
205 };
206
207 class ConvertBeep : public Thread
208 {
209 public:
210         enum { BEEP_SAMPLE_RATE=48000 };
211         typedef int16_t audio_data_t;
212         ConvertBeep(MWindow *mwindow);
213         ~ConvertBeep();
214
215         void run();
216         void start();
217         void stop(int wait);
218         void tone(double freq, double secs, double gain);
219
220         MWindow *mwindow;
221         double freq, secs, gain;
222         AudioDevice *audio;
223         int playing_audio, interrupted;
224         int audio_pos;
225 };
226
227 #endif