2012-01-16 8 views
1

シンプルなメトロノームアプリを構築しようとしていて、そこからサンプルコードやオープンソースプロジェクトがあるかどうか疑問です。私はリンゴはそれを持っていたが、それ以上はないと思う。私はそれほど難しいとは思っていませんが、オーディオをロードする方法、タイマーを設定する方法、それに応じてオーディオをループする方法を知りたいと思っています。どんな助けでも大歓迎です。シンプルなメトロノームiPhoneアプリ

+1

あなたが失望していないことを確認するだけです。既に[多くのメトロノームアプリ](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)。 –

答えて

3

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のようなもので解凍することができます。

+0

ヒントをありがとうが、残念ながら私はIOS 4.3、iOS 5.0とxcode 4.2 devのライブラリを参照してください...どこからiOS 4.2ライブラリですか? – xoail

+0

フィードURLで回答を更新しました。 – Walter

+0

リンクが動作していません。ページが見つかりません... iosデベロッパーライブラリを検索しました。 –

0

これは私が以前作ったメトロノームプロジェクトですが、それはかなりシンプルですが、それは参考にしてください、ちょうど私を参照してください、ジョーダンブラウン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]; 

    } 
+0

ありがとうございましたジョーダン、私はこのコードの作業をしようとしています...私は単一のプロジェクトを作成し、これらのファイルを含んでいます...また、2つのUILabels、UISwitch、UISegmentedControlコントロールをnibファイルに追加しましたが、上、下、停止)をマップする必要がありますか? – xoail

+3

この手法を使用する時間精度は悪くなります。 – justin

+0

アクションはボタンで接続されます。あなたはまた、精度を変更することができます、私はちょうど10の増分を使用しましたが、あなたは簡単にそれを変更することができます – Jordan

2

私はNSTimerを試しましたが、プロメトロノームを探しているなら、それは良い解決策ではありません。時間が必要な場所にくるようにするコアエンジンが必要です。 NSTimerは、必要な精度を得ることができなかった時間空間をループすることができます。

今見て、iOS 5ではミュージカルアプリの良いソリューションであるミュージックシーケンサーを使用できます。そして、時間をコントロールするコアエンジンを持っています。

+0

こんにちはCristian、あなたはそのMusic Sequencerを使用してさらに発展させることができますか?私はウェブ上でそれについて多くを見つけることができませんでした。ありがとう! – Lucas

0

Googleの目的のためにここに私の知見があります。私はアップルの例のアプローチ(バックグラウンドスレッドを使用)とNSTimerのアプローチの両方を試してきましたが、勝者はスレッド化の使用です。メイン(UI)スレッド上で実行されている間にNSTimerを正確に起動させる方法はありません。私はあなたがバックグラウンドで実行時間を得ることができると思うが、Appleの例は本当にうまく動作します。

関連する問題