Putting all the code from the current master branch of TWBlue

This commit is contained in:
2014-10-27 16:29:04 -06:00
parent 58c82e5486
commit 1af4a8b291
284 changed files with 58760 additions and 0 deletions

View File

@@ -0,0 +1 @@
from .tempo import Tempo

View File

@@ -0,0 +1,39 @@
from __future__ import absolute_import
from sound_lib.external import pybass
from .effect import SoundEffect
class Chorus(SoundEffect):
effect_type = pybass.BASS_FX_DX8_CHORUS
struct = pybass.BASS_DX8_CHORUS
class Echo(SoundEffect):
effect_type = pybass.BASS_FX_DX8_ECHO
struct = pybass.BASS_DX8_ECHO
class Compressor(SoundEffect):
effect_type = pybass.BASS_FX_DX8_COMPRESSOR
struct = pybass.BASS_DX8_COMPRESSOR
class Reverb(SoundEffect):
effect_type = pybass.BASS_FX_DX8_REVERB
struct = pybass.BASS_DX8_REVERB
class Distortion(SoundEffect):
effect_type = pybass.BASS_FX_DX8_DISTORTION
struct = pybass.BASS_DX8_DISTORTION
class Flanger(SoundEffect):
effect_type = pybass.BASS_FX_DX8_FLANGER
struct = pybass.BASS_DX8_FLANGER
class Gargle(SoundEffect):
effect_type = pybass.BASS_FX_DX8_GARGLE
struct = pybass.BASS_DX8_GARGLE
class I3DL2Reverb(SoundEffect):
effect_type = pybass.BASS_FX_DX8_I3DL2REVERB
struct = pybass.BASS_DX8_I3DL2REVERB
class ParamEq(SoundEffect):
effect_type = pybass.BASS_FX_DX8_PARAMEQ
struct = pybass.BASS_DX8_PARAMEQ

View File

@@ -0,0 +1,14 @@
from __future__ import absolute_import
from sound_lib.external import pybass_fx
from .effect import SoundEffect
class Volume(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_VOLUME
struct = pybass_fx.BASS_BFX_VOLUME
class PeakEq(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_PEAKEQ
struct = pybass_fx.BASS_BFX_PEAKEQ
class DAmp(SoundEffect):
effect_type = pybass_fx.BASS_FX_BFX_DAMP
struct = pybass_fx.BASS_BFX_DAMP

View File

@@ -0,0 +1,71 @@
from future.builtins import object
from sound_lib.main import bass_call
import ctypes
from sound_lib.external import pybass
import string #for the alphabet!
class SoundEffect(object):
def __init__(self, channel, type=None, priority=0):
self.original_channel = channel
if hasattr(channel, 'handle'):
channel = channel.handle
if type is None:
type = self.effect_type
self.effect_type = type
self.priority = priority
self.handle = bass_call(pybass.BASS_ChannelSetFX, channel, type, priority)
def get_parameters(self):
"""Retrieves the parameters of an effect."""
res = {}
params = self.struct()
bass_call(pybass.BASS_FXGetParameters, self.handle, ctypes.pointer(params))
for f in params._fields_:
res[f[0]] = getattr(params, f[0])
return res
def set_parameters(self, parameters):
params = self.struct()
for p, v in parameters.items():
setattr(params, p, v)
bass_call(pybass.BASS_FXSetParameters, self.handle, ctypes.pointer(params))
def __dir__(self):
res = dir(self.__class__)
return res + self._get_pythonic_effect_fields()
def _get_effect_fields(self):
return [i[0] for i in self.struct._fields_]
def _get_pythonic_effect_fields(self):
return [self._bass_to_python(i) for i in self._get_effect_fields() if not i.startswith('_') ]
def _bass_to_python(self, func):
for c in string.ascii_lowercase:
func = func.replace(c.upper(), '_%s' % c)
if func.startswith('_'):
func = func[1:]
return func[2:]
def _python_to_bass(self, func):
for c in string.ascii_lowercase:
func = func.replace('_%s' % c, c.upper())
func = '%s%s' % (func[0].upper(), func[1:])
for f in self._get_effect_fields():
if f.endswith(func):
func = f
return func
def __getattr__(self, attr):
return self.get_parameters()[self._python_to_bass(attr)]
def __setattr__(self, attr, val):
if attr not in self._get_pythonic_effect_fields():
return super(SoundEffect, self).__setattr__(attr, val)
params = self.get_parameters()
key = self._python_to_bass(attr)
if key not in params:
raise AttributeError('Unable to set attribute, suspect issue with base name-munging code')
params[key] = val
self.set_parameters(params)

View File

@@ -0,0 +1,65 @@
import ctypes
from sound_lib.external import pybass, pybass_fx
from sound_lib.stream import BaseStream
from sound_lib.channel import Channel
from sound_lib.main import bass_call, bass_call_0
class Tempo(BaseStream):
def __init__(self, channel, flags=0, loop=False, software=False, three_d=False, sample_fx=False, autofree=False, decode=False, free_source=False):
flags = flags | self.flags_for(loop=False, software=False, three_d=False, sample_fx=False, autofree=False, decode=False, free_source=False)
self.channel = channel
if isinstance(channel, Channel):
channel = channel.handle
handle = bass_call(pybass_fx.BASS_FX_TempoCreate, channel, flags)
super(Tempo, self).__init__(handle)
self.add_attributes_to_mapping(
tempo=pybass_fx.BASS_ATTRIB_TEMPO,
tempo_pitch=pybass_fx.BASS_ATTRIB_TEMPO_PITCH,
tempo_freq=pybass_fx.BASS_ATTRIB_TEMPO_FREQ,
)
@property
def tempo(self):
"""The tempo of a channel."""
return self.get_attribute(pybass_fx.BASS_ATTRIB_TEMPO)
@tempo.setter
def tempo(self, val):
self.set_attribute('tempo', val)
@property
def tempo_pitch(self):
return self.get_attribute('tempo_pitch')
@tempo_pitch.setter
def tempo_pitch(self, val):
self.set_attribute('tempo_pitch', val)
@property
def tempo_freq(self):
return self.get_attribute('tempo_freq')
@tempo_freq.setter
def tempo_freq(self, val):
self.set_attribute('tempo_freq', val)
def setup_flag_mapping(self):
super(Tempo, self).setup_flag_mapping()
self.flag_mapping.update({
'free_source': pybass_fx.BASS_FX_FREESOURCE,
})
def get_source(self):
source = pybass_fx.BASS_FX_TempoGetSource(self.handle)
if source == self.channel.handle:
source = self.channel
return source
source = property(fget=get_source)
def get_rate_ratio(self):
return bass_call(pybass_fx.BASS_FX_TempoGetRateRatio, self.handle)
rate_ratio = property(fget=get_rate_ratio)