aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llaudiostatus.cpp
blob: f24d939b9ed4a46a1aa01c94630084a79210e12d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/** 
 * @file llaudiostatus.cpp
 * @brief Audio channel allocation information
 *
 * Copyright (c) 2001-2007, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlife.com/developers/opensource/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlife.com/developers/opensource/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 */

#include "llviewerprecompiledheaders.h"

#include "llaudiostatus.h"

#include "linked_lists.h"
#include "llmath.h"		// clampf()
#include "llgl.h"
#include "llview.h"
#include "llfontgl.h"
#include "llcircuit.h"
#include "message.h"
#include "sound_ids.h"
#include "audioengine.h"

#include "llui.h"
#include "llagent.h"
#include "llviewercontrol.h"
#include "viewer.h"

#include "llglheaders.h"

//
// Imported globals
//
extern LLMessageSystem* gMessageSystem;
extern LLAudioEngine*   gAudiop;

//
// Constants
//


LLAudiostatus::LLAudiostatus(const std::string& name, const LLRect& rect)
		:	LLView(name, rect, FALSE)
{
	mPage = 0;
}

//
// Functions
//

EWidgetType LLAudiostatus::getWidgetType() const
{
	return WIDGET_TYPE_AUDIO_STATUS;
}

LLString LLAudiostatus::getWidgetTag() const
{
	return LL_AUDIOSTATUS_TAG;
}

const F32 AUDIOSTATUS_SIZE = 64;

void LLAudiostatus::draw()
{
	/*
	mPage = gSavedSettings.getS32("AudioInfoPage");

	if (!getVisible() || !mPage)
	{
		return;
	}
	
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	// We're going to be drawing flat shaded rectangles
	{
		LLGLSNoTexture gls_ui_no_texture;

		// Draw background black rectangle
		glColor4f(0.f, 0.f, 0.f, 0.3f);
		gl_rect_2d(0, 0, 325, -340);   // -y is down (don't know why)
	}
		
	glPopMatrix();
	glPushMatrix();

    S32 channel;
	char out_str[64];
	LLColor4 color; 

	if (gAudiop)
	{
		for (channel = 0; channel < MAX_BUFFERS; channel++)
		{
			if (gAudiop->getFlags(channel) & LL_SOUND_FLAG_LOOP)
			{
				color.setVec(0.5f,0.5f,1.f,1.f);
			}
			else
			{
				color.setVec(1.f,1.f,1.f,1.f);
			}

			sprintf(out_str,"%d:",channel);

			U8 render_style = LLFontGL::NORMAL;

			if (gAudiop->getFlags(channel) & LL_SOUND_FLAG_SYNC_MASTER)
			{
				render_style |= LLFontGL::BOLD;
			}

			if (gAudiop->getFlags(channel) & LL_SOUND_FLAG_SYNC_SLAVE)
			{
				render_style |= LLFontGL::ITALIC;
			}

			if (gAudiop->getFlags(channel) & LL_SOUND_FLAG_SYNC_PENDING)
			{
				render_style |= LLFontGL::UNDERLINE;
			}

			LLFontGL::sMonospace->render(out_str, 0, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP, render_style, S32_MAX, S32_MAX, NULL);

//			render_style = LLFontGL::NORMAL;
//			if (gAudiop->mCurrentSyncMaster == channel)
//			{
//				render_style |= LLFontGL::BOLD;
//			}

			if (!gAudiop->mBufferInUse[channel])
			{
				color.setVec(0.5f,0.5f,0.5f,1.f);
			}
			else if (gAudiop->isPlaying(channel))
			{
				color.setVec(0.f,1.f,0.f,1.f);
			}
			else
			{
				color.setVec(1.f,0.f,0.f,1.f);
			}

			if (gAudiop->mWindBufferID ==channel)
			{
				strcpy(out_str,"wind DMO");
			}
			else if (gAudiop->mWaterBufferID ==channel)
			{
				strcpy(out_str,"water DMO");
			}
			else if (gAudiop->mGUID[channel] == SND_CHIRP)
			{
				strcpy(out_str,"chirp");				
			}
			else if (gAudiop->mGUID[channel] == SND_SHOT)
			{
				strcpy(out_str,"shot");				
			}
			else if (gAudiop->mGUID[channel] == SND_MORTAR)
			{
				strcpy(out_str,"mortar");				
			}
			else if (gAudiop->mGUID[channel] == SND_HIT)
			{
				strcpy(out_str,"hit");				
			}
			else if (gAudiop->mGUID[channel] == SND_EXPLOSION)
			{
				strcpy(out_str,"explosion");				
			}
			else if (gAudiop->mGUID[channel] == SND_BOING)
			{
				strcpy(out_str,"boing");				
			}
			else if (gAudiop->mGUID[channel] == SND_MUNCH)
			{
				strcpy(out_str,"munch");				
			}
			else if (gAudiop->mGUID[channel] == SND_PUNCH)
			{
				strcpy(out_str,"punch");				
			}
			else if (gAudiop->mGUID[channel] == SND_SPLASH)
			{
				strcpy(out_str,"splash");				
			}
			else if (gAudiop->mGUID[channel] == SND_CLICK)
			{
				strcpy(out_str,"click");				
			}
			else if (gAudiop->mGUID[channel] == SND_ARROW_SHOT)
			{
				strcpy(out_str,"arrow");				
			}
			else if (gAudiop->mGUID[channel] == SND_ARROW_THUD)
			{
				strcpy(out_str,"arrow thud");				
			}
			else if (gAudiop->mGUID[channel] == SND_SILENCE)
			{
				strcpy(out_str,"silence");				
			}
			else if (gAudiop->mGUID[channel] == SND_WELCOME)
			{
				strcpy(out_str,"welcome");				
			}
			else if (gAudiop->mGUID[channel] == SND_WELCOME)
			{
				strcpy(out_str,"welcome");				
			}
			else if (gAudiop->mGUID[channel] == SND_READY_FOR_BATTLE)
			{
				strcpy(out_str,"ready for battle");				
			}
			else if (gAudiop->mGUID[channel] == SND_SQUISH)
			{
				strcpy(out_str,"squish");				
			}
			else if (gAudiop->mGUID[channel] == SND_FOOTSTEPS)
			{
				strcpy(out_str,"footsteps");				
			}
			else if (gAudiop->mGUID[channel] == SND_BALL_COLLISION)
			{
				strcpy(out_str,"ball collision");				
			}
			else
			{
				gAudiop->mGUID[channel].toString(out_str);
			}

			out_str[8] = 0;
			LLFontGL::sMonospace->render(out_str, 23, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP, render_style, S32_MAX, S32_MAX, NULL);

			if (mPage == 1)
			{
				LLVector3 pos = gAudiop->getSourcePos(channel);
				sprintf(out_str,"%6.2f %6.2f %6.2f",pos.mV[VX],pos.mV[VY],pos.mV[VZ]);
				LLFontGL::sMonospace->render(out_str, 103, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
				
				F32 gain = gAudiop->getSourceGain_dB(channel);
				sprintf(out_str,"%7.2f",gain);
				LLFontGL::sMonospace->render(out_str, 260, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
				
				sprintf(out_str,"%X", gAudiop->mPriority[channel] >> 28);
				LLFontGL::sMonospace->render(out_str, 315, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
			}
			else if (mPage == 4)
			{
				F32 indicator_width = 240;
				
				glPushMatrix();
				// We're going to be drawing flat shaded rectangles
				LLGLSNoTexture gls_no_texture;				
				// Draw background black rectangle
				glColor4f(0.f, 0.f, 0.f, 1.0f);
				
				F32 length = gAudiop->getSourceLength(channel);
				length = length/(44100.0*2.0);  // length in seconds
				length = length/10.f;           // rescale per maximum length

				gl_rect_2d(80, (-channel*10)-1, 80 + llfloor((F32)(indicator_width * length)), (-channel*10)-9);   // -y is down (don't know why)
				
				F32 current_pointer = gAudiop->getSourceCurrentSample(channel);
				current_pointer = current_pointer/(44100.0*2.0);  // length in seconds
				current_pointer = current_pointer/10.f;           // rescale per maximum length

				if (!gAudiop->mBufferInUse[channel])
				{
					glColor4f(0.5f,0.5f,0.5f,1.f);
				}
				else if (gAudiop->isPlaying(channel))
				{
					glColor4f(0.f,1.f,0.f,1.f);
				}
				else
				{
					glColor4f(1.f,0.f,0.f,1.f);
				}

				gl_rect_2d(80, (-channel*10)-1, 80 + llfloor((F32)(indicator_width * current_pointer)), (-channel*10)-9);   // -y is down (don't know why)
				
				glPopMatrix();
				{
				LLGLSUIDefault gls_ui;

				color.setVec(1.f,1.f,1.f,1.f);

				sprintf(out_str,"%6.3f",length*10.f);
				LLFontGL::sMonospace->render(out_str, 200, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP, render_style, S32_MAX, S32_MAX, NULL);

				if (!(gAudiop->mVO_ID[channel].isNull()))
				{
					gAudiop->mVO_ID[channel].toString(out_str);
					out_str[8] = 0;
					LLFontGL::sMonospace->render(out_str, 260, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP, render_style, S32_MAX, S32_MAX, NULL);
				}
				if (gAudiop->mQueuedTrigger[channel])
				{
					gAudiop->mQueuedTrigger[channel]->mID.toString(out_str);
					out_str[8] = 0;
					LLFontGL::sMonospace->render(out_str, 320, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP, render_style, S32_MAX, S32_MAX, NULL);
				}
				}
			}
			else 
			{
				S32 volume;
				S32 freq;
				S32 inside;
				S32 outside;
				LLVector3 orient;
				S32 out_volume;
				F32 min_dist;
				F32 max_dist;
				
				gAudiop->get3DParams(channel, &volume, &freq, &inside, &outside, &orient, &out_volume, &min_dist, &max_dist);

				if (mPage == 2)
				{
					sprintf(out_str,"%4.2f %4.2f %4.2f",orient.mV[VX],orient.mV[VY],orient.mV[VZ]);
					LLFontGL::sMonospace->render(out_str, 103, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
					
					sprintf(out_str,"%4d %4d",inside, outside);
					LLFontGL::sMonospace->render(out_str, 210, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
					
					sprintf(out_str,"%6d", out_volume);
					LLFontGL::sMonospace->render(out_str, 280, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
				}
				else // mPage == 3
				{
					F32 distance = 0.f;
					if (gAudiop->isSourceAmbient(channel))
					{
						distance = dist_vec(gAudiop->getSourcePos(channel),LLVector3::zero);
					}
					else
					{
						distance = dist_vec(gAudiop->getSourcePos(channel),gAudiop->getListenerPos());
					}

					sprintf(out_str,"%6.2f   %6.2f %6.2f",distance, min_dist, max_dist);
					LLFontGL::sMonospace->render(out_str, 103, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
					
					F32 gain = gAudiop->getSourceGain_dB(channel);
					sprintf(out_str,"%7.2f",gain);
					LLFontGL::sMonospace->render(out_str, 280, -channel*10, color, LLFontGL::LEFT, LLFontGL::TOP);
  				}
			}
		}
		LLFontGL::sMonospace->render("Listener", 23, -(channel*10+5), color, LLFontGL::LEFT, LLFontGL::TOP);


		if (mPage == 1)
		{
			LLVector3 lpos = gAudiop->getListenerPos();
			sprintf(out_str,"%6.2f %6.2f %6.2f",lpos.mV[VX],lpos.mV[VY],lpos.mV[VZ]);
			LLFontGL::sMonospace->render(out_str, 103, -(channel*10+5), color, LLFontGL::LEFT, LLFontGL::TOP);

			F32 gain = gAudiop->getMasterGain_dB();
			sprintf(out_str,"%7.2f",gain);
			LLFontGL::sMonospace->render(out_str, 280, -(channel*10+5), color, LLFontGL::LEFT, LLFontGL::TOP);
		}
		else if (mPage == 2)
		{
			sprintf(out_str,"cone orient    inner outer gain");
			LLFontGL::sMonospace->render(out_str, 103, -(channel*10+5), color, LLFontGL::LEFT, LLFontGL::TOP);
		}
		else if (mPage == 3)
		{
			sprintf(out_str,"distance    min    max      gain");
			LLFontGL::sMonospace->render(out_str, 103, -(channel*10+5), color, LLFontGL::LEFT, LLFontGL::TOP);			
		}
	}
	else
	{
		LLFontGL::sMonospace->render("No Audio Engine available", 50 , -175, 
			LLColor4(1.f,0.1f,0.1f,1.f),
			LLFontGL::LEFT, LLFontGL::TOP);		
	}
	
	glPopMatrix();
	*/
}