Esempio n. 1
0
def shape_plot(save=True, show=False):
    mys = Synth()
    shapes = [
        'Sine', 'Triangle', 'Square', 'SquareH', 'Sawtooth', 'Pulse',
        'Semicircle', 'WhiteNoise'
    ]
    sa = []
    for s in shapes:
        mys.set_parameters(osc_2=s, amp_1=0, amp_2=1)
        sa.append(mys.get_sound_array())

    plt.figure(figsize=(5, 6))
    for i, s in enumerate(shapes):
        plt.subplot(4, 2, i + 1)
        if s == 'WhiteNoise':
            plt.plot(sa[i], linewidth=2)
        else:
            plt.plot(sa[i][:250], linewidth=4)
        plt.yticks(ticks=[-1, 1], labels=['-1', '1'])
        plt.tick_params(
            axis='x',  # changes apply to the x-axis
            which='both',  # both major and minor ticks are affected
            bottom=False,  # ticks along the bottom edge are off
            top=False,  # ticks along the top edge are off
            labelbottom=False)  # labels along the bottom edge are off
        plt.title(s, fontsize=15)

    plt.tight_layout()
    if save:
        plt.savefig(os.path.join(PLOT_DIR_PATH, f"shapes.pdf"),
                    bbox_inches="tight")
    if show:
        plt.show()
Esempio n. 2
0
class Voice2Midi(object):
    def __init__(self):
        self._synth = Synth()
        self._onset_detector = OnsetDetector()
        self._f0_detector = F0Detector()
        self._wf = wave.open('audio_files/vocal2.wav', 'rb')
        self._p = PyAudio()
        self._e = threading.Event()
        self._input_buffer = []
        self._stream = self._p.open(format=self._p.get_format_from_width(
            self._wf.getsampwidth()),
                                    channels=self._wf.getnchannels(),
                                    rate=self._wf.getframerate(),
                                    output=True,
                                    frames_per_buffer=WINDOW_SIZE,
                                    stream_callback=self._process_frame)

    def run(self):
        print(self._wf.getframerate())

        self._synth.run()  #main loop of the synth

        self._stream.stop_stream()
        self._stream.close()
        self._p.terminate()

    def _process_frame(self, in_data, frame_count, time_info, status_flag):
        data = self._wf.readframes(frame_count)
        data_array = np.frombuffer(data, dtype=np.int32)
        if np.shape(data_array)[0] == WINDOW_SIZE and np.shape(
                np.nonzero(data_array))[1] > 0:
            # print(np.shape(np.nonzero(data_array))[1])
            data_array = data_array.astype('float32')
            data_array = data_array / np.max(data_array)

            # onset = self._onset_detector.find_onset(data_array)
            if self._onset_detector.find_onset(data_array):
                freq0 = self._f0_detector.find_f0(data_array)
                if freq0:
                    # Onset detected
                    print("Note detected; fundamental frequency: ", freq0)
                    midi_note_value = int(hz_to_midi(freq0)[0])
                    print("Midi note value: ", midi_note_value)
                    note = RTNote(midi_note_value, 100, 0.5)
                    self._synth.set_new_note(note)
                    self._synth.e.set()
            return data, paContinue
        else:
            print("Sending over")
            return data, paComplete
Esempio n. 3
0
 def __init__(self):
     self._synth = Synth()
     self._onset_detector = OnsetDetector()
     self._f0_detector = F0Detector()
     self._wf = wave.open('audio_files/vocal2.wav', 'rb')
     self._p = PyAudio()
     self._e = threading.Event()
     self._input_buffer = []
     self._stream = self._p.open(format=self._p.get_format_from_width(
         self._wf.getsampwidth()),
                                 channels=self._wf.getnchannels(),
                                 rate=self._wf.getframerate(),
                                 output=True,
                                 frames_per_buffer=WINDOW_SIZE,
                                 stream_callback=self._process_frame)
Esempio n. 4
0
    def __init__(self, seed, synthName='../FluidR3_GM.sf2'):
        random.seed(seed)

        self.synth = Synth(synthName)
        self.set_cpb(10, 0, 0)
        self.cur_idx = 0
        self.set_num_notes_per_beat(kDefaultNumNotesPerBeat)
Esempio n. 5
0
    def __init__(self, parent=None, notes=None, volumes=None):
        super(MainWindow, self).__init__(parent=parent)

        self.resize(800, 600)

        self.layout = QHBoxLayout()

        self.plot = WavePlot(self)
        self.layout.addWidget(self.plot)

        self.freq = Frequencies(self, frequencies=notes, amplitudes=volumes)
        self.layout.addWidget(self.freq)

        self.setLayout(self.layout)

        self.synth = Synth([], update_hz=10)
        self.synth.start()
Esempio n. 6
0
def test_writeMono():
    
    synth = Synth(44100)
    
    synth.noteOn(60)

    out = []
        
    for _ in range(4410):
        out.append(synth.getSample())
        
    synth.noteOff(60)
    
    writeMono("test_writeMono.wav", out, 44100)
Esempio n. 7
0
 def __init__(self, master):
     self.root = master
     self.root.resizable(False, False)
     self.root.title("pyImprov")
     self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
     self.synth = Synth()
     self.content = ttk.Frame(self.root)
     self.length_label = Label(self.content, text="Set length")
     self.length_text = Text(self.content, height=1, width=14)
     self.meter_label = Label(self.content, text="Set meter")
     self.meter_variable = StringVar(self.root)
     self.meter_variable.set("4/4")
     self.meter_menu = OptionMenu(self.content, self.meter_variable, "4/4",
                                  "3/4")
     self.scale_label = Label(self.content, text="Set scale")
     self.scale_variable = StringVar(self.root)
     self.scale_variable.set("Pentatonic")
     self.scale_menu = OptionMenu(self.content, self.scale_variable,
                                  "Pentatonic", "Blues", "Major", "Minor")
     self.tonic_label = Label(self.content, text="Set tonic")
     self.tonic_variable = StringVar(self.root)
     self.tonic_variable.set("C")
     self.tonic_menu = OptionMenu(self.content, self.tonic_variable, "A",
                                  "A#", "B", "C", "C#", "D", "D#", "E", "F",
                                  "F#", "G", "G#")
     self.tempo_label = Label(self.content, text="Set tempo")
     self.tempo_text = Text(self.content, height=1, width=14)
     self.instrument_label = Label(self.content, text="Set instrument")
     self.instrument_variable = StringVar(self.root)
     self.instrument_variable.set("Piano")
     self.instrument_menu = OptionMenu(self.content,
                                       self.instrument_variable, "Piano",
                                       "Plucked", "Sawtooth", "Square",
                                       "Rhodes")
     self.filename_label = Label(self.content, text="Set name")
     self.filename_text = Text(self.content, height=1, width=14)
     self.separator_label = Label(self.content)
     self.status_label = Label(self.content)
     self.button = Button(self.content,
                          text="Create",
                          width=16,
                          height=2,
                          command=self.on_click)
     self.content.grid(column=0, row=0)
     self.length_label.grid(column=0, row=0)
     self.length_text.insert(END, "30")
     self.length_text.grid(column=1, row=0)
     self.meter_label.grid(column=0, row=1)
     self.meter_menu.grid(column=1, row=1)
     self.scale_label.grid(column=0, row=2)
     self.scale_menu.grid(column=1, row=2)
     self.tonic_label.grid(column=0, row=3)
     self.tonic_menu.grid(column=1, row=3)
     self.tempo_label.grid(column=0, row=4)
     self.tempo_text.insert(END, "150")
     self.tempo_text.grid(column=1, row=4)
     self.instrument_label.grid(column=0, row=5)
     self.instrument_menu.grid(column=1, row=5)
     self.filename_label.grid(column=0, row=6)
     self.filename_text.insert(END, "output")
     self.filename_text.grid(column=1, row=6)
     self.separator_label.grid(column=0, row=7, columnspan=2)
     self.status_label.grid(column=0, row=8, columnspan=2)
     self.button.grid(column=0, row=9, columnspan=2)
     self.content.pack(padx=10, pady=11)
     self.separator_label.config(text=" ")
     self.status_label.config(text="Ready")
Esempio n. 8
0
# $ gcloud preview app run ./app.yaml
# $ gcloud preview app deploy .yaml

from flask import Flask, helpers
import subprocess
import tempfile

from synth import Synth

app = Flask(__name__)
app.debug = True

synth = Synth()

MESSAGES = '/tmp/messages.txt'


@app.route("/")
def fortune():
    msg = subprocess.check_output('/usr/games/fortune')
    with open(MESSAGES, 'a') as f:
        f.write(msg)
    with tempfile.NamedTemporaryFile() as f:
        synth.say(msg, out=f)
        return helpers.send_file(f.name,
                                 mimetype="audio/wav",
                                 as_attachment=False)


@app.route("/messages")
def messages():
Esempio n. 9
0
#this should be the camera
cap = cv2.VideoCapture(0)

fgbg = cv2.BackgroundSubtractorMOG()

trained_hand = False
trained_dollar = True

pointing_threshold = 50

hand_hist = None
dollar_hist = None

ret, frame1 = cap.read()
syn = Synth(len(frame1), len(frame1[0]))

start_timer = 0
cv2.namedWindow('frame', cv2.WINDOW_AUTOSIZE)

frame_num = 0
frame_len = 10

def addKeyboard(img):
    xlen = len(img[0])
    ylen = len(img)

    note = syn.NUM_NOTES - syn.currNote - 1

    cv2.rectangle(img,(0,0),(xlen,ylen),(0,255,0),3)
Esempio n. 10
0
# register JLAT
from book import Books
app.register_blueprint(
    Books(url_prefix="/",
          dir_books=os.path.join(JLAT_DIR, "files", "uploads", "book")))
from note import Notes
app.register_blueprint(Notes(url_prefix="/"))
from review import Reviews
app.register_blueprint(Reviews(url_prefix="/"))
from up import Ups
app.register_blueprint(
    Ups(url_prefix='/',
        dir_uploads=os.path.join(JLAT_DIR, "files", "uploads", "import")))
from synth import Synth
app.register_blueprint(Synth(url_prefix='/'))
from history import History
app.register_blueprint(
    History(url_prefix='/',
            archives=os.path.join(JLAT_DIR, "files", "archives")))
from register import Register
app.register_blueprint(Register(url_prefix='/'))


@app.route("/", methods=["GET", "POST"])
@login_required
def home():
    return render_template('index.html')


if __name__ == "__main__":
Esempio n. 11
0
class BaseGenerator(object):

    def __init__(self, seed, synthName='../FluidR3_GM.sf2'):
        random.seed(seed)

        self.synth = Synth(synthName)
        self.set_cpb(10, 0, 0)
        self.cur_idx = 0
        self.set_num_notes_per_beat(kDefaultNumNotesPerBeat)
        #self.synth.set_reverb_on(True)

    # Subclasses should override this
    # can return an array of scalars, or an
    # array of chords, or a mixture
    def get_notes_list(self):
        return []

    # Subclasses should override this
    def get_note_velocity(self):
        return 60

    def set_cpb(self, channel, bank, preset):
        self.channel = channel
        cbp = (self.channel, bank, preset)
        self.synth.program(*cbp)

    def set_cc(self, channel, control, value):
        self.synth.cc(channel, control, value)

    def set_num_notes_per_beat(self, notesPerBeat):
        self.notesPerBeat = notesPerBeat
        self.ticksPerNote = int(kTicksPerBeat / notesPerBeat)

    # Internal method
    def get_frames(self):
        # Actual script
        # frames
        data_frames = []
         # start generating things
        currentTick = 0
        lastTick = 0
        stopGeneration = False
        pendingOffticks = []
        deltaTicks = 0
        envelope_final_frames = 1000 # leave some frames for the note_off envelope

        currentNotes = self.get_notes_list()

        while stopGeneration is not True:
            # First, generate ticks up to this point
            new_frames, good = self.synth.generate(deltaTicks * kFramesPerTick)

            # check if we're done, before committing new frames
            if self.cur_idx >= len(currentNotes) and len(pendingOffticks) < 1:
                if np.absolute(new_frames).max() <= 0.001:
                    stopGeneration = True
                    continue

            data_frames = np.append(data_frames, new_frames)

            # Apply config changes for this new tick
            if self.cur_idx < len(currentNotes) and currentTick % self.ticksPerNote == 0:
                # do the next _note_on
                (offTick, pitch) = self._noteon(currentTick)
                if offTick > 0:
                    pendingOffticks.append((offTick, pitch))
            if len(pendingOffticks) > 0:
                if pendingOffticks[0][0] <= currentTick:
                    (offTick, pitch) = pendingOffticks.pop(0)
                    self._noteoff(offTick, pitch)
            

            # get the next tick
            lastTick = currentTick
            tickOfNextNote = int((currentTick + self.ticksPerNote) / self.ticksPerNote) * self.ticksPerNote
            nextTick = tickOfNextNote
            if len(pendingOffticks) > 0:
                currentTick = min(nextTick, pendingOffticks[0][0])
            else:
                currentTick = nextTick
            deltaTicks = currentTick - lastTick

        return data_frames

    # noteset is either a single midi pitch or
    # a list of midi pitches, based on the implementation
    # of get_notes_list
    def _get_next_noteset(self):
        currentNotes = self.get_notes_list()
        noteset = currentNotes[self.cur_idx]

        notes_len = len(currentNotes)

        # Zeroes in the sequence mark sustains.
        duration = 1
        for i in range(self.cur_idx+1, notes_len):
            if currentNotes[i] is 0:
                duration += 1
            else:
                break

        # advance index
        self.cur_idx += 1

        return noteset, duration

    # returns off tick
    def _noteon(self, tick):
        noteset, note_duration = self._get_next_noteset()
        if isinstance(noteset, list):
            for value in noteset:
                pitch = value
                # play note on:
                noteVelocity = self.get_note_velocity()
                self.synth.noteon(self.channel, pitch, int(noteVelocity))
            # post note-off:
            off_tick = tick + note_duration * self.ticksPerNote
            return (off_tick, noteset)
        else:
            pitch = noteset
            if pitch not in [0, -1]:
                # play note on:
                noteVelocity = self.get_note_velocity()
                self.synth.noteon(self.channel, pitch, int(noteVelocity))
                # post note-off:
                off_tick = tick + note_duration * self.ticksPerNote
                return (off_tick, pitch)
            return (-1, pitch)

    def _noteoff(self, tick, noteset):
        if isinstance(noteset, list):
            for value in noteset:
                pitch = value
                self.synth.noteoff(self.channel, pitch)
        else:
            self.synth.noteoff(self.channel, noteset)


    # Used by Main
    def get_config(self):
        notesToConfig = []
        # generate sixteenth notes. Our notes list may be in quarter notes, etc.
        # depending on our notesPerBeat
        extraNoteRatio = float(kDefaultNumNotesPerBeat) / float(self.notesPerBeat)
        if extraNoteRatio < 1:
            print "We don't support so few notes ;("
        notesList = self.get_notes_list()
        for i in xrange(0, int(len(notesList) * extraNoteRatio)):
            relevantIndex = int(i / extraNoteRatio)
            note = notesList[relevantIndex]
            if extraNoteRatio > 1:
                if i % extraNoteRatio != 0:
                    if note != -1:
                        notesToConfig.append("0")
                        continue
            if isinstance(note, list):
                notesToConfig.append(str(sum(note)))
            else:
                notesToConfig.append(str(note))

        return " ".join(notesToConfig)
Esempio n. 12
0
#this should be the camera
cap = cv2.VideoCapture(0)

fgbg = cv2.BackgroundSubtractorMOG()

trained_hand = False
trained_dollar = True

pointing_threshold = 50

hand_hist = None
dollar_hist = None

ret, frame1 = cap.read()
syn = Synth(len(frame1), len(frame1[0]))

start_timer = 0
cv2.namedWindow('frame', cv2.WINDOW_AUTOSIZE)

frame_num = 0
frame_len = 10


def addKeyboard(img):
    xlen = len(img[0])
    ylen = len(img)

    note = syn.NUM_NOTES - syn.currNote - 1

    cv2.rectangle(img, (0, 0), (xlen, ylen), (0, 255, 0), 3)
Esempio n. 13
0
from flask import Flask, Response, request, render_template
from synth import Synth
app = Flask(__name__, template_folder='', static_folder='', static_url_path='')


@app.route("/")
def main():
    return render_template('synth.html')


@app.route("/synthesize")
def syn():
    text = request.args.get('text')
    wave = s.synth(text)
    return Response(wave, mimetype='audio/wav')


s = Synth()
if __name__ == "__main__":
    app.run(host="0.0.0.0")
Esempio n. 14
0
# -*- coding: utf-8 -*-
import sys
import os
import traceback
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
from synth import Synth

success = True
wd = webdriver.Firefox()
wd.implicitly_wait(60)

monitor = Synth(wd, os.path.basename(sys.argv[0]).replace(' ', '_'))

def is_alert_present(wd):
    try:
        wd.switch_to_alert().text
        return True
    except:
        return False

try:
    monitor.StartTx("test")
    wd.get("http://www.sebuilder.com/")
    print wd.execute_script(performance.timing)
    monitor.StopTx("test")
except:
    monitor.FailTx('null', 'ERROR', traceback.format_exc(3))
finally:
Esempio n. 15
0
p = pyaudio.PyAudio()

stream = p.open(format=2,
                channels=1,
                rate=44100,
                output=True,
                output_device_index=0)

RATE = 44100
NOTE = 440
NOTE_LENGTH = 10

pygame.init()
pygame.midi.init()

synth = Synth()

running = True
screen = pygame.display.set_mode((240, 180))
input = pygame.midi.Input(3)
for index in range(pygame.midi.get_count()):
    print(pygame.midi.get_device_info(index))

controls = {
    1: {
        'name': 'attack',
        'max': 100000
    },
    2: {
        'name': 'decay',
        'max': 100000
Esempio n. 16
0
class App(object):
    def __init__(self, Iface, *args, **kwargs):
        super(App).__init__(*args, **kwargs)
        self.stop = False
        self.log = logging.getLogger(LOGGER_NAME)

        self.log.debug('Initializing Input...')
        self._init_input()

        self.log.debug('Initializing synth...')
        self._init_synth()

        self.log.debug('Initializing Interface...')
        self.IfaceType = Iface
        self._init_interface()

    def _init_input(self):
        self.input_queue = EventQueue()
        self.input = KeyboardInput(self.input_queue)
        self.input.start()

        self.input_thread = threading.Thread(target=self._process_input_queue)
        self.input_thread.start()

    def _process_input_queue(self):
        while not self.stop:
            event = self.input_queue.get()  # Blocking

            self.log.debug(f'Got event {event}')

            item = event.item

            if event.type.startswith(EVT_SYS):
                if item == EXIT_ITEM:
                    self._terminate()

            if event.type.startswith(EVT_KEY):
                if item in keyboard_note_table:
                    note, octave = keyboard_note_table[item]

                    new_event = Event(event_type_midi_action[event.type](
                        note, octave, 127),
                                      midi.EVT_MIDI,
                                      ancestor=event,
                                      timestamp=time.time())

                    self.synth_queue.put(new_event)
                else:
                    if item == EXIT_KEY:
                        self.input_queue.put(
                            Event(EXIT_ITEM,
                                  EVT_SYS,
                                  ancestor=event,
                                  timestamp=time.time()))

        self.log.debug('Exiting input Thread loop...')

    def _init_interface(self):
        self.interface = self.IfaceType(self.synth, log=self.log)
        self.interface.start(exit_action=self.exit)

    def _init_synth(self):
        self.synth = Synth(log=self.log)
        self.synth_queue = self.synth.input_queue

    def _terminate(self):
        self.log.debug("Terminating app...")
        self.stop = True

        self.log.debug("Terminating Input...")
        self.input.stop()

        self.log.debug("Terminating Synth...")
        self.synth.terminate()

        if threading.get_ident() != self.input_thread.ident:
            self.log.debug('Stopping input Thread...')
            self.input_thread.join()

        self.log.debug("Terminating Interface...")
        self.interface.stop()

        self.log.debug("Finished terminating app!")

    def exit(self):
        self.input_queue.put(EXIT_EVENT)
Esempio n. 17
0
 def _init_synth(self):
     self.synth = Synth(log=self.log)
     self.synth_queue = self.synth.input_queue
Esempio n. 18
0
def generate():
    if request.remote_addr not in ip_set:
        oid = randint(100000, 999999)
        ip_set[request.remote_addr] = oid
        s = Synth()
        if request.args.get("length") is not None:
            s.set_length(request.args.get("length"))
        if request.args.get("meter") is not None:
            s.set_meter(request.args.get("meter"))
        if request.args.get("scale") is not None:
            if request.args.get("tonic") is not None:
                s.set_scale(request.args.get("scale"),
                            request.args.get("tonic"))
            else:
                s.set_scale(request.args.get("scale"), "C")
        if request.args.get("tempo") is not None:
            s.set_tempo(request.args.get("tempo"))
        if request.args.get("instrument") is not None:
            s.set_instrument(request.args.get("instrument"))
        s.create(oid)
        ip_set.pop(request.remote_addr)
    else:
        oid = ip_set[request.remote_addr]
        while request.remote_addr in ip_set:
            return redirect('/', code=302)
    path = '/wav/' + str(oid) + '.wav'
    return redirect(path, code=302)
Esempio n. 19
0
def main():
    options = options_play.get_options()
    samplerate = options["samplerate"]
    sd.default.samplerate = samplerate
    synth = Synth(no_of_voices=options["no_of_voices"],
                  no_of_bass_voices=1,
                  waveform=options["waveform"],
                  samplerate=samplerate,
                  transposition_factor=options["transposition_factor"],
                  attack_time=options["attack_time"],
                  release_time=options["release_time"],
                  decay_time=options["decay_time"],
                  after_decay_level=options["after_decay_level"],
                  bass_attack_time=options["bass_attack_time"],
                  bass_release_time=options["bass_release_time"],
                  bass_decay_time=options["bass_decay_time"],
                  bass_after_decay_level=options["bass_after_decay_level"],
                  bass_transposition_factor=1.0,
                  volume=options["volume"])

    # set-up pygame dislay
    full_screen = options["fullscreen"]
    pygame.init()
    if full_screen:
        os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0"
        info = pygame.display.Info()
        options["size_x"] = info.current_w
        options["size_y"] = info.current_h
        display = pygame.display.set_mode((info.current_w, info.current_h),
                                          pygame.NOFRAME)
    else:
        display = pygame.display.set_mode(
            (options["size_x"], options["size_y"]))

    freq_board = FrequencyBoard(
        options["size_x"],
        options["size_y"],
        filename=options["frequency_board"],
        transition_size=options["transition_size"],
        wildcard_frequency=options["wildcard_frequency"],
        shuffle_row_frequencies=options["shuffle_row_frequencies"])

    for ix in range(options["size_x"]):
        for iy in range(options["size_y"]):
            color = freq_board.colors[iy][ix][::-1]
            display.set_at((ix, iy), color)
    pygame.display.update()

    # initialize variables
    running = True
    is_sliding = False
    bass_hold = False
    current_bass_key = None

    current_bass_keys = Set([])
    bass_frequencies = freq_board.get_bass_frequencies(
        options["bass_frequencies_filename"])
    bass_keys = get_bass_keys()
    bass_change = 2.0**(1.0 / 96.0)

    bass_change_pressed = False

    with sd.OutputStream(channels=1, callback=synth, samplerate=samplerate):
        while running:
            sd.sleep(1)
            keys = pygame.key.get_pressed()

            # bass transpose
            if keys[pygame.K_SPACE] and (not bass_change_pressed):
                synth.bass_transposition_factor /= bass_change
                print("transpose bass down " +
                      str(synth.bass_transposition_factor))
                bass_change_pressed = True
            elif keys[pygame.K_LSHIFT] and (not bass_change_pressed):
                synth.bass_transposition_factor *= bass_change
                bass_change_pressed = True
                print("transpose bass up " +
                      str(synth.bass_transposition_factor))

            if not (keys[pygame.K_SPACE]
                    or keys[pygame.K_LSHIFT]) and bass_change_pressed:
                bass_change_pressed = False

            for key in list(current_bass_keys):
                if not keys[key]:
                    current_bass_keys = Set([])
                    break

            for bass_index, bass_key in enumerate(bass_keys):
                if keys[bass_key]:
                    if not bass_key in current_bass_keys:
                        synth.set_bass_frequency(bass_frequencies[bass_index])
                        current_bass_keys.add(bass_key)
                        current_bass_key = bass_key
                        synth.start_bass_envelope = True
                        current_bass_key = bass_key
                        bass_hold = True

            if len(current_bass_keys) == 0 and bass_hold:
                bass_hold = False
                synth.release_bass_envelope = True

            for event in pygame.event.get():
                if event.type == pygame.MOUSEMOTION:
                    if is_sliding:
                        pos = pygame.mouse.get_pos()
                        pos_x = pos[0]
                        pos_y = pos[1]
                        freq = freq_board.frequencies[pos_y][pos_x]
                        synth.set_frequency(freq)

                # mouse buttons are pressed
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button in [1, 3]:
                        is_sliding = True
                        pos = pygame.mouse.get_pos()
                        pos_x = pos[0]
                        pos_y = pos[1]
                        freq = freq_board.frequencies[pos_y][pos_x]
                        synth.set_frequency(freq)
                        synth.start_envelope = True

                if event.type == pygame.MOUSEBUTTONUP:
                    if event.button in [1, 3]:
                        is_sliding = False
                        synth.release_envelope = True

                if event.type == pygame.QUIT or keys[pygame.K_ESCAPE]:
                    running = False