11c6a3100d249cd08b94a4a109d4c8e343fa4e03
[goodguy/history.git] / cinelerra-5.1 / cinelerra / fileformat.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 "asset.h"
23 #include "assets.h"
24 #include "bitspopup.h"
25 #include "fileformat.h"
26 #include "language.h"
27 #include "mwindow.h"
28 #include "mwindowgui.h"
29 #include "new.h"
30
31
32
33 FileFormat::FileFormat(MWindow *mwindow)
34  : BC_Window(_(PROGRAM_NAME ": File Format"),
35                 mwindow->gui->get_abs_cursor_x(0),
36                 mwindow->gui->get_abs_cursor_y(0),
37                 375,
38                 300,
39                 375,
40                 300)
41 {
42         this->mwindow = mwindow;
43 }
44
45 FileFormat::~FileFormat()
46 {
47         lock_window("FileFormat::~FileFormat");
48         delete lohi;
49         delete hilo;
50         delete signed_button;
51         delete header_button;
52         delete rate_button;
53         delete channels_button;
54         delete bitspopup;
55         unlock_window();
56 }
57
58 void FileFormat::create_objects(Asset *asset, char *string2)
59 {
60 // ================================= copy values
61         this->asset = asset;
62         create_objects_(string2);
63 }
64
65 void FileFormat::create_objects_(char *string2)
66 {
67         char string[1024];
68         int x1 = 10, x2 = 180;
69         int x = x1, y = 10;
70
71         lock_window("FileFormat::create_objects_");
72         add_subwindow(new BC_Title(x, y, string2));
73         y += 20;
74         add_subwindow(new BC_Title(x, y, _("Assuming raw PCM:")));
75
76         y += 30;
77         add_subwindow(new BC_Title(x, y, _("Channels:")));
78         sprintf(string, "%d", asset->channels);
79         channels_button = new FileFormatChannels(x2, y, this, string);
80         channels_button->create_objects();
81
82         y += 30;
83         add_subwindow(new BC_Title(x, y, _("Sample rate:")));
84         sprintf(string, "%d", asset->sample_rate);
85         add_subwindow(rate_button = new FileFormatRate(x2, y, this, string));
86         add_subwindow(new SampleRatePulldown(mwindow, rate_button, x2 + 100, y));
87
88         y += 30;
89         add_subwindow(new BC_Title(x, y, _("Bits:")));
90         bitspopup = new BitsPopup(this,
91                 x2,
92                 y,
93                 &asset->bits,
94                 0,
95                 1,
96                 1,
97                 0,
98                 1);
99         bitspopup->create_objects();
100
101         y += 30;
102         add_subwindow(new BC_Title(x, y, _("Header length:")));
103         sprintf(string, "%d", asset->header);
104         add_subwindow(header_button = new FileFormatHeader(x2, y, this, string));
105
106         y += 30;
107
108 //printf("FileFormat::create_objects_ 1 %d\n", asset->byte_order);
109         add_subwindow(new BC_Title(x, y, _("Byte order:")));
110         add_subwindow(lohi = new FileFormatByteOrderLOHI(x2, y, this, asset->byte_order));
111         add_subwindow(hilo = new FileFormatByteOrderHILO(x2 + 70, y, this, !asset->byte_order));
112
113         y += 30;
114         add_subwindow(signed_button = new FileFormatSigned(x, y, this, asset->signed_));
115
116         add_subwindow(new BC_OKButton(this));
117         add_subwindow(new BC_CancelButton(this));
118
119         show_window(1);
120         unlock_window();
121 }
122
123 FileFormatChannels::FileFormatChannels(int x, int y, FileFormat *fwindow, char *text)
124  : BC_TumbleTextBox(fwindow,
125         (int)atol(text),
126         (int)1,
127         (int)MAXCHANNELS,
128         x,
129         y,
130         50)
131 {
132         this->fwindow = fwindow;
133 }
134
135 int FileFormatChannels::handle_event()
136 {
137         fwindow->asset->channels = atol(get_text());
138         return 0;
139 }
140
141 FileFormatRate::FileFormatRate(int x, int y, FileFormat *fwindow, char *text)
142  : BC_TextBox(x, y, 100, 1, text)
143 {
144         this->fwindow = fwindow;
145 }
146
147 int FileFormatRate::handle_event()
148 {
149         fwindow->asset->sample_rate = atol(get_text());
150         return 0;
151 }
152
153 FileFormatHeader::FileFormatHeader(int x, int y, FileFormat *fwindow, char *text)
154  : BC_TextBox(x, y, 100, 1, text)
155 {
156         this->fwindow = fwindow;
157 }
158
159 int FileFormatHeader::handle_event()
160 {
161         fwindow->asset->header = atol(get_text());
162         return 0;
163 }
164
165 FileFormatByteOrderLOHI::FileFormatByteOrderLOHI(int x, int y, FileFormat *fwindow, int value)
166  : BC_Radial(x, y, value, _("Lo Hi"))
167 {
168         this->fwindow = fwindow;
169 }
170
171 int FileFormatByteOrderLOHI::handle_event()
172 {
173         update(1);
174         fwindow->asset->byte_order = 1;
175         fwindow->hilo->update(0);
176         return 1;
177 }
178
179 FileFormatByteOrderHILO::FileFormatByteOrderHILO(int x, int y, FileFormat *fwindow, int value)
180  : BC_Radial(x, y, value, _("Hi Lo"))
181 {
182         this->fwindow = fwindow;
183 }
184
185 int FileFormatByteOrderHILO::handle_event()
186 {
187         update(1);
188         fwindow->asset->byte_order = 0;
189         fwindow->lohi->update(0);
190         return 1;
191 }
192
193 FileFormatSigned::FileFormatSigned(int x, int y, FileFormat *fwindow, int value)
194  : BC_CheckBox(x, y, value, _("Values are signed"))
195 {
196         this->fwindow = fwindow;
197 }
198
199 int FileFormatSigned::handle_event()
200 {
201         fwindow->asset->signed_ = get_value();
202         return 1;
203 }