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