Tightened the source code and README documentations in the library.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension Sound {
|
||||
/// A bank of synth voices for playing a sequence track. Wraps
|
||||
/// `PDSynthInstrument`.
|
||||
/// A pool of synth voices for polyphonic playback. Wraps `PDSynthInstrument`.
|
||||
/// Keeps added voices alive.
|
||||
public final class Instrument {
|
||||
private static var api: UnsafePointer<playdate_sound_instrument> { Playdate.instrumentAPI.unsafelyUnwrapped }
|
||||
|
||||
@@ -26,9 +26,8 @@ extension Sound {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a voice to the instrument, handling notes in
|
||||
/// `rangeStart...rangeEnd` (0...127 handles all notes), transposed by
|
||||
/// `transpose` half-steps.
|
||||
/// Voices notes `rangeStart...rangeEnd`, transposed `transpose` half-steps on top of
|
||||
/// the instrument. Returns `false` if `synth` has another instrument or channel.
|
||||
@discardableResult
|
||||
public func addVoice(_ synth: Synth, rangeStart: MIDINote = 0, rangeEnd: MIDINote = 127,
|
||||
transpose: Float = 0) -> Bool {
|
||||
@@ -40,8 +39,8 @@ extension Sound {
|
||||
return added
|
||||
}
|
||||
|
||||
/// Plays a note at `frequency` Hz on an available voice. Returns the
|
||||
/// synth used, if any.
|
||||
/// Uses the next free voice, else the one released or playing longest. Arguments
|
||||
/// as in `Synth.playNote`. Returns the voice used, if any.
|
||||
@discardableResult
|
||||
public func playNote(frequency: Float, velocity: Float = 1,
|
||||
length: Float? = nil, when: UInt32 = 0) -> Synth? {
|
||||
@@ -50,7 +49,7 @@ extension Sound {
|
||||
return voice(for: synth)
|
||||
}
|
||||
|
||||
/// Plays a MIDI note on an available voice. Returns the synth used.
|
||||
/// Like `playNote(frequency:velocity:length:when:)`; returns the voice used, if any.
|
||||
@discardableResult
|
||||
public func playMIDINote(_ note: MIDINote, velocity: Float = 1,
|
||||
length: Float? = nil, when: UInt32 = 0) -> Synth? {
|
||||
@@ -67,33 +66,32 @@ extension Sound {
|
||||
return Synth(pointer: pointer, isOwned: false)
|
||||
}
|
||||
|
||||
/// Bends played notes by `bend` × the pitch bend range.
|
||||
/// A fraction of the pitch bend range.
|
||||
public func setPitchBend(_ bend: Float) {
|
||||
Instrument.api.pointee.setPitchBend.unsafelyUnwrapped(pointer, bend)
|
||||
}
|
||||
|
||||
/// The range of `setPitchBend(_:)`, in half-steps.
|
||||
/// The range of `setPitchBend(_:)`; default 12.
|
||||
public func setPitchBendRange(halfSteps: Float) {
|
||||
Instrument.api.pointee.setPitchBendRange.unsafelyUnwrapped(pointer, halfSteps)
|
||||
}
|
||||
|
||||
/// Transposes played notes by `halfSteps` (fractional values
|
||||
/// allowed).
|
||||
/// Transposes all voices; fractional values allowed.
|
||||
public func setTranspose(halfSteps: Float) {
|
||||
Instrument.api.pointee.setTranspose.unsafelyUnwrapped(pointer, halfSteps)
|
||||
}
|
||||
|
||||
/// Releases the voice playing `note` at time `when` (0 = now).
|
||||
/// Releases the voice playing `note` at audio-clock time `when`, or now if 0.
|
||||
public func noteOff(_ note: MIDINote, when: UInt32 = 0) {
|
||||
Instrument.api.pointee.noteOff.unsafelyUnwrapped(pointer, note, when)
|
||||
}
|
||||
|
||||
/// Releases every playing voice at time `when` (0 = now).
|
||||
/// Releases every voice at audio-clock time `when`, or now if 0.
|
||||
public func allNotesOff(when: UInt32 = 0) {
|
||||
Instrument.api.pointee.allNotesOff.unsafelyUnwrapped(pointer, when)
|
||||
}
|
||||
|
||||
/// The volume of the left and right channels, 0...1.
|
||||
/// Left and right volume, 0...1.
|
||||
public var volume: (left: Float, right: Float) {
|
||||
get {
|
||||
var left: Float = 0, right: Float = 0
|
||||
@@ -103,7 +101,6 @@ extension Sound {
|
||||
set { Instrument.api.pointee.setVolume.unsafelyUnwrapped(pointer, newValue.left, newValue.right) }
|
||||
}
|
||||
|
||||
/// The number of voices currently playing.
|
||||
public var activeVoiceCount: Int {
|
||||
Int(Instrument.api.pointee.activeVoiceCount.unsafelyUnwrapped(pointer))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user