5 #include "cwindowgui.h"
8 #include "edlsession.h"
9 #include "levelwindow.h"
10 #include "levelwindowgui.h"
12 #include "meterpanel.h"
14 #include "mwindowgui.h"
16 #include "rotateframe.h"
19 #include "transportque.h"
23 #include "vwindowgui.h"
27 #define _(String) gettext(String)
28 #define gettext_noop(String) String
29 #define N_(String) gettext_noop (String)
35 SetAudio::SetAudio(MWindow *mwindow)
36 :BC_MenuItem(_("Audio Setup..."))
38 this->mwindow = mwindow;
39 thread = new SetAudioThread(mwindow);
46 int SetAudio::handle_event()
48 if(!thread->running())
54 thread->window->raise_window();
60 SetAudioThread::SetAudioThread(MWindow *mwindow)
63 this->mwindow = mwindow;
66 SetAudioThread::~SetAudioThread()
76 void SetAudioThread::run()
78 new_settings = new EDL;
79 new_settings->create_objects();
80 new_settings->copy_session(mwindow->edl);
81 window = new SetAudioWindow(mwindow, this);
82 window->create_objects();
84 int result = window->run_window();
87 long old_rate = mwindow->edl->session->sample_rate;
88 long new_rate = new_settings->session->sample_rate;
89 int old_channels = mwindow->edl->session->audio_channels;
90 int new_channels = new_settings->session->audio_channels;
92 mwindow->undo->update_undo_before(_("set audio"), LOAD_EDITS | LOAD_SESSION);
93 mwindow->edl->copy_session(new_settings);
94 mwindow->edl->resample(old_rate, new_rate, TRACK_AUDIO);
95 mwindow->undo->update_undo_after();
99 mwindow->gui->lock_window();
100 mwindow->gui->update(1,
107 mwindow->gui->unlock_window();
110 mwindow->cwindow->gui->lock_window();
111 mwindow->cwindow->gui->resize_event(mwindow->cwindow->gui->get_w(),
112 mwindow->cwindow->gui->get_h());
113 mwindow->cwindow->gui->meters->set_meters(new_channels, 1);
114 mwindow->cwindow->gui->flush();
115 mwindow->cwindow->gui->unlock_window();
117 mwindow->vwindow->gui->lock_window();
118 mwindow->vwindow->gui->resize_event(mwindow->vwindow->gui->get_w(),
119 mwindow->vwindow->gui->get_h());
120 mwindow->vwindow->gui->meters->set_meters(new_channels, 1);
121 mwindow->vwindow->gui->flush();
122 mwindow->vwindow->gui->unlock_window();
124 mwindow->lwindow->gui->lock_window();
125 mwindow->lwindow->gui->panel->set_meters(new_channels, 1);
126 mwindow->lwindow->gui->flush();
127 mwindow->lwindow->gui->unlock_window();
134 mwindow->cwindow->gui->lock_window();
135 mwindow->cwindow->gui->slider->set_position();
136 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
140 mwindow->cwindow->gui->unlock_window();
141 mwindow->save_backup();
152 SetAudioWindow::SetAudioWindow(MWindow *mwindow, SetAudioThread *thread)
153 : BC_Window(PROGRAM_NAME ": Audio Setup",
154 mwindow->gui->get_abs_cursor_x(),
155 mwindow->gui->get_abs_cursor_y(),
164 this->mwindow = mwindow;
165 this->thread = thread;
167 SetAudioWindow::~SetAudioWindow()
171 int SetAudioWindow::create_objects()
173 int x = 10, y = 10, x1;
177 add_subwindow(new BC_Title(x1, y, _("Samplerate:")));
179 add_subwindow(textbox = new SetSampleRateTextBox(thread, x1, y));
180 x1 += textbox->get_w();
181 add_subwindow(new SampleRatePulldown(mwindow, textbox, x1, y));
184 y += textbox->get_h() + 5;
185 add_subwindow(new BC_Title(x1, y, _("Channels:")));
187 add_subwindow(textbox = new SetChannelsTextBox(thread, x1, y));
188 x1 += textbox->get_w();
189 add_subwindow(new BC_ITumbler(textbox, 1, MAXCHANNELS, x1, y));
192 y += textbox->get_h() + 15;
193 add_subwindow(new BC_Title(x1, y, _("Channel positions:")));
195 add_subwindow(canvas = new SetChannelsCanvas(mwindow, thread, x, y));
198 add_subwindow(new BC_OKButton(this));
199 add_subwindow(new BC_CancelButton(this));
204 SetSampleRateTextBox::SetSampleRateTextBox(SetAudioThread *thread, int x, int y)
205 : BC_TextBox(x, y, 100, 1, (long)thread->new_settings->session->sample_rate)
207 this->thread = thread;
209 int SetSampleRateTextBox::handle_event()
211 thread->new_settings->session->sample_rate = CLIP(atol(get_text()), 1, 1000000);
215 SetChannelsTextBox::SetChannelsTextBox(SetAudioThread *thread, int x, int y)
216 : BC_TextBox(x, y, 100, 1, thread->new_settings->session->audio_channels)
218 this->thread = thread;
220 int SetChannelsTextBox::handle_event()
222 thread->new_settings->session->audio_channels = CLIP(atol(get_text()), 0, MAXCHANNELS);
223 thread->window->canvas->draw();
228 SetChannelsCanvas::SetChannelsCanvas(MWindow *mwindow, SetAudioThread *thread, int x, int y)
229 : BC_SubWindow(x, y, mwindow->theme->channel_bg_data->get_w(), mwindow->theme->channel_bg_data->get_h())
231 //printf("SetChannelsCanvas::SetChannelsCanvas 1\n");
232 this->thread = thread;
233 this->mwindow = mwindow;
235 //printf("SetChannelsCanvas::SetChannelsCanvas 1\n");
236 box_r = mwindow->theme->channel_position_data->get_w() / 2;
237 //printf("SetChannelsCanvas::SetChannelsCanvas 1\n");
238 temp_picon = new VFrame(0,
239 mwindow->theme->channel_position_data->get_w(),
240 mwindow->theme->channel_position_data->get_h(),
241 mwindow->theme->channel_position_data->get_color_model());
242 //printf("SetChannelsCanvas::SetChannelsCanvas 1\n");
243 rotater = new RotateFrame(mwindow->edl->session->smp + 1,
244 mwindow->theme->channel_position_data->get_w(),
245 mwindow->theme->channel_position_data->get_h());
246 //printf("SetChannelsCanvas::SetChannelsCanvas 2\n");
248 SetChannelsCanvas::~SetChannelsCanvas()
254 int SetChannelsCanvas::draw(int angle)
257 int real_w = get_w() - box_r * 2;
258 int real_h = get_h() - box_r * 2;
262 draw_top_background(get_top_level(), 0, 0, get_w(), get_h());
263 draw_vframe(mwindow->theme->channel_bg_data, 0, 0);
270 set_color(mwindow->theme->channel_position_color);
271 for(int i = 0; i < thread->new_settings->session->audio_channels; i++)
273 //printf("SetChannelsCanvas::draw %d\n", thread->new_settings->session->achannel_positions[i]);
274 get_dimensions(thread->new_settings->session->achannel_positions[i], x, y, w, h);
275 double rotate_angle = thread->new_settings->session->achannel_positions[i];
276 rotate_angle = -rotate_angle;
277 while(rotate_angle < 0) rotate_angle += 360;
278 rotater->rotate(temp_picon,
279 mwindow->theme->channel_position_data,
283 BC_Pixmap temp_pixmap(this,
287 draw_pixmap(&temp_pixmap, x, y);
288 sprintf(string, "%d", i + 1);
289 draw_text(x + 2, y + box_r * 2 - 2, string);
294 sprintf(string, _("%d degrees"), angle);
295 draw_text(this->get_w() / 2 - 40, this->get_h() / 2, string);
302 int SetChannelsCanvas::get_dimensions(int channel_position,
308 int real_w = this->get_w() - box_r * 2 - 50;
309 int real_h = this->get_h() - box_r * 2 - 50;
310 float corrected_position = channel_position;
311 if(corrected_position < 0) corrected_position += 360;
312 Units::polar_to_xy((float)corrected_position, real_w / 2, x, y);
313 x += real_w / 2 + 25;
314 y += real_h / 2 + 25;
320 int SetChannelsCanvas::button_press_event()
322 if(!cursor_inside()) return 0;
323 // get active channel
325 i < thread->new_settings->session->audio_channels;
329 get_dimensions(thread->new_settings->session->achannel_positions[i],
334 if(get_cursor_x() > x && get_cursor_y() > y &&
335 get_cursor_x() < x + w && get_cursor_y() < y + h)
338 degree_offset = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
340 if(degree_offset >= 360) degree_offset -= 360;
341 degree_offset -= thread->new_settings->session->achannel_positions[i];
342 draw(thread->new_settings->session->achannel_positions[i]);
349 int SetChannelsCanvas::button_release_event()
351 if(active_channel >= 0)
360 int SetChannelsCanvas::cursor_motion_event()
362 if(active_channel >= 0)
364 // get degrees of new channel
366 new_d = (int)Units::xy_to_polar(get_cursor_x() - this->get_w() / 2, get_cursor_y() - this->get_h() / 2);
368 if(new_d >= 360) new_d -= 360;
369 new_d -= degree_offset;
370 if(new_d < 0) new_d += 360;
371 if(thread->new_settings->session->achannel_positions[active_channel] != new_d)
373 thread->new_settings->session->achannel_positions[active_channel] = new_d;
374 draw(thread->new_settings->session->achannel_positions[active_channel]);