Skip to content

Commit

Permalink
Adding pitch support (#2564)
Browse files Browse the repository at this point in the history
* add the pitch thing

* Changing the set_pitch to something more functional

* Set the FLX_PITCH define

* Delete all the code pasting to be more integrated to Lime

* Delete a small mental typo

* change the FLX_PITCH define for flash to "work"

* Polish the FLX_PITCH and FLX_NO_PITCH setting

* Can we forget I forgot a semicolon?
  • Loading branch information
Cheemsandfriends committed Sep 29, 2022
1 parent 0f3ae2d commit e58f765
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
24 changes: 15 additions & 9 deletions flixel/system/FlxSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ class FlxSound extends FlxBasic
* Set volume to a value between 0 and 1 to change how this sound is.
*/
public var volume(get, set):Float;

#if (sys && openfl_legacy)
#if FLX_PITCH
/**
* Set pitch, which also alters the playback speed. Default is 1.
*/
public var pitch(get, set):Float;
#end

/**
* The position in runtime of the music playback in milliseconds.
* If set while paused, changes only come into effect after a `resume()` call.
Expand Down Expand Up @@ -177,14 +175,12 @@ class FlxSound extends FlxBasic
* Internal tracker for sound length, so that length can still be obtained while a sound is paused, because _sound becomes null.
*/
var _length:Float = 0;

#if (sys && openfl_legacy)
#if FLX_PITCH
/**
* Internal tracker for pitch.
*/
var _pitch:Float = 1.0;
#end

/**
* Internal tracker for total volume adjustment.
*/
Expand Down Expand Up @@ -432,6 +428,9 @@ class FlxSound extends FlxBasic
updateTransform();
exists = true;
onComplete = OnComplete;
#if FLX_PITCH
pitch = 1;
#end
_length = (_sound == null) ? 0 : _sound.length;
endTime = _length;
return this;
Expand Down Expand Up @@ -610,7 +609,7 @@ class FlxSound extends FlxBasic
_channel = _sound.play(_time, 0, _transform);
if (_channel != null)
{
#if (sys && openfl_legacy)
#if FLX_PITCH
pitch = _pitch;
#end
_channel.addEventListener(Event.SOUND_COMPLETE, stopped);
Expand Down Expand Up @@ -736,17 +735,24 @@ class FlxSound extends FlxBasic
updateTransform();
return Volume;
}

#if (sys && openfl_legacy)
#if FLX_PITCH
inline function get_pitch():Float
{
return _pitch;
}


function set_pitch(v:Float):Float
{
if (_channel != null)
#if openfl_legacy
_channel.pitch = v;
#else
@:privateAccess
if (_channel.__source != null)
_channel.__source.pitch = v;
#end

return _pitch = v;
}
#end
Expand Down
10 changes: 9 additions & 1 deletion flixel/system/macros/FlxDefines.hx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private enum UserDefines
FLX_4_LEGACY_COLLISION;
/* Simplifies FlxPoint but can increase GC frequency */
FLX_NO_POINT_POOL;
FLX_NO_PITCH;
}

/**
Expand Down Expand Up @@ -54,6 +55,7 @@ private enum HelperDefines
FLX_ACCELEROMETER;
FLX_DRAW_QUADS;
FLX_POINT_POOL;
FLX_PITCH;
}

class FlxDefines
Expand Down Expand Up @@ -141,7 +143,13 @@ class FlxDefines

if (!defined(FLX_NO_SOUND_SYSTEM) && !defined(FLX_NO_SOUND_TRAY))
define(FLX_SOUND_TRAY);


if (defined(FLX_NO_SOUND_SYSTEM) || #if openfl_legacy !defined("sys") #elseif (lime >= "8.0.0") defined("flash") #end)
define(FLX_NO_PITCH);

if (!defined(FLX_NO_PITCH))
define(FLX_PITCH);

if ((!defined("openfl_legacy") && !defined("flash")) || defined("flash11_8"))
define(FLX_GAMEINPUT_API);
else if (!defined("openfl_next") && (defined("cpp") || defined("neko")))
Expand Down

0 comments on commit e58f765

Please sign in to comment.