BBGroover 0.1.0

BBGroover 0.1.0

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2014年12月

Parker Wightman 维护。



BBGroover 0.1.0

  • 作者:
  • Parker

一个易于使用的打击乐调度/序列库。请看它的工作视频(请原谅音频不同步)。

安装

BBGroover/Grooving 文件夹中的所有文件复制到您的项目中。BBGroover 使用 ARC,所以如果您的项目未使用 ARC,请确保将 -fobjc-arc 编译器标志包含在 Grooving 文件夹中的每个文件中。我计划不久创建 CocoaPods spec。

此项目使用最新 LLVM 编译器中可用的 Objective-C 功能,如对象字面量和自动合成。仅与 Xcode 4.5+ 兼容。

用法

下面的示例代码是从该存储库中包含的示例项目中提取的。

BBVoice

一个声音是一个逻辑播放单元,例如低音鼓、嗵鼓或钹。根据“击打”位置创建所需数量的声音,并使用一个表示声音“击打”位置的值数组。

NSArray *values = @[ @NO,  @NO,  @YES, @YES ];
BBVoice *snare = [[BBVoice alloc] initWithValues:values];
snare.name = @"Snare drum";
snare.audioPath = @"snare.wav";

您也可以创建一个空声音,并仅标识部分。

BBVoice *hihat = [[BBVoice alloc] initWithSubdivision:BBGrooverBeatEighth];
hihat.name = @"Hi Hat";
hihat.audioPath = @"hihat.wav";

BBGroove

一个 groove 存储一组声音以及其他相关元数据,如速度和拍号

BBGroove *groove = [[BBGroove alloc] init];

groove.voices = @[ snare, hihat ];
groove.tempo = 120;

// 4/4 time
groove.beats = 4;
groove.beatUnit = BBGrooverBeatQuarter;

BBGroover

groover 的任务是安排传入的 groove 中每个声音在适当的时间播放。groove 并不实际播放音符,但只通知委托,它可以自选播放音频。

BBGroover *groover = [[BBGroover alloc] initWithGroove:groove];
[groover startGrooving];

BBGrooverDelegate

每当 groover 擐动时都会调用此方法。擐动由具有最高分区的声音决定。例如,如果 groove 的速度为 60,而具有最高分区的是十六分音符,则此委托每秒会被调用 16 次,无论声音是否实际播放。

- (void) groover:(BBGroover *)groover didTick:(NSNumber *)tick {
    // You could update the UI to reflect where the groover was ticking, for example.
}

此方法类似于上面的方法,但除非在特定分区上擐动的声音,否则不会调用此方法。在这里,我们只是在播放与每个擐动的声音相关的音频文件。

- (void) groover:(BBGroover *)groover voicesDidTick:(NSArray *)voices {
    for (BBVoice *voice in voices) {
        // Using ObjectAL to play the audio here.
        [[OALSimpleAudio sharedInstance] playEffect:voice.audioPath];
    }

}

块的替代委托

如果您愿意,每个委托方法也有块的版本。

groover.didTickBlock = ^(NSUInteger tick) {
    // Update UI
};

groover.voicesDidTickBlock = ^(NSArray *voices) {
    for (BBVoice *voice in voices) {
        [[OALSimpleAudio sharedInstance] playEffect:voice.audioPath];
    }
};

运行项目以查看其功能。快乐grooving!

贡献者

Parker Wightman (@parkerwightman)