Итак, я пытаюсь выяснить API MusicPlayer для iOS.Мне удалось воспроизвести MIDI, так что моя последовательность там и заполнена чем-то полезным, но я не могу получить доступ к трекам (или в этом случае трек, так как есть только одна музыкальная дорожка, другаяявляется дорожкой темпа).
Если я запускаю MusicSequenceGetTrackCount для "mySequence", я получаю возврат 2;это ожидается.
Если я запускаю MusicSequenceGetInfoDictionary, он возвращает 3 записи:
Printing description of sequenceInfo:
{
tempo = 120;
"time signature" = "4/4";
title = "RHand";
}
Это имеет смысл, поскольку вся эта информация совпадает с моей дорожкой.
Итак, все это заставит меня задуматься, если я использую метод MusicSequenceGetIndTrack (MusicSequence inSequence, UInt32 inTrackIndex, MusicTrack * outTrack), я должен иметь возможность выводить трек, чтобы я мог внести некоторые изменения.
Вот мой коддо сих пор.Если бы кто-нибудь мог посмотреть и посмотреть, где я иду не так, это было бы здорово.Кроме того, если у кого-то есть хорошие ресурсы по использованию MusicPlayer, я был бы очень благодарен.Спасибо.
ViewController.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/MusicPlayer.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *noteDisplayLabel;
@property MusicSequence mySequence;
@property MusicPlayer player;
@property MusicEventIterator iterator;
@property MusicTrack RHand;
@property MusicTrack LHand;
- (IBAction)practiceLesson:(id)sender;
- (IBAction)changeTempo:(id)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize noteDisplayLabel, mySequence, player, iterator, RHand, LHand;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CFBundleRef appBundle = CFBundleGetMainBundle();
CFStringRef filename = CFSTR("simpleCScale");
CFStringRef ext = CFSTR("mid");
CFURLRef fileLocation = CFBundleCopyResourceURL(appBundle, filename, ext, NULL);
NewMusicSequence(&mySequence);
MusicSequenceFileLoad(mySequence, fileLocation, 0, kMusicSequenceLoadSMF_ChannelsToTracks);
NewMusicPlayer(&player);
UInt32 trackCount;
MusicSequenceGetTrackCount(mySequence, &trackCount);
NSLog(@"Number of tracks: %lu", trackCount);
CFDictionaryRef sequenceInfo;
sequenceInfo = MusicSequenceGetInfoDictionary(mySequence);
UInt32 trackIndex = 0;
MusicTrack track;
MusicSequenceGetIndTrack (mySequence,trackIndex,&track);
MusicEventIterator iter;
Boolean hasEvent = 0;
NewMusicEventIterator(track, &iter);
Boolean hasNextEvent = 1;
while (hasNextEvent == 1) {
MusicEventIteratorHasCurrentEvent(iter, &hasEvent);
NSLog(@"Has Event: %i", hasEvent);
MusicTimeStamp timestamp;
MusicEventType eventType = 0;
void *eventData = NULL;
UInt32 eventDataSize;
MusicEventIteratorGetEventInfo(iter, ×tamp, &eventType, eventData, &eventDataSize);
NSLog(@"Event %f: Type = %lu, Data = %p, Size = %lu", timestamp, eventType, eventData, eventDataSize);
MusicEventIteratorNextEvent(iter);
MusicEventIteratorHasNextEvent(iter, &hasNextEvent);
NSLog(@"More Events? : %i", hasNextEvent);
}
}
- (void)viewDidUnload
{
[self setNoteDisplayLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (IBAction)practiceLesson:(id)sender {
MusicPlayerSetSequence(player, mySequence);
MusicPlayerStart(player);
}
- (IBAction)changeTempo:(id)sender {
}
@end
РЕДАКТИРОВАТЬ
Попытка сделать следующее в методе viewDidLoad, но он не работал:
UInt32 trackIndex = 1;
MusicTrack *track;
MusicSequenceGetIndTrack (mySequence,trackIndex,&track);
РЕДАКТИРОВАТЬ
Обновлен код выше, чтобы включитьизменения.У меня работает EventIterator, но я не могу получить какие-либо данные о событиях из него?Запуск программы дает мне следующий вывод:
2012-03-13 14:09:39.709 musicPlayerSandbox[61775:f803] Number of tracks: 2
2012-03-13 14:09:39.711 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.712 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.713 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.714 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.714 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.715 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.716 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.716 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.717 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.718 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.719 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.719 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.720 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.845 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.846 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.846 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.847 musicPlayerSandbox[61775:f803] Event 1.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.847 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.848 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.849 musicPlayerSandbox[61775:f803] Event 2.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.850 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.850 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.851 musicPlayerSandbox[61775:f803] Event 3.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.851 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.852 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.853 musicPlayerSandbox[61775:f803] Event 4.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.887 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.888 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.888 musicPlayerSandbox[61775:f803] Event 5.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.889 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.890 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.891 musicPlayerSandbox[61775:f803] Event 6.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.891 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.892 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.893 musicPlayerSandbox[61775:f803] Event 7.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.893 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.894 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.895 musicPlayerSandbox[61775:f803] Event 8.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.899 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.900 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.901 musicPlayerSandbox[61775:f803] Event 9.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.902 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.902 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.903 musicPlayerSandbox[61775:f803] Event 10.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.904 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.905 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.905 musicPlayerSandbox[61775:f803] Event 11.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.906 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.907 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.908 musicPlayerSandbox[61775:f803] Event 12.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.908 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.909 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.928 musicPlayerSandbox[61775:f803] Event 13.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.929 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.930 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.930 musicPlayerSandbox[61775:f803] Event 14.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.931 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.932 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.932 musicPlayerSandbox[61775:f803] Event 15.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.933 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.933 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.934 musicPlayerSandbox[61775:f803] Event 16.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.935 musicPlayerSandbox[61775:f803] More Events? : 0