気にしないでください。互換性がありません。面倒でエラーが発生しやすいです。c++ には、この機能が存在するずっと前から、より簡単に管理できるソリューションがありました。構造体の最後に何を付けていますか? 通常、std::vector、std::array、または固定サイズの配列などを使用します。
アップデート
ノートの開始時間 (uint64_t) のリストを取得し、それらを繰り返し処理して、再生中のものがあればそれを確認したいと考えています。構造体に count var を追加して、柔軟な配列にあるアイテムの数を追跡するつもりでした。
ポリフォニーが固定されている場合は、固定サイズの配列で問題ありません。ほとんどの iOS シンセでは、そのような配列は 1 つしか必要ありません。もちろん、「今後のノート」配列のサイズは、アプリのシンセによって異なる可能性がありますか? サンプラー?シーケンサー?ライブ入力?
template <size_t NumNotes_>
class t_note_start_times {
public:
static const size_t NumNotes = NumNotes_;
typedef uint64_t t_timestamp;
/*...*/
const t_timestamp& timestampAt(const size_t& idx) const {
assert(this->d_numFutureNotes <= NumNotes);
assert(idx < NumNotes);
assert(idx < this->d_numFutureNotes);
return this->d_startTimes[idx];
}
private:
t_timestamp d_presentTime;
size_t d_numFutureNotes; // presumably, this will be the number of active notes,
// and values will be compacted to [0...d_numFutureNotes)
t_timestamp d_startTimes[NumNotes];
};
// in use
const size_t Polyphony = 16;
t_note_start_times<Polyphony> startTimes;
startTimes.addNoteAtTime(noteTimestamp); // defined in the '...' ;)
startTimes.timestampAt(0);
非常に大きくなる動的なサイズの配列が必要な場合は、ベクトルを使用してください。これのインスタンスが 1 つだけ必要で、最大ポリフォニーが (たとえば) 64 の場合は、これを使用してください。