Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int loadPatterns(IT_MAIN *newModule, FILE *modHandle)
- {
- int i, j;
- for (i = 0; i < newModule->PatNum; i++)
- {
- if (newModule->patOffsets[i] == 0)
- {
- newModule->patLengths[i] = 64;
- newModule->pat[i] = (IT_NOTE *)malloc(sizeof (IT_NOTE) * 64 * 64);
- for (j = 0; j < 64 * 64; j++)
- {
- newModule->pat[i]->note = 0;
- newModule->pat[i]->inst = 255;
- newModule->pat[i]->volCol = 255;
- newModule->pat[i]->cmd = 0;
- newModule->pat[i]->param = 0;
- }
- continue;
- }
- fseek(modHandle, newModule->patOffsets[i], SEEK_SET);
- {
- unsigned char lastMaskVariable[64];
- IT_NOTE lastValue[64];
- IT_NOTE *p;
- int packLength = 0, row = 0, bytesRead = 0;
- unsigned char channel = 0, maskVariable, channelVariable;
- for (j = 0; j < 64; j++)
- {
- lastValue[j].note = 0;
- lastValue[j].inst = 255;
- lastValue[j].volCol = 255;
- lastValue[j].cmd = 0;
- lastValue[j].param = 0;
- lastMaskVariable[j] = 0;
- }
- fread(&packLength, 2, 1, modHandle);
- fread(&newModule->patLengths[i], 2, 1, modHandle);
- fseek(modHandle, 4, SEEK_CUR);
- p = newModule->pat[i] = (IT_NOTE *)malloc(sizeof (IT_NOTE) * newModule->patLengths[i] * 64);
- if (p == NULL)
- {
- for (i = 0; i < 199; i++)
- {
- if (newModule->pat[i] != NULL)
- {
- free(newModule->pat[i]);
- }
- }
- return 0;
- }
- for (j = 0; j < (64 * 64); j++)
- {
- p[i].note = 0;
- p[i].inst = 255;
- p[i].volCol = 255;
- p[i].cmd = 0;
- p[i].param = 0;
- }
- while (row < newModule->patLengths[i])
- {
- IT_NOTE n;
- fread(&channelVariable, 1, 1, modHandle);
- if (channelVariable == 0)
- {
- row++;
- continue;
- }
- channel = (channelVariable - 1) & 63;
- if (channelVariable & 128)
- {
- fread(&maskVariable, 1, 1, modHandle);
- lastMaskVariable[channel] = maskVariable;
- }
- if (lastMaskVariable[channel] & 1)
- {
- unsigned char note;
- fread(¬e, 1, 1, modHandle);
- if (note == 255)
- {
- lastValue[channel].note = n.note = 255;
- p[(row * 64) + channel].note = n.note;
- }
- else if (note == 254)
- {
- lastValue[channel].note = n.note = 254;
- p[(row * 64) + channel].note = n.note;
- }
- else if (note <= 120)
- {
- lastValue[channel].note = n.note = note;
- p[(row * 64) + channel].note = n.note;
- }
- }
- if (lastMaskVariable[channel] & 2)
- {
- unsigned char instrument;
- fread(&instrument, 1, 1, modHandle);
- if (instrument <= 99)
- {
- lastValue[channel].inst = n.inst = instrument - 1;
- p[(row * 64) + channel].inst = n.inst;
- }
- }
- if (lastMaskVariable[channel] & 4)
- {
- unsigned char volCol;
- fread(&volCol, 1, 1, modHandle);
- if (volCol <= 212)
- {
- lastValue[channel].volCol = n.volCol = volCol;
- p[(row * 64) + channel].volCol = n.volCol;
- }
- }
- if (lastMaskVariable[channel] & 8)
- {
- unsigned char cmd, param;
- fread(&cmd, 1, 1, modHandle);
- fread(¶m, 1, 1, modHandle);
- if (cmd > 0)
- {
- lastValue[channel].cmd = n.cmd = cmd;
- p[(row * 64) + channel].cmd = n.cmd;
- }
- lastValue[channel].param = n.param = param;
- p[(row * 64) + channel].param = n.param;
- }
- if (lastMaskVariable[channel] & 16)
- {
- n.note = lastValue[channel].note;
- p[(row * 64) + channel].note = n.note;
- }
- if (lastMaskVariable[channel] & 32)
- {
- n.inst = lastValue[channel].inst;
- p[(row * 64) + channel].inst = n.inst;
- }
- if (lastMaskVariable[channel] & 64)
- {
- n.volCol = lastValue[channel].volCol;
- p[(row * 64) + channel].volCol = n.volCol;
- }
- if (lastMaskVariable[channel] & 128)
- {
- n.cmd = lastValue[channel].cmd;
- n.param = lastValue[channel].param;
- p[(row * 64) + channel].cmd = n.cmd;
- p[(row * 64) + channel].param = n.param;
- }
- }
- }
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment