1(function ( PKAE ) { 2 'use strict'; 3 4 function PKState ( _depth, app ) { 5 if (!_depth) _depth = 1; 6 7 var q = this; 8 9 var _id = 1; 10 var _fireEvent = app.fireEvent; 11 var _listenFor = app.listenFor; 12 13 var undo_state_list = []; 14 var redo_state_list = []; 15 16 q.getLastUndoState = function () { 17 return (undo_state_list [ undo_state_list.length - 1]); 18 }; 19 20 q.pushUndoState = function ( state ) { 21 if (!state) return (false); 22 23 if (!state.id) state.id = ++_id; 24 if (undo_state_list.length >= _depth) undo_state_list.shift (); 25 26 if (undo_state_list.length > 0) 27 { 28 if (undo_state_list[undo_state_list.length - 1].id !== state.id - 1) 29 undo_state_list = []; 30 } 31 if (redo_state_list.length > 0) 32 { 33 if (redo_state_list[0].id !== state.id + 1) 34 redo_state_list = []; 35 } 36 37 undo_state_list.push ( state ); 38 39 _fireEvent ( 'StatePush', undo_state_list.length ); 40 _fireEvent ( 'DidStateChange', undo_state_list, redo_state_list); 41 42 return (true); 43 }; 44 45 q.popUndoState = function () { 46 var last_state =undo_state_list.pop (); 47 48 if (last_state) { 49 if (redo_state_list.length > 0) 50 { 51 if (redo_state_list[0].id !== last_state.id + 1) 52 redo_state_list = []; 53 } 54 55 var temp = app.engine.wavesurfer.backend.buffer; 56 _fireEvent ( 'StateDidPop', last_state, 1 ); 57 58 last_state.data = temp; 59 redo_state_list.unshift (last_state); 60 61 _fireEvent ( 'DidStateChange', undo_state_list, redo_state_list); 62 } 63 64 return (last_state); 65 }; 66 67 q.shiftRedoState = function () { 68 var last_state = redo_state_list.shift (); 69 70 if (last_state) { 71 if (undo_state_list.length > 0) 72 { 73 if (undo_state_list[undo_state_list.length - 1].id !== last_state.id - 1) 74 undo_state_list = []; 75 } 76 77 var temp = app.engine.wavesurfer.backend.buffer; 78 _fireEvent ( 'StateDidPop', last_state, 0 ); 79 80 last_state.data = temp; 81 undo_state_list.push (last_state); 82 83 _fireEvent ( 'DidStateChange', undo_state_list, redo_state_list); 84 } 85 86 return (last_state); 87 }; 88 89 q.clearAllState = function () { 90 undo_state_list = []; 91 redo_state_list = []; 92 93 _fireEvent ( 'StateClearAll' ); 94 _fireEvent ( 'DidStateChange', [], []); 95 }; 96 97 _listenFor ('StateRequestPush', function ( _state ) { 98 q.pushUndoState ( _state ); 99 }); 100 _listenFor ('StateRequestUndo', function () { 101 q.popUndoState (); 102 }); 103 _listenFor ('StateRequestRedo', function () { 104 q.shiftRedoState (); 105 }); 106 _listenFor ('StateRequestClearAll', function () { 107 q.clearAllState (); 108 }); 109 _listenFor ('StateRequestLastState', function () { 110 _fireEvent ('StateDidLastState', q.getLastUndoState ()); 111 }); 112 // - 113 }; 114 115 PKAE._deps.state = PKState; 116 117})( PKAudioEditor );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.