]> git.vomp.tv Git - vompclient.git/blob - vaudioselector.cc
Translation updates
[vompclient.git] / vaudioselector.cc
1 /*
2     Copyright 2006 Chris Tallon, Marten Richter
3
4     This file is part of VOMP.
5
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.
10
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.
15
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
19 */
20
21 #include "vaudioselector.h"
22
23 VAudioSelector::VAudioSelector(void* tparent, bool* availableAudioChannels, int currentAudioChannel, RecInfo* recInfo)
24 {
25   Log::getInstance()->log("VAS", Log::DEBUG, "%i", currentAudioChannel);
26
27   parent = tparent;
28
29   create(200, 120);
30
31 //  setTitleText(tr("Audio"));
32 //  setTitleBarOn(1);
33 //  setTitleBarColour(Colour::TITLEBARBACKGROUND);
34
35   sl.setSurface(surface);
36   sl.setSurfaceOffset(40, 30);
37   sl.setDimensions(area.w - 45, area.h - 30);
38
39   // Load data from availableAudioChannels, currentAudioChannel and recInfo
40
41   int i;
42
43   for (i = 0; i < PES_AUDIO_MAXCHANNELS; i++)
44   {
45     if (availableAudioChannels[i])
46     {
47       AudioChannel* ac = new AudioChannel();
48       ac->type = 0;
49       ac->name = NULL;
50       ac->pestype = PES_AUDIO_START + i;
51       acl.push_back(ac);
52     }
53   }
54
55   unsigned char numchan_recinfo = recInfo->numComponents;
56   unsigned char numchan_siz = acl.size();
57   int mp_audcounter = 0;
58   int ac3_counter = 0;
59   int ac3_offset = 0;
60
61   for (i = 0; i < numchan_siz; i++)
62   {
63     AudioChannel* ac = acl[i];
64     if (ac)
65     {
66       if (ac->type==0)
67       {
68         ac3_offset++;
69       }
70     }
71   }
72
73   unsigned char type;
74   char* lang;
75   char* description;
76   int type_int;
77
78   for (i = 0; i < numchan_recinfo; i++)
79   {
80     if (recInfo->streams[i] != 2) continue; //not an audio component
81     type = recInfo->types[i];
82     lang = recInfo->languages[i];
83     description = recInfo->descriptions[i];
84     AudioChannel* ac = NULL;
85     type_int = 0;
86
87     switch (type)
88     {
89       case 1: //mpaudio mono
90       case 3: //mpaudio stereo
91         if (mp_audcounter < numchan_siz) ac = acl[mp_audcounter];
92         type_int = 0;
93         break;
94       case 5: //ac3
95         if (ac3_counter + ac3_offset < numchan_siz) ac = acl[ac3_counter + ac3_offset];
96         type_int = 1;
97         break;
98     }
99
100     if (ac)
101     {
102       if (ac->type == type_int)
103       {
104         if (description && (strlen(description) > 0))
105         {
106           ac->name = new char[strlen(description)+1];
107           strcpy(ac->name, description);
108         }
109         else if (lang && (strlen(lang) > 0))
110         {
111           ac->name = new char[strlen(lang)+1];
112           strcpy(ac->name, lang);
113         }
114       }
115     }
116
117     switch (type_int)
118     {
119       case 0: //mpaudio
120         mp_audcounter++;
121         break;
122       case 1: //ac3
123         ac3_counter++;
124         break;
125     }
126   }
127
128   // Now do display
129
130   char tempString[300];
131   int audioChannelListSize = acl.size();
132
133   if (audioChannelListSize)
134   {
135     for(i = 0; i < audioChannelListSize; i++)
136     {
137       AudioChannel* ac = acl[i];
138
139       if (ac->name)
140       {
141         sl.addOption(ac->name, (ULONG)ac, (ac->pestype == currentAudioChannel));
142       }
143       else
144       {
145         SNPRINTF(tempString, 299, "%lu", (ULONG)(ac->pestype - PES_AUDIO_START));
146         sl.addOption(tempString, (ULONG)ac, (ac->pestype == currentAudioChannel));
147       }
148     }
149   }
150   else
151   {
152     sl.addOption(tr("No audio channel data available"), 0, 1);
153   }
154 }
155
156 VAudioSelector::~VAudioSelector()
157 {
158   int audioChannelListSize = acl.size();
159   for(int i = 0; i < audioChannelListSize; i++)
160   {
161     delete acl[i];
162   }
163   acl.clear();
164
165   sl.clear();
166
167   Message* m = new Message();
168   m->from = this;
169   m->to = parent;
170   m->message = Message::CHILD_CLOSE;
171   Command::getInstance()->postMessageNoLock(m);
172 }
173
174 void VAudioSelector::draw()
175 {
176   View::draw();
177   rectangle(0, 0, area.w, 30, Colour::TITLEBARBACKGROUND);
178   drawText(tr("Audio"), 45, 5, Colour::LIGHTTEXT);
179
180   sl.setBackgroundColour(backgroundColour);
181   sl.draw();
182 }
183
184 int VAudioSelector::handleCommand(int command)
185 {
186   switch (command)
187   {
188     case Remote::BACK:
189     case Remote::OK:
190     case Remote::GREEN:
191     {
192       return 4;
193     }
194     case Remote::DF_UP:
195     case Remote::UP:
196     {
197       sl.up();
198       sl.draw();
199
200       ViewMan::getInstance()->updateView(this);
201
202       Message* m = new Message();
203       m->from = this;
204       m->to = parent;
205       m->message = Message::AUDIO_CHANGE_CHANNEL;
206       m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype;
207       Command::getInstance()->postMessageNoLock(m);
208
209       return 2;
210     }
211     case Remote::DF_DOWN:
212     case Remote::DOWN:
213     {
214       sl.down();
215       sl.draw();
216
217       ViewMan::getInstance()->updateView(this);
218
219       Message* m = new Message();
220       m->from = this;
221       m->to = parent;
222       m->message = Message::AUDIO_CHANGE_CHANNEL;
223       m->parameter = ((AudioChannel*)sl.getCurrentOptionData())->pestype;
224       Command::getInstance()->postMessageNoLock(m);
225
226       return 2;
227     }
228   }
229
230   return 0;
231 }
232
233 void VAudioSelector::processMessage(Message* m)
234 {
235   if (m->message == Message::MOUSE_MOVE)
236   {
237     if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
238     {
239       sl.draw();
240       ViewMan::getInstance()->updateView(this);
241     }
242   }
243   else if (m->message == Message::MOUSE_LBDOWN)
244   {
245     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
246     {
247       ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
248     }
249     else
250     { //check if press is outside this view! then simulate cancel
251       int x=(m->parameter>>16)-getScreenX();
252       int y=(m->parameter&0xFFFF)-getScreenY();
253       if (x<0 || y <0 || x>getWidth() || y>getHeight())
254       {
255         ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
256       }
257     }
258   }
259 }