rework set default transtion, nested proxy edl fixes, doubleclick proxy media fix...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / formatpresets.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 "clip.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "formatpresets.h"
26 #include "mwindow.h"
27 #include "new.h"
28 #include "setformat.h"
29 #include "interlacemodes.h"
30
31
32 FormatPresets::FormatPresets(MWindow *mwindow,
33         NewWindow *new_gui,
34         SetFormatWindow *format_gui,
35         int x,
36         int y)
37 {
38         this->mwindow = mwindow;
39         this->new_gui = new_gui;
40         this->format_gui = format_gui;
41         gui_base = new_gui ? (BC_WindowBase*)new_gui : (BC_WindowBase*)(format_gui);
42         this->x = x;
43         this->y = y;
44         text = 0;
45         pulldown = 0;
46 }
47
48 FormatPresets::~FormatPresets()
49 {
50         if(text) delete text;
51         if(pulldown) delete pulldown;
52         for(int i = 0; i < preset_items.total; i++)
53                 delete preset_items.values[i];
54 }
55
56 void FormatPresets::create_objects()
57 {
58         FormatPresetItem * item = new FormatPresetItem(mwindow, this, _("User Defined"));
59         preset_items.append(item);
60
61         int i;  const char *p;
62         for(i = 0; (p = mwindow->get_preset_name(i)) != 0; i++) {
63                 item = new FormatPresetItem(mwindow, this, p);
64                 mwindow->fill_preset_defaults(p, item->edl->session);
65                 preset_items.append(item);
66         }
67
68         gui_base->add_subwindow(new BC_Title(x, y, _("Presets:")));
69         int x1 = x;
70         y += 20;
71
72
73         gui_base->add_subwindow(text = new FormatPresetsText(mwindow,
74                 this,
75                 x,
76                 y));
77         x += text->get_w();
78         gui_base->add_subwindow(pulldown = new FormatPresetsPulldown(mwindow,
79                 this,
80                 x,
81                 y));
82         x = x1;
83 }
84
85 FormatPresetItem* FormatPresets::find_preset(EDL *edl)
86 {
87         for(int i = 1; i < preset_items.total; i++)
88         {
89                 FormatPresetItem *preset = preset_items.values[i];
90                 if(edl->session->audio_tracks == preset->edl->session->audio_tracks &&
91                         edl->session->audio_channels == preset->edl->session->audio_channels &&
92                         edl->session->sample_rate == preset->edl->session->sample_rate &&
93                         edl->session->video_tracks == preset->edl->session->video_tracks &&
94                         EQUIV(edl->session->frame_rate, preset->edl->session->frame_rate) &&
95                         edl->session->output_w == preset->edl->session->output_w &&
96                         edl->session->output_h == preset->edl->session->output_h &&
97                         EQUIV(edl->session->aspect_w, preset->edl->session->aspect_w) &&
98                         EQUIV(edl->session->aspect_h, preset->edl->session->aspect_h) &&
99                         edl->session->interlace_mode == preset->edl->session->interlace_mode &&
100                         edl->session->color_model == preset->edl->session->color_model)
101                 {
102                         return preset;
103                 }
104         }
105         return 0;
106 }
107
108 const char* FormatPresets::get_preset_text(EDL *edl)
109 {
110         FormatPresetItem *item = edl ? find_preset(edl) : 0;
111         return item ? item->get_text() : _("User Defined");
112 }
113
114
115 int FormatPresets::handle_event()
116 {
117         return 0;
118 }
119
120 EDL* FormatPresets::get_edl()
121 {
122         return 0;
123 }
124
125
126
127
128
129 FormatPresetsText::FormatPresetsText(MWindow *mwindow,
130         FormatPresets *gui,
131         int x,
132         int y)
133  : BC_TextBox(x,
134         y,
135         200,
136         1,
137         gui->get_preset_text(gui->get_edl()))
138 {
139         this->gui =  gui;
140         this->mwindow = mwindow;
141 }
142
143 int FormatPresetsText::handle_event()
144 {
145         return 1;
146 }
147
148
149
150
151
152
153
154
155
156
157 FormatPresetsPulldown::FormatPresetsPulldown(MWindow *mwindow,
158         FormatPresets *gui,
159         int x,
160         int y)
161  : BC_ListBox(x, y, 200, 250,
162                 LISTBOX_TEXT,                   // Display text list or icons
163                 (ArrayList<BC_ListBoxItem*>*)&gui->preset_items, // Each column has an ArrayList of BC_ListBoxItems.
164                 0,  // Titles for columns.  Set to 0 for no titles
165                 0,  // width of each column
166                 1,  // Total columns.
167                 0,  // Pixel of top of window.
168                 1)
169 {
170         this->mwindow = mwindow;
171         this->gui = gui;
172 }
173
174 int FormatPresetsPulldown::handle_event()
175 {
176         gui->handle_event();
177         FormatPresetItem *preset = ((FormatPresetItem*)get_selection(0, 0));
178         gui->get_edl()->copy_all(preset->edl);
179         gui->text->update(preset->get_text());
180         gui->handle_event();
181         return 1;
182 }
183
184 FormatPresetItem::FormatPresetItem(MWindow *mwindow,
185         FormatPresets *gui,
186         const char *text)
187  : BC_ListBoxItem(text)
188 {
189         this->mwindow = mwindow;
190         this->gui = gui;
191         edl = new EDL;
192         edl->create_objects();
193         edl->copy_all(gui->get_edl());
194 }
195
196 FormatPresetItem::~FormatPresetItem()
197 {
198         edl->Garbage::remove_user();
199 }
200
201