Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
engine
Commits
fb131e84
Commit
fb131e84
authored
4 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
Current volume sensitive fading. #44
parent
653b008e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/core/engine.py
+2
-2
2 additions, 2 deletions
modules/core/engine.py
modules/core/mixer.py
+83
-9
83 additions, 9 deletions
modules/core/mixer.py
with
85 additions
and
11 deletions
modules/core/engine.py
+
2
−
2
View file @
fb131e84
...
@@ -405,7 +405,7 @@ class Player:
...
@@ -405,7 +405,7 @@ class Player:
return
return
if
transition
==
TransitionType
.
FADE
:
if
transition
==
TransitionType
.
FADE
:
self
.
mixer
.
fade_out
(
entry
.
channel
,
entry
.
volume
)
self
.
mixer
.
fade_out
(
entry
.
channel
)
else
:
else
:
self
.
mixer
.
channel_volume
(
entry
.
channel
,
0
)
self
.
mixer
.
channel_volume
(
entry
.
channel
,
0
)
...
@@ -435,7 +435,7 @@ class Player:
...
@@ -435,7 +435,7 @@ class Player:
self
.
logger
.
info
(
f
"
Fading out channel
'
{
dirty_channel
}
'"
)
self
.
logger
.
info
(
f
"
Fading out channel
'
{
dirty_channel
}
'"
)
self
.
connector
.
enable_transaction
()
self
.
connector
.
enable_transaction
()
self
.
mixer_fallback
.
fade_out
(
dirty_channel
,
100
)
self
.
mixer_fallback
.
fade_out
(
dirty_channel
)
self
.
connector
.
disable_transaction
()
self
.
connector
.
disable_transaction
()
def
clean_up
():
def
clean_up
():
...
...
This diff is collapsed.
Click to expand it.
modules/core/mixer.py
+
83
−
9
View file @
fb131e84
...
@@ -37,6 +37,26 @@ class MixerType(Enum):
...
@@ -37,6 +37,26 @@ class MixerType(Enum):
class
MixerUtil
:
"""
Little helpers for the mixer.
"""
@staticmethod
def
channel_status_dict
(
status
):
"""
Transforms a channel status string to a dictionary.
"""
s
=
{}
pairs
=
status
.
split
(
"
"
)
for
pair
in
pairs
:
kv
=
pair
.
split
(
"
=
"
)
s
[
kv
[
0
]]
=
kv
[
1
]
return
s
class
Mixer
():
class
Mixer
():
"""
"""
A virtual mixer.
A virtual mixer.
...
@@ -154,18 +174,41 @@ class Mixer():
...
@@ -154,18 +174,41 @@ class Mixer():
return
self
.
mixer_channels
()
return
self
.
mixer_channels
()
#
# Channel
#
def
channel_number
(
self
,
channel
):
"""
Returns the channel number for the given channel ID.
Args:
channel (Channel): The channel
Returns:
(Integer): The channel number
"""
channels
=
self
.
mixer_channels
()
index
=
channels
.
index
(
channel
)
if
index
<
0
:
self
.
logger
.
critical
(
f
"
There
'
s no valid channel number for channel ID
'
{
channel
.
value
}
'"
)
return
None
return
index
def
channel_status
(
self
,
channel_number
):
def
channel_status
(
self
,
channel_number
):
"""
"""
Retrieves the status of a channel identified by the channel number.
Retrieves the status of a channel identified by the channel number.
Args:
channel_number (Integer): The channel number
Returns:
(String): Channel status info as a String
"""
"""
return
self
.
connector
.
send_lqc_command
(
self
.
mixer_id
.
value
,
"
mixer_status
"
,
channel_number
)
return
self
.
connector
.
send_lqc_command
(
self
.
mixer_id
.
value
,
"
mixer_status
"
,
channel_number
)
#
# Channel
#
def
channel_select
(
self
,
channel
,
select
):
def
channel_select
(
self
,
channel
,
select
):
"""
"""
Selects/deselects some mixer channel
Selects/deselects some mixer channel
...
@@ -217,6 +260,20 @@ class Mixer():
...
@@ -217,6 +260,20 @@ class Mixer():
self
.
logger
.
critical
(
"
Ran into exception when activating channel. Reason:
"
+
str
(
e
))
self
.
logger
.
critical
(
"
Ran into exception when activating channel. Reason:
"
+
str
(
e
))
def
channel_current_volume
(
self
,
channel
):
"""
Retrieves the current volume of the channel.
"""
channel_number
=
self
.
channel_number
(
channel
.
value
)
status
=
self
.
channel_status
(
channel_number
)
channel_status
=
MixerUtil
.
channel_status_dict
(
status
)
volume
=
channel_status
.
get
(
"
volume
"
)
if
volume
:
return
int
(
volume
.
split
(
"
%
"
)[
0
])
else
:
self
.
logger
.
error
(
f
"
Invalid volume for channel
{
channel
.
value
}
(status:
'
{
status
}
'"
)
return
0
def
channel_volume
(
self
,
channel
,
volume
):
def
channel_volume
(
self
,
channel
,
volume
):
"""
"""
...
@@ -278,6 +335,15 @@ class Mixer():
...
@@ -278,6 +335,15 @@ class Mixer():
(Boolean): `True` if successful
(Boolean): `True` if successful
"""
"""
try
:
try
:
current_volume
=
self
.
channel_current_volume
(
channel
)
if
current_volume
==
volume
:
self
.
logger
.
warning
(
f
"
Current volume for channel
{
channel
.
value
}
is already at target volume of
{
volume
}
% SKIPPING...
"
)
return
elif
current_volume
>
volume
:
self
.
logger
.
warning
(
f
"
Current volume
{
current_volume
}
% of channel
{
channel
.
value
}
exceeds target volume of
{
volume
}
% SKIPPING...
"
)
return
fade_in_time
=
float
(
self
.
config
.
get
(
"
fade_in_time
"
))
fade_in_time
=
float
(
self
.
config
.
get
(
"
fade_in_time
"
))
if
fade_in_time
>
0
:
if
fade_in_time
>
0
:
...
@@ -313,9 +379,9 @@ class Mixer():
...
@@ -313,9 +379,9 @@ class Mixer():
def
fade_out
(
self
,
channel
,
volume
):
def
fade_out
(
self
,
channel
,
volume
=
None
):
"""
"""
Performs a fade-out for the given channel.
Performs a fade-out for the given channel
starting at it
'
s current volume
.
Args:
Args:
channel (Channel): The channel to fade
channel (Channel): The channel to fade
...
@@ -325,10 +391,18 @@ class Mixer():
...
@@ -325,10 +391,18 @@ class Mixer():
(Boolean): `True` if successful
(Boolean): `True` if successful
"""
"""
try
:
try
:
current_volume
=
self
.
channel_current_volume
(
channel
)
if
not
volume
:
volume
=
current_volume
if
current_volume
==
0
:
self
.
logger
.
warning
(
f
"
Current volume for channel
{
channel
.
value
}
is already at target volume of 0%. SKIPPING...
"
)
return
fade_out_time
=
float
(
self
.
config
.
get
(
"
fade_out_time
"
))
fade_out_time
=
float
(
self
.
config
.
get
(
"
fade_out_time
"
))
if
fade_out_time
>
0
:
if
fade_out_time
>
0
:
step
=
abs
(
fade_out_time
)
/
volume
step
=
abs
(
fade_out_time
)
/
current_
volume
msg
=
"
Starting to fading-out
'
%s
'
. Step is %ss.
"
%
(
channel
,
str
(
step
))
msg
=
"
Starting to fading-out
'
%s
'
. Step is %ss.
"
%
(
channel
,
str
(
step
))
self
.
logger
.
info
(
SU
.
pink
(
msg
))
self
.
logger
.
info
(
SU
.
pink
(
msg
))
...
@@ -353,4 +427,4 @@ class Mixer():
...
@@ -353,4 +427,4 @@ class Mixer():
except
LQConnectionError
as
e
:
except
LQConnectionError
as
e
:
self
.
logger
.
critical
(
str
(
e
))
self
.
logger
.
critical
(
str
(
e
))
return
False
return
False
return
True
return
True
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment