MIDISequencer 0.0.4

MIDISequencer 0.0.4

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布最新发布2018年1月
SwiftSwift版本3.0
SPM支持SPM

Cem OlcayAurelius Prochazka维护。



 
依赖
AudioKit>= 0
MusicTheorySwift>= 0
 

  • 作者:
  • cemolcay

MIDISequencer

MIDI Sequencer,向其他应用程序发送MIDI事件。
基于iOS和macOS的AudioKitAKSequencer构建。
只需专注于音符,即可创建智能MIDI旋律乐器。

要求

  • Swift 3.0+
  • iOS 9.0+
  • macOS 10.11+

安装

pod 'MIDISequencer'

用法

MIDISequencer在AudioKitAKSequencer上构建,并使用MusicTheory库创建专注于音符的序列,支持多轨道。

  • 创建一个MIDISequencer实例。
let sequencer = MIDISequencer(name: "Awesome Sequencer")
  • 创建一个MIDISequencerTrack并将其添加到序列器的轨道中。
let track = MIDISequencerTrack(
	name: "Track 1", 
	midiChannel: 1)
sequencer.tracks.append(track)
  • 设置节奏和拍号
sequencer.tempo = Tempo(
  timeSignature: TimeSignature(
    beats: 4,
    noteValue: .quarter),
  bpm: 80)
  • 将一些MIDISequencerStep添加到轨道的steps
track.steps = [
	MIDISequencerStep(
	  note: Note(type: .c, octave: 4),
	  noteValue: NoteValue(type: .quarter),
	  velocity: .standard(100)),
	MIDISequencerStep(
	  note: Note(type: .d, octave: 4),
	  noteValue: NoteValue(type: .quarter),
	  velocity: .standard(100)),
	MIDISequencerStep(
	  note: Note(type: .e, octave: 4),
	  noteValue: NoteValue(type: .quarter),
	  velocity: .standard(100)),
	MIDISequencerStep(
	  note: Note(type: .f, octave: 4),
	  noteValue: NoteValue(type: .quarter),
	  velocity: .standard(100)),
	]
sequencer.addTrack(track: track1)
  • 您甚至可以向任何步骤添加和弦、多个音符或两者。
MIDISequencerStep(
  chord: Chord(type: .maj, key: .c),
  octave: 4,
  noteValue: NoteValue(type: .quarter),
  velocity: .standard(60))
  
MIDISequencerStep(
  notes: [Note(type: .c, octave: 4), Note(type: .d, octave: 4)],
  octave: 4,
  noteValue: NoteValue(type: .quarter),
  velocity: .standard(60))
  
MIDISequencerStep(
  notes: Chord(type: .maj, key: .c).notes(octave: 4) + [Note(type: .c, octave: 4), Note(type: .d, octave: 4)],
  noteValue: NoteValue(type: .quarter),
  velocity: .standard(60))
  • 使用MIDISequencerArpeggiator将和弦、任何八度范围内的音阶中的任何音符创建成琶音步骤。
let arpeggiator = MIDISequencerArpeggiator(
  scale: Scale(type: .blues, key: .a),
  arpeggio: .random,
  octaves: [4, 5])

let melody = MIDISequencerTrack(
  name: "Melody",
  midiChannel: 3,
  steps: arpeggiator.steps(noteValue: NoteValue(type: .quarter), velocity: .random(min: 80, max: 120)))

sequencer.addTrack(track: melody)
  • isMuted属性设置为true以静音任何MIDISequencerStep

  • 调用play()playAsync()中的一个函数来播放序列。

state = .loading
sequancer.playAsync(completion: {
	self.state = .playing
})
  • 调用stop()停止播放。
sequencer.stop()

文档

查看完整文档

AppStore

在我的应用程序ChordBud中使用此库,查看它!

alt tag