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