iOS钢琴表到NSString表示与字母(A-Z)

时间:2014-05-26 04:44:05

标签: ios cocoa-touch uikit

我制作的游戏类似于钢琴拼图" Link"。

我有26个mp3文件,按升序表示音符(A.mp3 - Z.mp3)

现在我需要将钢琴表或任何其他标准表示(例如MIDI)转换为一串大写字母。

每个音符的持续时间或音量无关紧要。我只需要每首歌的连续字符序列。

如果原始格式的音符太低/太高,我只需将其替换为最低(' A')/最高(' Z' .mp3)声音。

我存储当前" noteIndex"和" songIndex"在NSUserDefault。当用户点击正确的钢琴键时,我会调用+playNextNote增加" noteIndex"和/或" songIndex"相应地并致电+playSong:(int)song note:(int)note

修改

当我在线搜索时,大多数钢琴曲都是PDF表格或MIDI。

编辑2:

详细实施

我想要的格式是+ (NSArray *)songList方法

+ (void)playNote:(char)note {
    NSString *file = [NSString stringWithFormat:@"%c.mp3", note];

    [ResourceHelper playFx:file];
}

+ (void)playRandomNote {

    [ResourceHelper playNote:[Helper getRandomIntBothInclusiveLow:'A' high:'Z']];

}

+ (void)playFx:(NSString *)fx {
    [ModuleHelper playFx:fx];
}



#define KEY_SONG_TITLE @"KEY_SONG_TITLE"
#define KEY_SONG_NOTES @"KEY_SONG_NOTES"



+ (void)playNextNote {

    int songIndex = [CacheHelper songIndex];
    int noteIndex = [CacheHelper noteIndex];

    NSDictionary *song = [ResourceHelper songList][songIndex - 1];
    NSString *notes = song[KEY_SONG_NOTES];
    int numChars = notes.length;
    if (noteIndex < numChars - 1) {
        noteIndex++;
    }
    else {
        int numSongs = [ResourceHelper songList].count;
        if (songIndex < numSongs - 1) {
            songIndex++;
            noteIndex = 0;
        }
        else {
            songIndex = 1;//0th song is random song
            noteIndex = 0;
        }
    }

    [ResourceHelper playNoteWithSongIndex:songIndex noteIndex:noteIndex];

}

+ (void)playNoteWithSongIndex:(int)songIndex noteIndex:(int)noteIndex {

    NSDictionary *song = [ResourceHelper songList][songIndex - 1];
    NSString *notes = song[KEY_SONG_NOTES];

    char note = [notes characterAtIndex:noteIndex];
    [ResourceHelper playNote:note];

}


+ (NSString *)songNameWithIndex:(int)index {
    if (index == 0) {
        return LOCALIZE(STR_UI_RANDOM_NOTES);
    }
    else {
        NSDictionary *song = [ResourceHelper songList][index - 1];
        return song[KEY_SONG_TITLE];
    }
}

static NSArray *songList;
+ (NSArray *)songList {
    if (songList == nil) {
        songList = @[
             @{KEY_SONG_TITLE:@"Baby",
               KEY_SONG_NOTES:@"AABBCC"},

             @{KEY_SONG_TITLE:@"Just Give Me a Reason",
               KEY_SONG_NOTES:@"AAABBBCCC"},

             @{KEY_SONG_TITLE:@"When You Believe",
               KEY_SONG_NOTES:@"ABCABCABC"},

             @{KEY_SONG_TITLE:@"Firework",
               KEY_SONG_NOTES:@"CCCCBBBBAAAA"},

             ];
    }
    return songList;
}

0 个答案:

没有答案