これは、音符の値とそのタイミングを保存する iOS デバイス用に作成する音楽アプリケーション用に C++ で作成された単純なクラスです。
class info {
public:
float attackTime;
Note noteStriked;
void setData(float timeOfAttack, Note nameOfStrikeNote){
attackTime = timeOfAttack;
noteStriked = nameOfStrikeNote;
}
};
上記...注は、{SNARE、DRUM、HIHAT}などのデフォルト値のみを含むことができる構造体です。Note オブジェクトを作成し、それらのオブジェクトを後でアクセスできるように NSMutableArray に格納するという考え方です。
次に、メインの .h ファイルに NSMutableArray sequenceOfNotes; があります。私の.mファイルで、オブジェクトを可変配列に追加しようとしています...しかし、これを行う方法がわかりません。色々やってみたけどダメ!
//Create one instance of the class
NoteData *currentNoteData;
// Update the instance of the class.. its two variables: attackTime and noteStriked
currentNoteData->attackTime = timeHit;
currentNoteData->noteStriked = SNARE;
//Then im trying to add the above instance to my mutableArray below
[sequenceOfNotes addObject:currentNoteData];
その行で生成されるエラーは、「NoteData *」型の左辺値で「id」型のパラメーターを初期化できません
エラーが修正された後に id がやりたいことは、選択した配列の任意の位置でオブジェクトを取得し、その特定のインデックスでそのオブジェクトから属性変数を選択できるようにすることです。
//PsuedoCode
array {
position 0: NoteData object {
attackTime = 45.34,
noteStriked = HIHAT
}
position 1: NoteData object {
attackTime = 65.32,
noteStriked = SNARE
}
position 2: NoteData object {
attackTime = 78.53,
noteStriked = HIHAT
}
position 3: NoteData object {
attackTime = 98.44,
noteStriked = KICK
}
etc etc
}
//and then convert NSObject to normal c++ object something like this...
NoteData temp = [noteSequence objectAtIndex:0];
//so that i can then do this:
float currentTime = temp.attackTime;
Note currentNote = temp.noteStriked;
明らかに、変換の問題があります..誰かがこれを手伝ってくれるなら、それは素晴らしいことです