Вставка пары в мультикарту на OSX - PullRequest
0 голосов
/ 08 мая 2018

Мне нужна помощь! Я использую мультикарту для отображения индексов музыкальных нот, поэтому я могу получить к ним доступ по строковому имени заметки, а также по значению int. Тем не менее, код отлично работает в Windows, но при перемещении его в OSX (последняя версия). Я получаю сообщение об ошибке «Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x0)» каждый раз, когда используется вставка.

Ошибка выполнения

Я знаю, что не использую лучший метод для вставки заметок и индексов в мультикарту, но я собираюсь переписать его.

Я пробовал несколько методов, чтобы заставить его работать, но безуспешно. Вот код.

Заголовок

class zelmNote
{
private:
    static bool bNoteMapped;
    static multimap<int, string> noteToName;
    static multimap<string, int> nameToNote;

    static void mapNotes();

public:
    zelmNote();
};

.cpp

multimap<int, string> zelmNote::noteToName;
multimap<string, int> zelmNote::nameToNote;

void zelmNote::mapNotes()
{
    bNoteMapped = true;
    int i = 9;
    string noteName = "";
    /*intToNote.insert(pair<int, string>(8, "G#"));
    noteToInt.insert(pair<string, int>("G#", 8));
    intToNote.insert(pair<int, string>(8, "Ab"));
    noteToInt.insert(pair<string, int>("G#", 8));*/
    //Do natural notes
    for (char c = 'A'; c <= 'G'; c++)
    {
        noteName = ofToString(c);
        noteToName.insert(pair<int, string>(i, noteName));
        nameToNote.insert(pair<string, int>(noteName, i));
        if (i == 11)
        {
            i = 0;
        }
        else if (i == 4)
        {
            i++;
        }
        else if ((i != 11) || (i != 4))
        {
            i += 2;
        }
    }


    //Do sharps
    noteToName.insert(pair<int, string>(0, "B#"));
    nameToNote.insert(pair<string, int>("B#", 0));

    noteToName.insert(pair<int, string>(1, "C#"));
    nameToNote.insert(pair<string, int>("C#", 1));

    noteToName.insert(pair<int, string>(3, "D#"));
    nameToNote.insert(pair<string, int>("D#", 3));

    noteToName.insert(pair<int, string>(4, "D##"));
    nameToNote.insert(pair<string, int>("D##", 4));

    noteToName.insert(pair<int, string>(5, "E#"));
    nameToNote.insert(pair<string, int>("E#", 5));

    noteToName.insert(pair<int, string>(6, "F#"));
    nameToNote.insert(pair<string, int>("F#", 6));

    noteToName.insert(pair<int, string>(8, "G#"));
    nameToNote.insert(pair<string, int>("G#", 8));

    noteToName.insert(pair<int, string>(10, "A#"));
    nameToNote.insert(pair<string, int>("A#", 10));


    //Do flats
    noteToName.insert(pair<int, string>(11, "Cb"));
    nameToNote.insert(pair<string, int>("Cb", 11));

    noteToName.insert(pair<int, string>(0, "Dbb"));
    nameToNote.insert(pair<string, int>("Dbb", 0));

    noteToName.insert(pair<int, string>(1, "Db"));
    nameToNote.insert(pair<string, int>("Db", 1));

    noteToName.insert(pair<int, string>(3, "Eb"));
    nameToNote.insert(pair<string, int>("Eb", 3));

    noteToName.insert(pair<int, string>(4, "Fb"));
    nameToNote.insert(pair<string, int>("Fb", 4));

    noteToName.insert(pair<int, string>(6, "Gb"));
    nameToNote.insert(pair<string, int>("Gb", 6));

    noteToName.insert(pair<int, string>(8, "Ab"));
    nameToNote.insert(pair<string, int>("Ab", 8));

    noteToName.insert(pair<int, string>(10, "Bb"));
    nameToNote.insert(pair<string, int>("Bb", 10));
}

zelmNote::zelmNote()
{
    if (!bNoteMapped)
    {
        mapNotes();
    }
}
...