001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-2-002/audio/src/java/org/sakaiproject/tool/assessment/audio/AudioRecorderParams.java $
003: * $Id: AudioRecorderParams.java 9270 2006-05-10 21:38:40Z daisyf@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.audio;
021:
022: import java.io.Serializable;
023: import java.applet.Applet;
024:
025: /**
026: *
027: * <p> By default, we turn more things on than we would from an applet
028: we support runnning as an application, too
029: </p>
030: * <p>Description: </p>
031: * <p>Sakai Project Copyright (c) 2005</p>
032: * <p> </p>
033: * @author Ed Smiley <esmiley@stanford.edu>
034: *
035: */
036: public class AudioRecorderParams implements Serializable {
037: private boolean enablePlay = true;
038: private boolean enableRecord = true;
039: private boolean enablePause = true;
040: private boolean enableLoad = false;
041: private boolean saveAu = true;
042: private boolean saveWave = true;
043: private boolean saveAiff = true;
044: private boolean saveToFile = true;
045: private boolean saveToUrl = false;
046: private String fileName = "audio";
047: private String url = "";
048: private String compression = "linear";
049: private int frequency = 8000;
050: private int bits = 8;
051: private boolean signed = true;
052: private boolean bigendian = true;
053: private boolean stereo = false;
054: private int maxSeconds = 60;
055: private int attemptsAllowed = 5;
056: private String imageUrl = "";
057: private String agentId = "";
058: private String localeLanguage = "";
059: private String localeCountry = "";
060:
061: // -1 indicate that attemptsRemaining is not set, it should be set when question is loaded the 1st time.
062: private int attemptsRemaining = -1;
063: private int currentRecordingLength = 0;
064:
065: /**
066: * compression algorithms
067: * btw using "u" for the greek letter "mu"
068: * perhaps we should be calling this "mu-law" and showing that letter in UI.
069: */
070: public static final String compressionAllowed[] = { "ulaw", "alaw",
071: "linear", };
072:
073: /**
074: * sampling rates
075: */
076: public static final int frequenciesAllowed[] = { 8000, 11025,
077: 16000, 22050, 44100, };
078:
079: /**
080: * 8 or 16 bit
081: */
082: public static int bitsAllowed[] = { 8, 16, };
083:
084: /**
085: * Support runnning as an application. We turn off url and trn off save to
086: * url. Thsi has to be explicitly turned on.
087: *
088: */
089: public AudioRecorderParams() {
090: // keep all defaults
091: }
092:
093: /**
094: *
095: * <p>From an applet we set all values that are specified in existing applet
096: * parameters, the names and properties correspond.
097: * </p>
098: * @param applet the applet using these settings
099: */
100: public AudioRecorderParams(Applet applet) {
101: // set values from applet parameters
102: String s = applet.getParameter("enablePlay");
103: if ("true".equalsIgnoreCase(s)) {
104: enablePlay = true;
105: } else if ("false".equalsIgnoreCase(s)) {
106: enablePlay = false;
107: }
108:
109: s = applet.getParameter("enableRecord");
110: if ("true".equalsIgnoreCase(s)) {
111: enableRecord = true;
112: } else if ("false".equalsIgnoreCase(s)) {
113: enableRecord = false;
114: }
115:
116: s = applet.getParameter("enablePause");
117: if ("true".equalsIgnoreCase(s)) {
118: enablePause = true;
119: } else if ("false".equalsIgnoreCase(s)) {
120: enablePause = false;
121: }
122:
123: s = applet.getParameter("enableLoad");
124: if ("true".equalsIgnoreCase(s)) {
125: enableLoad = true;
126: } else if ("false".equalsIgnoreCase(s)) {
127: enableLoad = false;
128: }
129:
130: s = applet.getParameter("saveAu");
131: if ("true".equalsIgnoreCase(s)) {
132: saveAu = true;
133: } else if ("false".equalsIgnoreCase(s)) {
134: saveAu = false;
135: }
136:
137: s = applet.getParameter("saveWave");
138: if ("true".equalsIgnoreCase(s)) {
139: saveWave = true;
140: } else if ("false".equalsIgnoreCase(s)) {
141: saveWave = false;
142: }
143:
144: s = applet.getParameter("saveAiff");
145: if ("true".equalsIgnoreCase(s)) {
146: saveAiff = true;
147: } else if ("false".equalsIgnoreCase(s)) {
148: saveAiff = false;
149: }
150:
151: s = applet.getParameter("saveToFile");
152: if ("true".equalsIgnoreCase(s)) {
153: saveToFile = true;
154: } else if ("false".equalsIgnoreCase(s)) {
155: saveToFile = false;
156: }
157:
158: s = applet.getParameter("saveToUrl");
159: if ("true".equalsIgnoreCase(s)) {
160: saveToUrl = true;
161: } else if ("false".equalsIgnoreCase(s)) {
162: saveToUrl = false;
163: }
164:
165: s = applet.getParameter("fileName");
166: if (s != null) {
167: fileName = s;
168: }
169: s = applet.getParameter("url");
170: if (s != null) {
171: url = s;
172: }
173:
174: s = applet.getParameter("compression");
175: if (s != null) {
176: for (int i = 0; i < this .compressionAllowed.length; i++) {
177: if (compressionAllowed[i].equalsIgnoreCase(s)) {
178: compression = compressionAllowed[i];
179: }
180: }
181: }
182:
183: s = applet.getParameter("frequency");
184: if (s != null) {
185: int f = 0;
186: try {
187: f = Integer.parseInt(s);
188: } catch (NumberFormatException ex) {
189: ex.printStackTrace();
190: }
191:
192: for (int i = 0; i < this .frequenciesAllowed.length; i++) {
193: if (frequenciesAllowed[i] == f) {
194: frequency = f;
195: }
196: }
197: }
198:
199: s = applet.getParameter("bits");
200: if (s != null) {
201: int b = 0;
202: try {
203: b = Integer.parseInt(s);
204: } catch (NumberFormatException ex) {
205: ex.printStackTrace();
206: }
207:
208: for (int i = 0; i < this .bitsAllowed.length; i++) {
209: if (bitsAllowed[i] == b) {
210: bits = b;
211: }
212: }
213: }
214:
215: s = applet.getParameter("signed");
216: if ("true".equalsIgnoreCase(s)) {
217: signed = true;
218: } else if ("false".equalsIgnoreCase(s)) {
219: signed = false;
220: }
221:
222: s = applet.getParameter("bigendian");
223:
224: if ("true".equalsIgnoreCase(s)) {
225: bigendian = true;
226: } else if ("false".equalsIgnoreCase(s)) {
227: bigendian = false;
228: }
229:
230: s = applet.getParameter("stereo");
231: if ("true".equalsIgnoreCase(s)) {
232: stereo = true;
233: } else if ("false".equalsIgnoreCase(s)) {
234: stereo = false;
235: }
236:
237: s = applet.getParameter("maxSeconds");
238: if (s != null) {
239: try {
240: maxSeconds = Integer.parseInt(s);
241: } catch (NumberFormatException ex) {
242: ex.printStackTrace();
243: }
244: }
245: s = applet.getParameter("attemptsAllowed");
246: if (s != null) {
247: try {
248: attemptsAllowed = Integer.parseInt(s);
249: } catch (NumberFormatException ex1) {
250: ex1.printStackTrace();
251: }
252: }
253: s = applet.getParameter("attemptsRemaining");
254: if (s != null && !("").equals(s)) {
255: try {
256: attemptsRemaining = Integer.parseInt(s);
257: } catch (NumberFormatException ex1) {
258: ex1.printStackTrace();
259: }
260: }
261: s = applet.getParameter("currentRecordingLength");
262: if (s != null) {
263: try {
264: currentRecordingLength = Integer.parseInt(s);
265: } catch (NumberFormatException ex1) {
266: ex1.printStackTrace();
267: }
268: }
269:
270: s = applet.getParameter("imageUrl");
271: if (s != null) {
272: imageUrl = s;
273: }
274:
275: s = applet.getParameter("agentId");
276: if (s != null) {
277: agentId = s;
278: }
279:
280: s = applet.getParameter("localeLanguage");
281:
282: if (s != null) {
283: localeLanguage = s;
284: AudioUtil.getInstance().setLocaleLanguage(s);
285: }
286:
287: s = applet.getParameter("localeCountry");
288:
289: if (s != null) {
290: localeCountry = s;
291: AudioUtil.getInstance().setLocaleCountry(s);
292: }
293:
294: }
295:
296: public boolean isBigendian() {
297: return bigendian;
298: }
299:
300: public int getBits() {
301: return bits;
302: }
303:
304: public String getCompression() {
305: return compression;
306: }
307:
308: public boolean isEnableLoad() {
309: return enableLoad;
310: }
311:
312: public boolean isEnablePause() {
313: return enablePause;
314: }
315:
316: public boolean isEnablePlay() {
317: return enablePlay;
318: }
319:
320: public boolean isEnableRecord() {
321: return enableRecord;
322: }
323:
324: public String getFileName() {
325: return fileName;
326: }
327:
328: public int getFrequency() {
329: return frequency;
330: }
331:
332: public int getMaxSeconds() {
333: return maxSeconds;
334: }
335:
336: public int getCurrentRecordingLength() {
337: return currentRecordingLength;
338: }
339:
340: public int getAttemptsAllowed() {
341: return attemptsAllowed;
342: }
343:
344: public int getAttemptsRemaining() {
345: return attemptsRemaining;
346: }
347:
348: public boolean isSaveAiff() {
349: return saveAiff;
350: }
351:
352: public boolean isSaveAu() {
353: return saveAu;
354: }
355:
356: public boolean isSaveToFile() {
357: return saveToFile;
358: }
359:
360: public boolean isSaveToUrl() {
361: return saveToUrl;
362: }
363:
364: public boolean isSaveWave() {
365: return saveWave;
366: }
367:
368: public boolean isSigned() {
369: return signed;
370: }
371:
372: public boolean isStereo() {
373: return stereo;
374: }
375:
376: public String getUrl() {
377: return url;
378: }
379:
380: public void setUrl(String url) {
381: this .url = url;
382: }
383:
384: public void setStereo(boolean stereo) {
385: this .stereo = stereo;
386: }
387:
388: public void setSigned(boolean signed) {
389: this .signed = signed;
390: }
391:
392: public void setSaveWave(boolean saveWave) {
393: this .saveWave = saveWave;
394: }
395:
396: public void setSaveToUrl(boolean saveToUrl) {
397: this .saveToUrl = saveToUrl;
398: }
399:
400: public void setSaveToFile(boolean saveToFile) {
401: this .saveToFile = saveToFile;
402: }
403:
404: public void setSaveAu(boolean saveAu) {
405: this .saveAu = saveAu;
406: }
407:
408: public void setSaveAiff(boolean saveAiff) {
409: this .saveAiff = saveAiff;
410: }
411:
412: public void setAttemptsAllowed(int attemptsAllowed) {
413: this .attemptsAllowed = attemptsAllowed;
414: }
415:
416: public void setAttemptsRemaining(int attemptsRemaining) {
417: this .attemptsRemaining = attemptsRemaining;
418: }
419:
420: public void setMaxSeconds(int maxSeconds) {
421: this .maxSeconds = maxSeconds;
422: }
423:
424: public void setCurrentRecordingLength(int currentRecordingLength) {
425: this .currentRecordingLength = currentRecordingLength;
426: }
427:
428: public void setFrequency(int frequency) {
429: this .frequency = frequency;
430: }
431:
432: public void setFileName(String fileName) {
433: this .fileName = fileName;
434: }
435:
436: public void setEnableRecord(boolean enableRecord) {
437: this .enableRecord = enableRecord;
438: }
439:
440: public void setEnablePlay(boolean enablePlay) {
441: this .enablePlay = enablePlay;
442: }
443:
444: public void setEnablePause(boolean enablePause) {
445: this .enablePause = enablePause;
446: }
447:
448: public void setEnableLoad(boolean enableLoad) {
449: this .enableLoad = enableLoad;
450: }
451:
452: public void setCompression(String compression) {
453: this .compression = compression;
454: }
455:
456: public void setBits(int bits) {
457: this .bits = bits;
458: }
459:
460: public void setBigendian(boolean bigendian) {
461: this .bigendian = bigendian;
462: }
463:
464: public String getImageUrl() {
465: return imageUrl;
466: }
467:
468: public void setImageUrl(String imageUrl) {
469: this .imageUrl = imageUrl;
470: }
471:
472: public String getAgentId() {
473: return agentId;
474: }
475:
476: public void setAgentId(String agentId) {
477: this .agentId = agentId;
478: }
479:
480: public String getLocaleLanguage() {
481: return localeLanguage;
482: }
483:
484: public void setLocaleLanguage(String localeLanguage) {
485: this .localeLanguage = localeLanguage;
486: }
487:
488: public String getLocaleCountry() {
489: return localeCountry;
490: }
491:
492: public void setLocaleCountry(String localeCountry) {
493: this.localeCountry = localeCountry;
494: }
495:
496: }
|