シンプルなメトロノームアプリを構築しようとしていて、そこからサンプルコードやオープンソースプロジェクトがあるかどうか疑問です。私はリンゴはそれを持っていたが、それ以上はないと思う。私はそれほど難しいとは思っていませんが、オーディオをロードする方法、タイマーを設定する方法、それに応じてオーディオをループする方法を知りたいと思っています。どんな助けでも大歓迎です。シンプルなメトロノームiPhoneアプリ
答えて
Appleのメトロノームアプリは、まだiOS 4.2ライブラリで利用できます。
Xcodeでは、単にWindow
- >Organizer
に行きます。
次に、Documentation
ペインに移動し、Metronome
を検索します。
サンプルコードセクションの下にメトロノームプロジェクトが表示されます。
iOS 4.2ライブラリがあることを確認するには、[環境設定] - > [ダウンロード] - > [ドキュメント]を選択し、iOS 4.2ライブラリがリストにあることを確認します。
だから... 2015年夏の時点で、アップルのウェブサイトの再設計により、これらのリンクが壊れているようです。私は.xar
形式のhttp://devimages.apple.com/docsets/20101122/com.apple.adc.documentation.AppleiOS4_2.iOSLibrary.Xcode4.xarのdocketリンクをダウンロードしてから、xar -xf <docsetfilename>
コマンドラインツールまたはunarchiver appのようなもので解凍することができます。
これは私が以前作ったメトロノームプロジェクトですが、それはかなりシンプルですが、それは参考にしてください、ちょうど私を参照してください、ジョーダンブラウン15yマンゴーアプリ。それはしばらくかかったが、決してそれからアプリを作ったことはありません。
//.h
NSTimer *timer;
int count;
float bpm;
float speed;
UILabel *numberLabel;
IBOutlet UISwitch *vibrate;
IBOutlet UISegmentedControl *timing;
}
- (IBAction)up;
- (IBAction)down;
- (IBAction)stop:(id)sender;
@property (nonatomic, retain)IBOutlet UILabel *numberLabel;
@property (nonatomic, retain)IBOutlet UILabel *bpmLabel;
@property (nonatomic, retain)IBOutlet UISegmentedControl *timing;
//.m
#define SECONDS 60
#import <AudioToolbox/AudioToolbox.h>
@implementation metronome
@synthesize numberLabel; // labels
@synthesize bpmLabel;
@synthesize timing;
-(IBAction)stop:(id)sender{
[timer invalidate];
[self performSelector:@selector(playTockSound)];
numberLabel.text = [NSString stringWithFormat:@"%i",count];
bpm = bpm;
if (bpm > 300) {
bpm = 300;
}
int new = bpm;
bpmLabel.text = [NSString stringWithFormat:@"%i",new];
speed = INFINITY;
NSLog(@"%f",speed);
timer = [NSTimer scheduledTimerWithTimeInterval:speed target:self selector:@selector(updateNumber) userInfo:nil repeats:YES];
}
-(IBAction)up{
[timer invalidate];
count = 1;
[self performSelector:@selector(playTockSound)];
numberLabel.text = [NSString stringWithFormat:@"%i",count];
bpm = bpm+10;
if (bpm > 300) {
bpm = 300;
}
int new = bpm;
bpmLabel.text = [NSString stringWithFormat:@"%i",new];
speed = SECONDS/bpm;
NSLog(@"%f",speed);
timer = [NSTimer scheduledTimerWithTimeInterval:speed target:self selector:@selector(updateNumber) userInfo:nil repeats:YES];
}
-(IBAction)down{
[timer invalidate];
count = 1;
[self performSelector:@selector(playTockSound)];
numberLabel.text = [NSString stringWithFormat:@"%i",count];
bpm = bpm-10;
if (bpm < 10) {
bpm = 10;
}
int new = bpm;
bpmLabel.text = [NSString stringWithFormat:@"%i",new];
speed = SECONDS/bpm;
NSLog(@"%f",speed);
timer = [NSTimer scheduledTimerWithTimeInterval:SECONDS/bpm target:self selector:@selector(updateNumber) userInfo:nil repeats:YES];
}
-(void)updateNumber{
count += 1;
//if 4/4 timing is selected then the count wont go past 4
if (timing.selectedSegmentIndex == 2) {
if (count >= 5) {
count = 1;
}
}
//if 3/4 timing is selected then the count wont go past 3
if (timing.selectedSegmentIndex == 1) {
if (count >= 4) {
count = 1;
}
}
//if 2/4 timing is selected then the count wont go past 2
if (timing.selectedSegmentIndex == 0) {
if (count >= 3) {
count = 1;
}
}
//In each timing case it plays the sound on one and depending
//on the limitiations on the cont value the amount of each tick
if (count == 1) {
[self performSelector:@selector(playTockSound)];
}else {
[self performSelector:@selector(playTickSound)];
}
numberLabel.text = [NSString stringWithFormat:@"%i",count];
}
-(void)playTickSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"tick"
ofType:@"caf"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
, &soundID);
AudioServicesPlaySystemSound (soundID);
}
-(void)playTockSound
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"tock"
ofType:@"caf"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path]
, &soundID);
AudioServicesPlaySystemSound (soundID);
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidLoad
{
bpm = 60.00;
speed = SECONDS/bpm;
timer = [NSTimer scheduledTimerWithTimeInterval:speed target:self selector:@selector(updateNumber) userInfo:nil repeats:YES];
int new = bpm;
bpmLabel.text = [NSString stringWithFormat:@"%i",new];
[super viewDidLoad];
}
私はNSTimerを試しましたが、プロメトロノームを探しているなら、それは良い解決策ではありません。時間が必要な場所にくるようにするコアエンジンが必要です。 NSTimerは、必要な精度を得ることができなかった時間空間をループすることができます。
今見て、iOS 5ではミュージカルアプリの良いソリューションであるミュージックシーケンサーを使用できます。そして、時間をコントロールするコアエンジンを持っています。
こんにちはCristian、あなたはそのMusic Sequencerを使用してさらに発展させることができますか?私はウェブ上でそれについて多くを見つけることができませんでした。ありがとう! – Lucas
Googleの目的のためにここに私の知見があります。私はアップルの例のアプローチ(バックグラウンドスレッドを使用)とNSTimerのアプローチの両方を試してきましたが、勝者はスレッド化の使用です。メイン(UI)スレッド上で実行されている間にNSTimerを正確に起動させる方法はありません。私はあなたがバックグラウンドで実行時間を得ることができると思うが、Appleの例は本当にうまく動作します。
- 1. シンプルなメトロノーム
- 2. メトロノームへのシンプルなレコード数/プレロール
- 3. UIButtonのシンプルなアプリ - iPhoneアプリケーションのエラー
- 4. クォーツ2DのシンプルなiPhoneの描画アプリ
- 5. オーディオキューを使用したiPhone用メトロノーム
- 6. シンプルなアプリ購入アプリAndroid
- 7. 非常にシンプルなiPhoneアプリがUILabel settextでクラッシュする
- 8. iphoneアプリの背景としてシンプルなアニメーション
- 9. (iphone)非常にシンプルなIphoneゲーム
- 10. 正確なメトロノームfor Android
- 11. iPhoneアプリ:あなたにiPhone
- 12. シンプルなアンドロイド電卓アプリ
- 13. AngularJSのシンプルなアプリのメモリリーク
- 14. 別のBluetoothデバイスに接続できるシンプルなiphoneアプリを作成します。
- 15. iPhone DropBox APIとのシンプルな同期
- 16. XMLなしのシンプルなAndroidアプリ
- 17. UWPメトロノームApp - MediaPlayerElementトランスポートコントロールとパフォーマンス
- 18. メトロノーム精度アルゴリズム数学
- 19. シンプルな電卓アプリがクラッシュし
- 20. シンプルなOCRアプリ使ってAndroidのカメラ
- 21. スウィフトはシンプルなアプリに - lldbエラー
- 22. iPhoneアプリのようなボタン
- 23. iphoneアプリ
- 24. iphoneアプリのウェブサイト - iphoneフレーム
- 25. Unity:PlayScheduled()で正確なメトロノームが動作しない
- 26. チタン:AndroidアプリへのiPhoneアプリ
- 27. iPhoneアプリ:アプリ内購入
- 28. iPhoneアプリ:アプリ購入時
- 29. iPhone:シンプルなUITableViewControllerがコンソールエラーやデバッグヒントなしでクラッシュする
- 30. iPhoneアプリとウェブサービス
あなたが失望していないことを確認するだけです。既に[多くのメトロノームアプリ](http://www.google.de/search?q=site%3Aitunes.apple.com+metronome)があります。あなたが練習としてそれをやっているなら、[appチュートリアル](http://developer.apple.com/library/mac/#documentation/General/Conceptual/Mac101/Articles/00_Introduction.html# // apple_ref/doc/uid/TP40010611)。 –