Skip to content
This repository has been archived by the owner on Nov 1, 2019. It is now read-only.

Commit

Permalink
fixed AmplitudeModulator's excessive range, solved embarassing tab in…
Browse files Browse the repository at this point in the history
…dex bag for form inputs.
  • Loading branch information
igorski committed Dec 12, 2011
1 parent fad902b commit fc6fa58
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 48 deletions.
4 changes: 2 additions & 2 deletions src/nl/igorski/lib/audio/generators/waveforms/Triangle.as
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ package nl.igorski.lib.audio.generators.waveforms

if( _phase < .5 ) {
tmp = ( _phase * 4.0 - 1.0 );
amplitude = ( 1.0 - tmp * tmp ) * env * env;
amplitude = ( 1.0 - tmp * tmp ) * env * env * .75;
}
else {
tmp = ( _phase * 4.0 - 3.0 );
amplitude = ( tmp * tmp - 1.0 ) * env * env;
amplitude = ( tmp * tmp - 1.0 ) * env * env * .75;
}

_phase += _phaseIncr;
Expand Down
14 changes: 10 additions & 4 deletions src/nl/igorski/lib/audio/model/vo/VOAudioEvent.as
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ package nl.igorski.lib.audio.model.vo
return true;

for ( _progress; _progress < m; ++_progress )
wave.generate( cacheBuffer, _progress );
{
if ( cacheBuffer != null && wave != null ) // TODO: this shouldn't occur !
wave.generate( cacheBuffer, _progress );
}

return _progress < _maximum;
}
Expand All @@ -191,10 +194,13 @@ package nl.igorski.lib.audio.model.vo
cacheBuffer = null;
_maximum = 0;

sample.valid = true;
sample.sample.invalidateSampleMemory();
sample.sample.commitChannelData();
if ( sample ) {
// TODO: this check should be uncessary
sample.valid = true;
sample.sample.invalidateSampleMemory();
sample.sample.commitChannelData();

}
removeEventListener( ThreadEvent.COMPLETE, threadComplete );
dispatchEvent( new AudioCacheEvent( AudioCacheEvent.CACHE_COMPLETED ));
}
Expand Down
22 changes: 13 additions & 9 deletions src/nl/igorski/lib/audio/modifiers/Delay.as
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ package nl.igorski.lib.audio.modifiers
// C O N S T R U C T O R

/**
* @param delayTime {Number} in milliseconds, time between consecutive repeats
* @param mix {Number} 0-1, percentage of dry/wet mix
* @param feedback {Number} 0-1, amount of repeats
* @param aDelayTime {Number} in milliseconds, time between consecutive repeats
* @param aMix {Number} 0-1, percentage of dry/wet mix
* @param aFeedback {Number} 0-1, amount of repeats
*/
public function Delay( delayTime:Number = 250, mix:Number = .2, feedback:Number = .7 ):void
public function Delay( aDelayTime:Number = 250, aMix:Number = .2, aFeedback:Number = .7 ):void
{
_time = Math.round(( AudioSequencer.SAMPLE_RATE * .001 ) * delayTime );
_time = Math.round(( AudioSequencer.SAMPLE_RATE * .001 ) * aDelayTime );
_delayBuffer = new Vector.<Vector.<Number>>( _time, true );
_mix = mix;
_feedback = feedback;
_mix = aMix;
_feedback = aFeedback;

for( var i:int = 0 ; i < _time ; ++i )
_delayBuffer[ i ] = new Vector.<Number>( 2, true );
Expand Down Expand Up @@ -91,6 +91,7 @@ package nl.igorski.lib.audio.modifiers
{
// might as well be OFF - we do this to prevent it from
// being saved as it's not removed from the sequencer's busModifiers

if ( mix == 0 && feedback == 0 )
return null;

Expand Down Expand Up @@ -118,11 +119,14 @@ package nl.igorski.lib.audio.modifiers

public function set delayTime( value:Number ):void
{
_time = Math.round(( AudioSequencer.SAMPLE_RATE * .001 ) * delayTime );
_time = Math.round(( AudioSequencer.SAMPLE_RATE * .001 ) * value );
_delayBuffer = new Vector.<Vector.<Number>>( _time, true );

for( var i:int = 0 ; i < _time ; ++i )
for ( var i:int = 0 ; i < _time ; ++i )
_delayBuffer[ i ] = new Vector.<Number>( 2, true );

if ( _delayIndex > _time )
_delayIndex = 0;
}

public function get mix():Number
Expand Down
10 changes: 9 additions & 1 deletion src/nl/igorski/lib/audio/modulators/AmplitudeModulator.as
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ package nl.igorski.lib.audio.modulators

override public function modulate( value:Number ):Number
{
return value * generate();
var theVolume:Number = .5;

// these can get loud
if ( _wave == LFO_SINE_WAVE )
theVolume = 0.05;
else if ( _wave == LFO_SQUARE_WAVE )
theVolume = 0.03;

return value * ( generate() * theVolume );
}

//_____________________________________________________________________________________________________________
Expand Down
15 changes: 10 additions & 5 deletions src/nl/igorski/lib/audio/ui/AudioTimeline.as
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,22 @@ public class AudioTimeline extends Sprite implements IAudioTimeline
/**
* showNext: draws the graphics and adds listeners for the timeline that is about to slide into view
*
* @param upper Boolean set to true for enabling visibility of next ( higher octave )
* set to false for enabling visibility of lower octave
* @param upper {Boolean} set to true for enabling visibility of next ( higher octave )
* set to false for enabling visibility of lower octave
* @param fromOctave {int} the octave we want to calculate from, defaults to the currently
* visible octave
*/
protected function showNext( upper:Boolean ):void
protected function showNext( upper:Boolean, fromOctave:int = -1 ):void
{
var next:int;

if ( fromOctave == -1 )
fromOctave = _curOctave;

if ( upper )
next = _curOctave + 1;
next = fromOctave + 1;
else
next = _curOctave - 1;
next = fromOctave - 1;

if ( next > _octaves || next < 0 )
return;
Expand Down
19 changes: 11 additions & 8 deletions src/nl/igorski/lib/ui/forms/components/Input.as
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

tabIndex = _tabIndex;

bg.alpha = 0;
bg.alpha = 0;
error_bg.alpha = 1;
}

Expand All @@ -103,7 +103,7 @@
draw();
swapChildren( textField, getChildAt( numChildren - 1 ));

bg.alpha = 1;
bg.alpha = 1;
error_bg.alpha = 0;
}

Expand Down Expand Up @@ -204,17 +204,18 @@
override public function set tabEnabled( value:Boolean ):void
{
textField.tabEnabled = true;
super.tabEnabled = false;
}

override public function set height( value:Number ):void
{
bg.height = value;
bg.height = value;
error_bg.height = value;
}

override public function set width( value:Number ):void
{
bg.width = value;
bg.width = value;
error_bg.width = value;
}

Expand All @@ -237,6 +238,8 @@

private function handleTextFieldFocus( e:FocusEvent ):void
{
stage.focus = textField; // force this for tab-key usage bug which might occur

if ( textField.text == _placeHolderText )
{
textField.text = " ";
Expand Down Expand Up @@ -310,10 +313,10 @@

if ( textField.multiline ) {
textField.height = bg.height - 2;
textField.y = Math.round( bg.y + 1 );
textField.y = Math.round( bg.y + 1 );
} else {
textField.height = 18;
textField.y = Math.round(( bg.height - 20 ) * .5 );
textField.y = Math.round(( bg.height - 20 ) * .5 );
}
addChild( textField );
addListeners();
Expand All @@ -324,13 +327,13 @@

private function addListeners():void
{
textField.addEventListener( FocusEvent.FOCUS_IN, handleTextFieldFocus );
textField.addEventListener( FocusEvent.FOCUS_IN, handleTextFieldFocus );
textField.addEventListener( FocusEvent.FOCUS_OUT, handleTextFieldBlur );
}

private function removeListeners():void
{
textField.removeEventListener( FocusEvent.FOCUS_IN, handleTextFieldFocus );
textField.removeEventListener( FocusEvent.FOCUS_IN, handleTextFieldFocus );
textField.removeEventListener( FocusEvent.FOCUS_OUT, handleTextFieldBlur );
}

Expand Down
50 changes: 31 additions & 19 deletions src/nl/igorski/lib/utils/pagination/Pagination.as
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,51 @@ package nl.igorski.lib.utils.pagination
{
private var _currentPage :int;
private var _buttonClass :Class;
private var _maxPages :int;
private var _totalPages :int;
private var _items_per_page :int;

private var _buttons :Vector.<IPaginatorButton>;

//_________________________________________________________________________________________________________
// C O N S T R U C T O R

public function Pagination( currentPage:int = 0, totalItems:int = 0, itemsPerPage:int = 5, buttonClass:Class = null )
/**
*
* @param currentPage {int} number of the current page
* @param totalPages {int} amount of pages
* @param itemsPerPage {int} the max. amount of buttons in the paginator
* @param buttonClass {Class} the Class to use for the buttons, must implement
* the IPaginatorButton interface
*/
public function Pagination( currentPage:int = 0, totalPages:int = 0, itemsPerPage:int = 5, buttonClass:Class = null )
{
_currentPage = currentPage;
_buttonClass = buttonClass;
_maxPages = Math.ceil( totalItems / itemsPerPage );
_totalPages = Math.ceil( totalPages / itemsPerPage );
_items_per_page = itemsPerPage;

_buttons = new <IPaginatorButton>[];

if ( _maxPages > 1 )
if ( _totalPages > 1 )
createButtons();
}

//_________________________________________________________________________________________________________
// P U B L I C M E T H O D S

public function update( currentPage:int = 0, totalItems:int = 0, itemsPerPage:int = 5 ):void
/**
* update the current paginator button list
* @param currentPage {int} number of the current page
* @param totalPages {int} amount of pages
*/
public function update( currentPage:int = 0, totalPages:int = 0 ):void
{
destroyButtons();

_currentPage = currentPage;
_maxPages = Math.ceil( totalItems / itemsPerPage );
_items_per_page = itemsPerPage;
_totalPages = totalPages;

if ( _maxPages > 1 )
if ( _totalPages > 1 )
createButtons();
}
//_________________________________________________________________________________________________________
Expand Down Expand Up @@ -90,31 +102,31 @@ package nl.igorski.lib.utils.pagination

var max:int = min + _items_per_page;

if ( max > _maxPages )
max = _maxPages;
if ( max > _totalPages )
max = _totalPages;

if ( min > 0 )
{
if ( max - 1 < _maxPages + 1 )
if ( max - 1 < _totalPages + 1 )
++min;

if ( _maxPages > _items_per_page ) {
createButton( 0, "1" );
if ( _totalPages > _items_per_page ) {
createButton( 0, "1..." );
}
}
var doLast:Boolean = false;

if ( max < _maxPages ) {
if ( max < _totalPages ) {
--max;
doLast = true;
}
else {

if ( _currentPage == _maxPages - 1 )
min -= ( _maxPages + theStep ) - max;
if ( _currentPage == _totalPages - 1 )
min -= ( _totalPages + theStep ) - max;

else if ( _currentPage == ( _maxPages - theStep ))
min -= ( _maxPages + 1 ) - max;
else if ( _currentPage == ( _totalPages - theStep ))
min -= ( _totalPages + 1 ) - max;

if ( min < 0 )
min = 0;
Expand All @@ -129,7 +141,7 @@ package nl.igorski.lib.utils.pagination
}

if ( doLast )
createButton( _maxPages - 1, "..." + _maxPages );
createButton( _totalPages - 1, "..." + _totalPages );
}

private function destroyButtons():void
Expand Down

0 comments on commit fc6fa58

Please sign in to comment.