diff --git a/pgfw/Note.py b/pgfw/Note.py index 355a55d..ca53f58 100644 --- a/pgfw/Note.py +++ b/pgfw/Note.py @@ -41,8 +41,7 @@ class Note(Samples): names = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"] SQUARE, TRIANGLE, SAW, SINE, DIRTY = range(5) - def __init__(self, name=None, octave=4, frequency=None, shape=SQUARE, - volume=1.0): + def __init__(self, name=None, octave=4, frequency=None, shape=SQUARE, volume=1.0): names = self.names self.shape = shape if frequency is None: @@ -61,8 +60,7 @@ class Note(Samples): octave_length = len(names) offset = (octave - self.base_octave) * octave_length + \ names.index(name) - names.index(self.base_name) - self.frequency = self.base_frequency * 2 ** \ - (offset / float(octave_length)) + self.frequency = self.base_frequency * 2 ** (offset / float(octave_length)) def set_name_and_octave(self): names = self.names @@ -126,27 +124,32 @@ class Note(Samples): else: samples[time] = -amplitude - def play(self, maxtime=0, fadeout=None, panning=None, fade_in=0): + def play(self, maxtime=0, fadeout=None, panning=None, fade_in=0, position=None): channel = Samples.play(self, -1, maxtime, fade_in) if fadeout: self.fadeout(fadeout) + if position is not None: + panning = self.get_panning(position) if channel and panning: channel.set_volume(*panning) return channel + def get_panning(self, position): + return 1 - max(0, ((position - .5) * 2)), 1 + min(0, ((position - .5) * 2)) + class Chord: def __init__(self, *args): self.notes = args - def play(self, maxtime=0, fadeout=[None], panning=None, fade_in=[0]): + def play(self, maxtime=0, fadeout=[None], panning=None, fade_in=[0], position=None): if isinstance(fadeout, int): fadeout = [fadeout] if isinstance(fade_in, int): fade_in = [fade_in] for ii, note in enumerate(self.notes): - note.play(maxtime, fadeout[ii % len(fadeout)], panning, fade_in[ii % len(fade_in)]) + note.play(maxtime, fadeout[ii % len(fadeout)], panning, fade_in[ii % len(fade_in)], position) def stop(self): for note in self.notes: diff --git a/pgfw/extension.py b/pgfw/extension.py index 3c87970..95d03af 100644 --- a/pgfw/extension.py +++ b/pgfw/extension.py @@ -350,11 +350,11 @@ def get_inverted_surface(base): del pixels return surface -def fill_tile(surface, tile, rect=None, flags=0): +def fill_tile(surface, tile, rect=None, flags=0, offset=Vector(0, 0)): w, h = tile.get_size() surface.set_clip(rect) - for x in range(0, surface.get_width(), w): - for y in range(0, surface.get_height(), h): + for x in range(-offset.x, surface.get_width(), w): + for y in range(-offset.y, surface.get_height(), h): surface.blit(tile, (x, y), None, flags) surface.set_clip(None)