2 Copyright 2006 Chris Tallon, Marten Richter
4 This file is part of VOMP.
6 VOMP 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.
11 VOMP 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.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vaudioselector.h"
23 VAudioSelector::VAudioSelector(void* tparent,bool* availableMpegAudioChannels,
24 bool* availableAc3AudioChannels,
25 int currentAudioChannel, RecInfo* recInfo)
27 Log::getInstance()->log("VAS", Log::DEBUG, "%i", currentAudioChannel);
33 // setTitleText(tr("Audio"));
35 // setTitleBarColour(Colour::TITLEBARBACKGROUND);
37 sl.setSurface(surface);
38 sl.setSurfaceOffset(40, 30);
39 sl.setDimensions(area.w - 45, area.h - 30);
41 // Load data from availableAudioChannels, currentAudioChannel and recInfo
45 for (i = 0; i < PES_AUDIO_MAXCHANNELS; i++)
47 if (availableMpegAudioChannels[i])
49 AudioChannel* ac = new AudioChannel();
52 ac->pestype = PES_AUDIO_START + i;
56 if (availableAc3AudioChannels != NULL)
58 for (i = 0; i < PES_AUDIO_AC3_MAXCHANNELS; i++)
60 if (availableAc3AudioChannels[i])
62 AudioChannel* ac = new AudioChannel();
65 ac->pestype = PES_AUDIO_AC3_START + i;
71 unsigned char numchan_recinfo = recInfo->numComponents;
72 unsigned char numchan_siz = acl.size();
73 int mp_audcounter = 0;
77 for (i = 0; i < numchan_siz; i++)
79 AudioChannel* ac = acl[i];
94 for (i = 0; i < numchan_recinfo; i++)
96 if (recInfo->streams[i] != 2) continue; //not an audio component
97 type = recInfo->types[i];
98 lang = recInfo->languages[i];
99 description = recInfo->descriptions[i];
100 AudioChannel* ac = NULL;
105 case 1: //mpaudio mono
106 case 3: //mpaudio stereo
107 if (mp_audcounter < numchan_siz) ac = acl[mp_audcounter];
111 if (ac3_counter + ac3_offset < numchan_siz) ac = acl[ac3_counter + ac3_offset];
118 if (ac->type == type_int)
120 if (description && (strlen(description) > 0))
122 ac->name = new char[strlen(description)+1];
123 strcpy(ac->name, description);
125 else if (lang && (strlen(lang) > 0))
127 ac->name = new char[strlen(lang)+1];
128 strcpy(ac->name, lang);
146 char tempString[300];
147 int audioChannelListSize = acl.size();
149 if (audioChannelListSize)
151 for(i = 0; i < audioChannelListSize; i++)
153 AudioChannel* ac = acl[i];
157 sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
163 SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START));
165 else if (ac->type==1)
167 SNPRINTF(tempString, 299, "ac3 %lu", (ULONG)(ac->pestype - PES_AUDIO_AC3_START));
171 SNPRINTF(tempString, 299, "unknown");
173 sl.addOption(tempString, (ULONG)ac, (ac->pestype == currentAudioChannel));
179 sl.addOption(tr("No audio channel data available"), 0, 1);
183 VAudioSelector::~VAudioSelector()
185 int audioChannelListSize = acl.size();
186 for(int i = 0; i < audioChannelListSize; i++)
194 Message* m = new Message();
197 m->message = Message::CHILD_CLOSE;
198 Command::getInstance()->postMessageNoLock(m);
201 void VAudioSelector::draw()
204 rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
205 drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
207 sl.setBackgroundColour(backgroundColour);
211 int VAudioSelector::handleCommand(int command)
227 ViewMan::getInstance()->updateView(this);
229 Message* m = new Message();
232 m->message = Message::AUDIO_CHANGE_CHANNEL;
233 m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype;
234 Command::getInstance()->postMessageNoLock(m);
238 case Remote::DF_DOWN:
244 ViewMan::getInstance()->updateView(this);
246 Message* m = new Message();
249 m->message = Message::AUDIO_CHANGE_CHANNEL;
250 m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype;
251 Command::getInstance()->postMessageNoLock(m);
260 void VAudioSelector::processMessage(Message* m)
262 if (m->message == Message::MOUSE_MOVE)
264 if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
267 ViewMan::getInstance()->updateView(this);
270 else if (m->message == Message::MOUSE_LBDOWN)
272 if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
274 ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
277 { //check if press is outside this view! then simulate cancel
278 int x=(m->parameter>>16)-getScreenX();
279 int y=(m->parameter&0xFFFF)-getScreenY();
280 if (x<0 || y <0 || x>getWidth() || y>getHeight())
282 ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press