Skip to content

Commit

Permalink
GitHub Action to spellcheck and lint Python code
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Apr 27, 2024
1 parent 16df212 commit 7906c5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: ci
on: [pull_request, push]
jobs:
codespell_and_ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install --user codespell[toml] ruff
- run: codespell **/*.py **/*.txt --skip="venv/lib/python3*"
- run: ruff check --output-format=github --target-version=py38 .
ci:
strategy:
fail-fast: false
Expand Down
28 changes: 17 additions & 11 deletions fluidsynth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
================================================================================
"""

from ctypes import *
from ctypes import (
CDLL, CFUNCTYPE, POINTER, Structure, byref, c_void_p, create_string_buffer, c_char,
c_char_p, c_double, c_float, c_int, c_short, c_uint
)
from ctypes.util import find_library
import os

Expand Down Expand Up @@ -711,7 +714,7 @@ def start(self, driver=None, device=None, midi_driver=None, midi_router=None):
new_fluid_cmd_handler(self.synth, self.router)
else:
fluid_synth_set_midi_router(self.synth, self.router)
if midi_router == None: ## Use fluidsynth to create a MIDI event handler
if midi_router is None: ## Use fluidsynth to create a MIDI event handler
self.midi_driver = new_fluid_midi_driver(self.settings, fluid_midi_router_handle_midi_event, self.router)
self.custom_router_callback = None
else: ## Supply an external MIDI event handler
Expand Down Expand Up @@ -880,7 +883,7 @@ def set_chorus_level(self, level):
if fluid_synth_set_chorus_level is not None:
return fluid_synth_set_chorus_level(self.synth, level)
else:
return self.set_chorus(leve=level)
return self.set_chorus(level=level)
def set_chorus_speed(self, speed):
if fluid_synth_set_chorus_speed is not None:

Check failure on line 888 in fluidsynth.py

View workflow job for this annotation

GitHub Actions / codespell_and_ruff

Ruff (F821)

fluidsynth.py:888:12: F821 Undefined name `fluid_synth_set_chorus_speed`
return fluid_synth_set_chorus_speed(self.synth, speed)

Check failure on line 889 in fluidsynth.py

View workflow job for this annotation

GitHub Actions / codespell_and_ruff

Ruff (F821)

fluidsynth.py:889:20: F821 Undefined name `fluid_synth_set_chorus_speed`
Expand Down Expand Up @@ -996,7 +999,7 @@ def get_samples(self, len=1024):
"""
return fluid_synth_write_s16_stereo(self.synth, len)
def tuning_dump(self, bank, prog, pitch):
return fluid_synth_tuning_dump(self.synth, bank, prog, name.encode(), length(name), pitch)
return fluid_synth_tuning_dump(self.synth, bank, prog, name.encode(), len(name), pitch)

Check failure on line 1002 in fluidsynth.py

View workflow job for this annotation

GitHub Actions / codespell_and_ruff

Ruff (F821)

fluidsynth.py:1002:64: F821 Undefined name `name`

Check failure on line 1002 in fluidsynth.py

View workflow job for this annotation

GitHub Actions / codespell_and_ruff

Ruff (F821)

fluidsynth.py:1002:83: F821 Undefined name `name`

def midi_event_get_type(self, event):
return fluid_midi_event_get_type(event)
Expand All @@ -1015,17 +1018,20 @@ def midi_event_get_value(self, event):

def play_midi_file(self, filename):
self.player = new_fluid_player(self.synth)
if self.player == None: return FLUID_FAILED
if self.custom_router_callback != None:
if self.player is None:
return FLUID_FAILED
if self.custom_router_callback is not None:
fluid_player_set_playback_callback(self.player, self.custom_router_callback, self.synth)
status = fluid_player_add(self.player, filename.encode())
if status == FLUID_FAILED: return status
if status == FLUID_FAILED:
return status
status = fluid_player_play(self.player)
return status

def play_midi_stop(self):
status = fluid_player_stop(self.player)
if status == FLUID_FAILED: return status
if status == FLUID_FAILED:
return status
status = fluid_player_seek(self.player, 0)
delete_fluid_player(self.player)
return status
Expand All @@ -1050,14 +1056,14 @@ def __init__(self, time_scale=1000, use_system_timer=True):
def register_fluidsynth(self, synth):
response = fluid_sequencer_register_fluidsynth(self.sequencer, synth.synth)
if response == FLUID_FAILED:
raise Error("Registering fluid synth failed")
raise Exception("Registering fluid synth failed")
return response

def register_client(self, name, callback, data=None):
c_callback = CFUNCTYPE(None, c_uint, c_void_p, c_void_p, c_void_p)(callback)
response = fluid_sequencer_register_client(self.sequencer, name.encode(), c_callback, data)
if response == FLUID_FAILED:
raise Error("Registering client failed")
raise Exception("Registering client failed")

# store in a list to prevent garbage collection
self.client_callbacks.append(c_callback)
Expand Down Expand Up @@ -1097,7 +1103,7 @@ def _create_event(self, source=-1, dest=-1):
def _schedule_event(self, evt, time, absolute=True):
response = fluid_sequencer_send_at(self.sequencer, evt, time, absolute)
if response == FLUID_FAILED:
raise Error("Scheduling event failed")
raise Exception("Scheduling event failed")

def get_tick(self):
return fluid_sequencer_get_tick(self.sequencer)
Expand Down
1 change: 0 additions & 1 deletion test/sequencerTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import time
import fluidsynth
from ctypes import *

seqduration = 1000

Expand Down

0 comments on commit 7906c5e

Please sign in to comment.