2 * Advanced Firefogg support. Lets you control many aspects of video encoding.
6 "fogg-help-sticky" : "Help (click to stick)",
7 "fogg-cg-preset" : "Preset: <strong>$1<\/strong>",
8 "fogg-cg-quality" : "Basic quality and resolution control",
9 "fogg-cg-meta" : "Metadata for the clip",
10 "fogg-cg-range" : "Encoding range",
11 "fogg-cg-advVideo" : "Advanced video encoding controls",
12 "fogg-cg-advAudio" : "Advanced audio encoding controls",
13 "fogg-preset-custom" : "Custom settings",
14 "fogg-webvideo-desc" : "Web video Theora, Vorbis 400 kbit\/s and 400px maximum width",
15 "fogg-savebandwidth-desc" : "Low bandwidth Theora, Vorbis 164 kbit\/s and 200px maximum width",
16 "fogg-highquality-desc" : "High quality Theora, Vorbis 1080px maximum width",
17 "fogg-videoQuality-title" : "Video quality",
18 "fogg-videoQuality-help" : "Used to set the <i>visual quality<\/i> of the encoded video (not used if you set bitrate in advanced controls below).",
19 "fogg-starttime-title" : "Start second",
20 "fogg-starttime-help" : "Only encode from time in seconds",
21 "fogg-endtime-title" : "End second",
22 "fogg-endtime-help" : "Only encode to time in seconds",
23 "fogg-audioQuality-title" : "Audio quality",
24 "fogg-audioQuality-help" : "Used to set the <i>acoustic quality<\/i> of the encoded audio (not used if you set bitrate in advanced controls below).",
25 "fogg-videoCodec-title" : "Video codec",
26 "fogg-videoCodec-help" : "Used to select the clip video codec. Presently only Theora is supported. More about the <a target=\"_new\" href=\"http:\/\/en.wikipedia.org\/wiki\/Theora\">Theora codec<\/a>.",
27 "fogg-audioCodec-title" : "Audio codec",
28 "fogg-audioCodec-help" : "Used to set the clip audio codec. Presently only Vorbis is supported. More about the <a target=\"_new\" href=\"http:\/\/en.wikipedia.org\/wiki\/Vorbis\">Vorbis codec<\/a>",
29 "fogg-width-title" : "Video width",
30 "fogg-width-help" : "Resize to given width.",
31 "fogg-height-title" : "Video height",
32 "fogg-height-help" : "Resize to given height.",
33 "fogg-videoBitrate-title" : "Video bitrate",
34 "fogg-videoBitrate-help" : "Video bitrate sets the encoding bitrate for video in (kb\/s)",
35 "fogg-twopass-title" : "Two pass encoding",
36 "fogg-twopass-help" : "Two pass encoding enables more constant quality by making two passes over the video file",
37 "fogg-framerate-title" : "Frame rate",
38 "fogg-framerate-help" : "The video frame rate. More about <a target=\"_new\" href=\"http:\/\/en.wikipedia.org\/wiki\/Frame_rate\">frame rate<\/a>.",
39 "fogg-aspect-title" : "Aspect ratio",
40 "fogg-aspect-help" : "The video aspect ratio can be 4:3 or 16:9. More about <a target=\"_new\" href=\"http:\/\/en.wikipedia.org\/wiki\/Aspect_ratio_%28image%29\">aspect ratios<\/a>.",
41 "fogg-keyframeInterval-title" : "Key frame interval",
42 "fogg-keyframeInterval-help" : "The keyframe interval in frames. Note: Most codecs force keyframes if the difference between frames is greater than keyframe encode size. More about <a href=\"http:\/\/en.wikipedia.org\/wiki\/I-frame\">keyframes<\/a>.",
43 "fogg-denoise-title" : "Denoise filter",
44 "fogg-denoise-help" : "Denoise input video. More about <a href=\"http:\/\/en.wikipedia.org\/wiki\/Video_denoising\">denoise<\/a>.",
45 "fogg-novideo-title" : "No video",
46 "fogg-novideo-help" : "disable video in the output",
47 "fogg-audioBitrate-title" : "Audio bitrate",
48 "fogg-samplerate-title" : "Audio sampling rate",
49 "fogg-samplerate-help" : "set output sample rate (in Hz).",
50 "fogg-noaudio-title" : "No audio",
51 "fogg-noaudio-help" : "disable audio in the output",
52 "fogg-title-title" : "Title",
53 "fogg-title-help" : "A title for your clip",
54 "fogg-artist-title" : "Creator name",
55 "fogg-artist-help" : "The creator of this clip",
56 "fogg-date-title" : "Date",
57 "fogg-date-help" : "The date the footage was created or released",
58 "fogg-location-title" : "Location",
59 "fogg-location-help" : "The location of the footage",
60 "fogg-organization-title" : "Organization",
61 "fogg-organization-help" : "Name of organization (studio)",
62 "fogg-copyright-title" : "Copyright",
63 "fogg-copyright-help" : "The copyright of the clip",
64 "fogg-license-title" : "License",
65 "fogg-license-help" : "The license of the clip (preferably a Creative Commons URL).",
66 "fogg-contact-title" : "Contact",
67 "fogg-contact-help" : "Contact link"
70 var mvAdvFirefogg = function( iObj ) {
71 return this.init( iObj );
73 var default_mvAdvFirefogg_config = {
74 // Config groups to include
75 'config_groups': [ 'preset', 'range', 'quality', 'meta', 'advVideo', 'advAudio' ],
77 // If you want to load any custom presets must follow the mvAdvFirefogg.presetConf json outline below
80 // Any Firefog config properties that may need to be excluded from options
81 'exclude_settings': [],
83 // The control container
84 'target_control_container': false
87 mvAdvFirefogg.prototype = {
88 // The configuration group names
89 config_groups: [ 'preset', 'range', 'quality', 'meta', 'advVideo', 'advAudio' ],
91 // Default configuration for this class
92 default_local_settings: {
93 'default': 'webvideo',
95 'selectVal': ['webvideo'],
99 'descKey': 'fogg-preset-custom',
103 'desc': gM( 'fogg-webvideo-desc' ),
106 'videoBitrate' : 544,
108 'noUpscaling' : true,
112 'desc': gM( 'fogg-savebandwidth-desc' ),
115 'videoBitrate' : 164,
117 'samplerate' : 22050,
124 'desc': gM( 'fogg-highquality-desc' ),
129 'noUpscaling' : true,
135 // Customised configuration hashtable
138 // Core Firefogg default encoder configuration
139 // See encoder options here: http://www.firefogg.org/dev/index.html
140 default_encoder_config: {
141 // Base quality settings
144 'range' : { 'min': 0,'max': 10 },
158 'range' : { 'min': -1, 'max': 10 },
163 'default' : "theora",
164 'selectVal' : [ 'theora' ],
169 'default' : "vorbis",
170 'selectVal' : [ 'vorbis' ],
175 'range' : { 'min': 0, 'max': 1080 },
181 'range' : { 'min': 0, 'max' : 1080 },
187 // Advanced video control
189 'range' : { 'min' : 1, 'max' : 16778 },
191 'group' : "advVideo",
199 'selectVal' : [ '12', '16', { '24000:1001' : '23.97' }, '24', '25',
200 { '30000:1001' : '29.97' }, '30' ],
207 'selectVal' : [ '4:3', '16:9' ],
210 'keyframeInterval': {
212 'range' : { 'min': 0, 'max': 65536 },
213 'numberType': 'force keyframe every $1 frames',
226 // Advanced audio control
228 'range' : { 'min': 32, 'max': 500 },
229 'numberType': '$1 kbs',
234 'selectVal' : [ { '22050': '22 kHz' }, { '44100': '44 khz' }, { '48000': '48 khz' } ],
235 'formatSelect' : function( val ) {
236 return ( Math.round( val / 100 ) * 10 ) + ' Hz';
279 * Initialise this object
281 init: function( options ) {
282 // Set up a supported object:
283 for ( var key in options ) {
284 if ( typeof default_mvAdvFirefogg_config[key] != 'undefined' ) {
285 this[key] = options[key];
288 // Inherit the base mvFirefogg class:
289 var baseFirefogg = new mvFirefogg( options );
290 for ( var key in baseFirefogg ) {
291 if ( typeof this[key] != 'undefined' ) {
292 this[ 'basefogg_' + key ] = baseFirefogg[ key ];
294 this[ key ] = baseFirefogg[ key ];
299 setupForm: function() {
300 basefogg_setupForm();
301 this.createControls();
305 createControls: function() {
306 js_log( "adv createControls" );
308 // Load presets from the cookie
309 this.loadEncSettings();
311 // Add the base control buttons
312 this.basefogg_createControls();
314 // Build the config group output
316 $j.each( this.config_groups, function( inx, group_key ) {
318 '<h3><a href="#" class="gd_' + group_key + '" >' +
319 gM( 'fogg-cg-' + group_key ) + '</a></h3>' +
321 // Output this group's control options:
322 gdout += '<table width="' + ( $j( _this.selector ).width() - 60 ) + '" >' +
323 '<tr><td width="35%"></td><td width="65%"></td></tr>';
324 // If this is the preset group, output the preset control
325 if ( group_key == 'preset' ) {
326 gdout += _this.getPresetControlHtml();
328 // Output the encoder config controls
329 for ( var configKey in _this.default_encoder_config ) {
330 var confEntry = _this.default_encoder_config[ configKey ];
331 if( confEntry.group == group_key ) {
332 gdout += _this.getConfigControlHtml( configKey );
335 gdout += '</table></div></div>';
337 // Add the control container
338 if( !this.target_control_container ) {
339 this.target_control_container = this.selector + ' .control_container';
340 $j( this.selector ).append( '<p><div class="control_container"></div>' );
342 // Hide the container and add the output
343 $j( this.target_control_container ).hide();
344 $j( this.target_control_container ).html( gdout );
347 // Custom advanced target rewrites
348 getControlHtml: function( target ) {
350 case 'target_btn_select_file':
351 case 'target_btn_select_new_file':
352 case 'target_btn_save_local_file':
354 if ( target == 'target_btn_save_local_file' ) {
355 icon = 'ui-icon-video'
357 icon = 'ui-icon-folder-open';
359 var linkText = gM( target.replace( /^target_btn_/, 'fogg-' ) );
360 return '<a class="ui-state-default ui-corner-all ui-icon_link ' +
361 target + '" href="#"><span class="ui-icon ' + icon + '"/>' +
364 case 'target_btn_select_url':
365 return $j.btnHtml( gM( 'fogg-select_url' ), target, 'link' );
366 case 'target_use_latest_firefox':
367 case 'target_please_install':
368 case 'target_passthrough_mode':
369 var text = gM( target.replace( '/^target_', 'fogg-' ) );
372 'style="margin-top:1em;padding: 0pt 0.7em;" ' +
373 'class="ui-state-error ui-corner-all ' +
376 '<span style="float: left; margin-right: 0.3em;" ' +
377 'class="ui-icon ui-icon-alert"/>' +
381 case 'target_input_file_name':
382 var text = gM( 'fogg-input_file_name' );
383 return '<br><br><input style="" ' +
384 'class="text ui-widget-content ui-corner-all ' + target + '" ' +
385 'type="text" value="' + text + '" size="60" /> ';
387 js_log( 'call : basefogg_getTargetHtml' );
388 return this.basefogg_getTargetHtml( target );
392 getPresetControlHtml: function() {
395 js_log( 'getPresetControlHtml::' );
396 if ( typeof this.local_settings.presets != 'undefined' ) {
397 out += '<select class="_preset_select">';
398 $j.each( this.local_settings.presets, function( presetKey, preset ) {
399 var presetDesc = preset.descKey ? gM( preset.descKey ) : preset.desc;
400 var sel = ( _this.local_settings['default'] == presetKey ) ? ' selected' : '';
401 out += '<option value="' + presetKey + '" ' + sel + '>' + presetDesc + '</option>';
408 getConfigControlHtml : function( configKey ) {
409 var configEntry = this.default_encoder_config[configKey];
411 out += '<tr><td valign="top">' +
412 '<label for="_' + configKey + '">' +
413 gM( 'fogg-' + configKey + '-title' ) + ':' +
414 '<span title="' + gM( 'fogg-help-sticky' ) + '" ' +
415 'class="help_' + configKey + ' ui-icon ui-icon-info" style="float:left">' +
417 '</label></td><td valign="top">';
418 // Get the default value (or an empty string if there is no default)
420 var defaultValue = this.default_encoder_config[configKey]['default'];
421 if ( !defaultValue ) {
424 var type = configEntry.type; // shortcut
426 // Switch on the config type
432 var size = ( type == 'string' || type == 'date' ) ? '14' : '4';
434 'size="' + size + '" ' +
436 'class="_' + configKey + ' text ui-widget-content ui-corner-all" ' +
437 'value="' + defaultValue + '" >';
440 var checked_attr = ( defaultValue === true ) ? ' checked="true"' : '';
443 'class="_' + configKey + ' ui-widget-content ui-corner-all" ' +
447 var strMax = this.default_encoder_config[ configKey ].range.max + '';
448 maxDigits = strMax.length + 1;
451 'maxlength="' + maxDigits + '" ' +
452 'size="' + maxDigits + '" ' +
453 'class="_' + configKey + ' text ui-widget-content ui-corner-all" ' +
454 'style="display:inline;border:0; color:#f6931f; font-weight:bold;" ' +
455 'value="' + defaultValue + '" >' +
456 '<div class="slider_' + configKey + '"></div>';
459 out += '<select class="_' + configKey + '">' +
460 '<option value=""> </option>';
461 for ( var i in configEntry.selectVal ) {
462 var val = configEntry.selectVal[i];
463 if ( typeof val == 'string' ) {
464 var sel = ( configEntry.selectVal[i] == val ) ? ' selected' : '';
465 out += '<option value="' + val + '"'+sel+'>' + val + '</option>';
466 } else if ( typeof val == 'object' ) {
467 for ( var key in val ) {
470 var sel = ( configEntry.selectVal[i] == key ) ? ' selected' : '';
472 out += '<option value="' + key + '"' + sel + '>' + hr_val + '</option>';
478 // output the help row:
479 out += '<div class="helpRow_' + configKey + '">' +
480 '<span class="helpClose_' + configKey + ' ui-icon ui-icon-circle-close" ' +
481 'title="Close Help"' +
482 'style="float:left"/>' +
483 gM( 'fogg-'+ configKey + '-help' ) +
485 out += '</td></tr><tr><td colspan="2" height="10"></td></tr>';
490 * Show a dialog box asking the user to select a source URL.
491 * FIXME: half-written, doesn't work at all.
493 selectSourceUrl: function() {
495 var url = prompt( "Please enter the source media url you would like " +
496 "to transcode from.", "http://" );
502 this.sourceMode = 'url';
503 this.sourceUrl = url;
504 this.clearSourceInfoCache();
505 this.updateSourceFileUI();
506 // update the input target
507 $j( this.target_input_file_name )
510 .removeAttr( 'readonly' );
513 bindControls: function() {
515 _this.basefogg_bindControls();
517 // Show the select by URL if present
518 /*$j( this.target_btn_select_url ).unbind()
519 .attr( 'disabled', false )
520 .css( { 'display': 'inline' } )
522 _this.selectSourceUrl();
526 // Hide the base advanced controls until a file is selected:
527 $j( this.target_control_container ).hide();
530 // Do some display tweaks
531 js_log( 'tw:' + $j( this.selector ).width() +
532 ' ssf:' + $j( this.target_btn_select_new_file ).width() +
533 ' sf:' + $j( this.target_btn_save_local_file ).width() );
536 $j( this.target_input_file_name ).width( 250 );
538 // Special preset action
539 $j( this.selector + ' ._preset_select' ).change( function() {
540 _this.updatePresetSelection( $j( this ).val() );
543 // Bind control actions
544 for ( var configKey in this.default_encoder_config ) {
545 var confEntry = this.default_encoder_config[configKey];
547 // Initial state is hidden
548 $j( this.selector + ' .helpRow_' + configKey ).hide();
550 $j( this.selector + ' .help_' + configKey )
553 // Get the config key (assume it's the last class)
554 var configKey = _this.getClassId( this, 'help_' );
556 if ( helpState[configKey] ) {
557 $j( _this.selector + ' .helpRow_' + configKey ).hide( 'slow' );
558 helpState[configKey] = false;
560 $j( _this.selector + ' .helpRow_' + configKey ).show( 'slow' );
561 helpState[configKey] = true;
568 // get the config key (assume it's the last class)
569 var configKey = _this.getClassId( this, 'help_' );
570 $j( _this.selector + ' .helpRow_' + configKey ).show( 'slow' );
573 var configKey = _this.getClassId( this, 'help_' );
574 if( !helpState[configKey] )
575 $j( _this.selector + ' .helpRow_' + configKey ).hide( 'slow' )
579 $j( this.selector + ' .helpClose_' + configKey )
582 js_log( "close help: " + configKey );
583 // get the config key (assume it's the last class)
584 var configKey = _this.getClassId( this, 'helpClose_' );
585 $j( _this.selector + ' .helpRow_' + configKey ).hide( 'slow' );
586 helpState[configKey] = false;
590 .css( 'cursor', 'pointer' );
592 // Set up bindings for the change events (validate input)
594 switch ( confEntry.type ) {
596 $j( this.selector + ' ._' + configKey)
598 _this.updateLocalValue( _this.getClassId( this ),
599 $j( this ).is( ":checked" ) );
600 _this.updatePresetSelection( 'custom' );
607 //@@check if we have a validate function on the string
608 $j( this.selector + ' ._' + configKey ).change( function() {
609 $j( this ).val( _this.updateLocalValue(
610 _this.getClassId( this ),
611 $j( this ).val() ) );
612 _this.updatePresetSelection( 'custom' );
616 $j( this.selector + ' ._' + configKey ).datepicker({
619 dateFormat: 'd MM, yy',
620 onSelect: function( dateText ) {
621 _this.updateInterfaceValue( _this.getClassId( this ), dateText );
626 var sliderId = _this.getClassId( this, 'slider_' );
627 $j( this.selector + ' .slider_' + configKey ).slider({
630 step: confEntry.step ? confEntry.step : 1,
631 value: $j( this.selector + ' ._' + configKey ).val(),
632 min: this.default_encoder_config[ configKey ].range.min,
633 max: this.default_encoder_config[ configKey ].range.max,
634 slide: function( event, ui ) {
635 $j( _this.selector + ' ._' + sliderId ).val( ui.value );
637 // Maintain source video aspect ratio
638 if ( sliderId == 'width' ) {
639 var sourceHeight = _this.sourceFileInfo.video[0]['height'];
640 var sourceWidth = _this.sourceFileInfo.video[0]['width'];
641 var newHeight = parseInt( sourceHeight / sourceWidth * ui.value );
642 // Reject the update if the new height is above the maximum
643 if ( newHeight > _this.updateInterfaceValue( 'height', newHeight ) )
646 if ( sliderId == 'height' ) {
647 var sourceHeight = _this.sourceFileInfo.video[0]['height'];
648 var sourceWidth = _this.sourceFileInfo.video[0]['width'];
649 var newWidth = parseInt( sourceWidth / sourceHeight * ui.value );
650 // Reject the update if the new width is above the maximum
651 if ( newWidth > _this.updateInterfaceValue( 'width', wv ) )
655 change: function( event, ui ) {
656 _this.updateLocalValue( sliderId, ui.value );
657 _this.updatePresetSelection( 'custom' );
661 $j( this.selector + ' ._' + configKey ).change( function() {
662 var classId = _this.getClassId( this );
663 var validValue = _this.updateLocalValue( classId.substr( 1 ),
665 _this.updatePresetSelection( 'custom' );
666 // Change it to the validated value
667 $j( this ).val( validValue );
669 js_log( "update: " + _this.selector + ' .slider' + classId );
670 $j( _this.selector + ' .slider' + classId )
671 .slider( 'option', 'value', validValue );
677 $j( this.target_control_container ).accordion({
684 // Do the config value updates if there are any
685 this.updateValuesInHtml();
689 * Update the UI due to a change in preset
691 updatePresetSelection: function( presetKey ) {
692 // Update the local configuration
693 this.local_settings['default'] = presetKey;
694 // js_log( 'update preset desc: ' + presetKey );
696 if ( this.local_settings.presets[presetKey].desc ) {
697 presetDesc = this.local_settings.presets[presetKey].desc;
699 presetDesc = gM( 'fogg-preset-' + presetKey );
701 // Update the preset title
702 $j( this.selector + ' .gd_preset' )
703 .html( gM( 'fogg-cg-preset', presetDesc ) );
704 // update the selector
705 $j( this.selector + ' ._preset_select' ).val( presetKey );
709 * Update the interface due to a change in a particular config key
711 updateInterfaceValue: function( confKey, val ) {
717 if ( typeof this.default_encoder_config[confKey] == 'undefined' ) {
718 js_error( 'error: missing default key: ' + confKey );
722 // Update the local value (if it's not already up-to-date)
723 if ( this.local_settings.presets['custom']['conf'][confKey] != val ) {
724 val = this.updateLocalValue( confKey, val );
726 // Update the text field
727 $j( _this.selector + ' ._' + confKey ).val( val );
728 // Update the interface widget
729 switch ( this.default_encoder_config[confKey].type ) {
731 $j( _this.selector + ' .slider_' + confKey )
732 .slider( 'option', 'value', $j( _this.selector + ' ._' + confKey ).val() );
739 * Validate the new config setting, fixing its type and bounding it within a
740 * range if required. Update the configuration with the validated value and
743 updateLocalValue: function( confKey, value ) {
744 if ( typeof this.default_encoder_config[confKey] == 'undefined' ) {
745 js_log( "Error: could not update conf key: " + confKey )
748 var confEntry = this.default_encoder_config[confKey];
749 var range = confEntry.range;
751 value = parseInt( value );
752 var min = ( range.local_min ) ? range.local_min : range.min;
755 var max = ( range.local_max ) ? range.local_max : range.max;
759 if ( confEntry.type == 'int' )
760 value = parseInt( value );
763 /* if( confEntry.step ) {
764 if ( ( value % confEntry.step ) != 0 ) {
765 value = value - (value % confEntry.step);
769 js_log( 'update:local_settings:custom:conf:' + confKey + ' = ' + value );
770 this.local_settings.presets['custom']['conf'][confKey] = value;
776 * Get a local config value from the custom preset
778 getLocalValue: function( confKey ) {
779 return this.local_settings.presets['custom']['conf'][confKey];
783 * Given an element or selector, get its primary class, and strip a given
786 * If no prefix is given, "_" is assumed.
788 getClassId: function( element, prefix ) {
789 var eltClass = $j( element ).attr( "class" ).split( ' ' ).slice( 0, 1 ).toString();
794 if ( eltClass.substr( 0, prefix.length ) == prefix ) {
795 eltClass = eltClass.substr( prefix.length );
801 * Get the appropriate encoder settings for the current Firefogg object,
802 * into which a video has already been selected. Overrides the base method.
804 getEncoderSettings: function() {
805 if ( this.current_encoder_settings != null ) {
806 return this.current_encoder_settings;
809 // Call the base function
810 // Note that settings will be a reference and can be modified
811 var settings = this.basefogg_getEncoderSettings();
813 // Allow re-encoding of files that are already ogg (unlike in the base class)
814 if ( this.isOggFormat() ) {
815 settings['passthrough'] = false;
820 * Do the necessary UI updates due to the source file changing.
821 * Overrides the parent method.
823 updateSourceFileUI: function() {
827 _this.basefogg_updateSourceFileUI();
829 var settings = this.getEncoderSettings();
830 var fileInfo = this.getSourceFileInfo();
832 // In passthrough mode, hide encoder controls
833 if ( settings['passthrough'] ) {
834 js_log( "in passthrough mode (hide control)" );
835 $j( this.target_control_container ).hide( 'slow' );
836 $j( this.target_passthrough_mode ).show( 'slow' );
840 // Show encoder controls
841 $j( this.target_control_container ).show( 'slow' );
842 $j( this.target_passthrough_mode ).hide( 'slow' );
844 // do set up settings based on local_settings /default_encoder_config with sourceFileInfo
845 // see: http://firefogg.org/dev/sourceInfo_example.html
846 var setValues = function( k, val, maxVal ) {
848 // update the value if unset:
849 _this.updateLocalValue( k, val );
852 // update the local range:
853 if ( _this.default_encoder_config[k].range ) {
854 _this.default_encoder_config[k].range.local_max = maxVal;
858 // container level settings
859 for ( var i in fileInfo ) {
860 var val = fileInfo[i];
864 // do nothing with these:
867 if ( val * 2 > this.default_encoder_config[k] ) {
868 maxVal = this.default_encoder_config[k];
874 setValues( k, val, maxVal );
876 // video stream settings
877 for ( var i in fileInfo.video[0] ) {
878 var val = fileInfo.video[0][i];
888 setValues( k, val, maxVal );
890 // audio stream settings, assumes for now thare is only one stream
891 for ( var i in fileInfo.audio[0] ) {
892 var val = fileInfo.audio[0][i];
898 if ( val * 2 > this.default_encoder_config[k] ) {
899 maxVal = this.default_encoder_config[k];
905 setValues( k, val, maxVal );
908 // set all values to new default ranges & update slider:
909 $j.each( this.default_encoder_config, function( inx, val ) {
910 if ( $j( _this.selector + ' ._' + inx ).length != 0 ) {
911 if ( typeof val.range != 'undefined' ) {
912 // update slider range
913 var new_max = (val.range.local_max) ? val.range.local_max : val.range.max
914 $j( _this.selector + ' .slider_' + inx ).slider( 'option', 'max', new_max );
916 // update slider/input value:
917 _this.updateInterfaceValue( inx,
918 _this.local_settings.presets['custom']['conf'][inx] );
923 this.updateValuesInHtml();
926 doEncode: function() {
927 // update the encoder settings (from local settings)
928 pKey = this.local_settings['default'];
929 this.encoder_settings = this.local_settings.presets[ pKey ].conf;
930 this.basefogg_doEncode();
934 * Set the HTML control values to whatever is currently present in this.local_settings
936 updateValuesInHtml: function() {
937 js_log( 'updateValuesInHtml::' );
939 var pKey = this.local_settings['default'];
940 this.updatePresetSelection( pKey );
942 // set the actual HTML & widgets based on any local settings values:
943 $j.each( _this.local_settings.presets['custom']['conf'], function( inx, val ) {
944 if ( $j( _this.selector + ' ._' + inx ).length != 0 ) {
945 $j( _this.selector + ' ._' + inx ).val( val );
951 * Restore settings from a cookie (if available)
953 loadEncSettings: function( force ) {
954 if ( $j.cookie( 'fogg_encoder_config' ) ) {
955 js_log( "load:fogg_encoder_config from cookie " );
956 this.local_settings = JSON.parse( $j.cookie( 'fogg_settings' ) );
958 // set to default if not loaded yet:
959 if ( this.local_settings && this.local_settings.presets
960 && this.local_settings.presets['custom']['conf'] )
962 js_log( 'local settings already populated' );
964 this.local_settings = this.default_local_settings;
969 * Clear preset settings
970 * FIXME: not called, does nothing
972 clearSettings: function( force ) {
976 * Save the current encoder settings to a cookie.
978 saveEncSettings: function() {
979 $j.cookie( 'fogg_settings', JSON.stringify( this.local_settings ) );