Пример #1
0
size_t MIDIParse_Header(MIDI_HEADER_CHUNK_t* header, void* data, uint32_t size)
{
    uint8_t* ptr = (uint8_t*)data;
    ptr = (uint8_t*)findSubString( (char*)data, (char*)MIDI_HEADER_STRING, MIDI_TRACK_BUFFER_SIZE);

    if (ptr)
    {
        uint16_t* tmp;
        tmp = (uint16_t*)&ptr[MIDI_HEADER_FMT];
        reverseOrder( (char*)tmp, 2);
        header->format = *tmp;

        tmp = (uint16_t*)&ptr[MIDI_HEADER_TRACK_COUNT];
        reverseOrder((char*)tmp, 2);
        header->trackCount = *tmp;

        tmp = (uint16_t*)&ptr[MIDI_HEADER_PPQ];
        reverseOrder((char*)tmp, 2);
        header->PPQ = *tmp;

        uint8_t* diff = ptr;
        diff = (uint8_t*)((uint8_t*)diff - (uint8_t*)(data));

        return  (size_t)(diff);
    }

    return 0;
}
Пример #2
0
//Returns the pointer to the first byte of the track data
void* MIDIParse_Track(MIDI_TRACK_CHUNK_t* track, void* data, uint32_t size)
{
    char* ptr = (char*)findSubString( (char*)data, (char*)MIDI_TRACK_STRING, size);
    if (ptr)
    {
        uint32_t* tmp;
        tmp = (uint32_t*)&ptr[MIDI_TRACK_LENGTH];
        reverseOrder( (char*)tmp, 4);
        track->length = *tmp;
        //MIDI_Printf("TRACKLENG: ", track->length);
        return &ptr[MIDI_TRACK_LENGTH+4];
    }

    return 0;
}
Пример #3
0
int interpret(tListOfInstr * ilist)
{
  tListItem * listItem = ilist->first;
  tInstr * i;
  while(listItem != NULL)
  {
    i = &listItem->Instruction;
    printDebug("zpracovavam instrukci typu %d\n", i->instType);
    switch(i->instType)
    {
      case I_READ:
        switch(i->type)
        {
          unsigned int size, length;
          char ch;
          case k_int:
            if ( scanf("%d", (int *)i->addr3) != 1) return EXIT_READ_STDIN_ERROR;
            break;
          case k_real:
            if (scanf("%lf", (double *)i->addr3) != 1) return EXIT_READ_STDIN_ERROR;
            break;
          case k_string:
            size = 8; length = 0;
            if ((((string *)i->addr3)->str = realloc(((string *)i->addr3)->str, sizeof(char) * size)) == NULL)
              return EXIT_INTERNAL_ERROR;
            while (EOF != (ch = getchar()) && ch != '\n')
            {
              ((string *)i->addr3)->str[length++] = ch;
              if (length == size)
              {
                if ((((string *)i->addr3)->str = realloc(((string *)i->addr3)->str, sizeof(char) * (size += 8))) == NULL)
                  return EXIT_INTERNAL_ERROR;
              }
            }
            ((string *)i->addr3)->str[length] = '\0';
            if ((((string *)i->addr3)->str = realloc(((string *)i->addr3)->str, sizeof(char) * length)) == NULL)
               return EXIT_INTERNAL_ERROR;
            ((string *)i->addr3)->alloc = length;
            ((string *)i->addr3)->length = length;
            break;
          case k_bool:
            return EXIT_TYPE_ERROR;
          default:
            printDebug("%d", i->type); return EXIT_READ_STDIN_ERROR;
        }
        printDebug("Nacteno ze vstupu.\n");
        break;
      case I_WRITE:
        switch(i->type)
        {
          case k_int:
            printf("%d", *(int *)i->addr1); break;
          case k_real:
            printf("%g", *(double *)i->addr1); break;
          case k_string:
            printf("%s", ((string *)i->addr1)->str); break;
          case k_bool:
            if (*(bool *)i->addr1 == true) printf("TRUE");
            else printf("FALSE");
            break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_JUMP: // instrukce skoku, jen se nastavim na zadanou v adrese (ve volani si beru addr1 = ilist->last)
        if (i->addr1 == NULL || !(*(bool *)i->addr1)) listItem = *(tListItem **)i->addr2;
        break;
      case I_ASSIGN: // isntukce prirazeni, jedina komplikace je string (kopiruju retezec, musim realloc)
        switch(i->type)
        {
          case k_int:
            *(int *)i->addr3 = *(int *)i->addr1;
            break;
          case k_real:
            *(double *)i->addr3 = *(double *)i->addr1;
            break;
          case k_string:
            if (((string *)i->addr3)->alloc < ((string *)i->addr1)->alloc)
            {
              ((string *)i->addr3)->alloc = ((string *)i->addr1)->alloc;
              if ((((string *)i->addr3)->str = realloc(((string *)i->addr3)->str, sizeof(char) * ((string *)i->addr1)->alloc)) == NULL)
                return EXIT_INTERNAL_ERROR;
            }
            strncpy(((string *)i->addr3)->str, ((string *)i->addr1)->str, ((string *)i->addr3)->alloc);
            ((string *)i->addr3)->length = ((string *)i->addr1)->length;
            break;
          case k_bool:
            *(bool *)i->addr3 = *(bool *)i->addr1;
            break;
          default:
            return EXIT_TYPE_ERROR;
        }
        printDebug("prirazuji z adresy %d (hodnota %d) na adresu %d nova hodnota je %d\n", i->addr1, i->addr3, *(int *)i->addr3, *(int *)i->addr3);
        break;
      case I_CALL_FUNCTION: // volani funkce (zaradim instrukce funkce jako nasledujici instrukci a za posledni instrukci fukce zaradim nasledujici instrukci (co by naseldovala v ilistu))
        ((tListOfInstr *)i->addr1)->last->nextItem = listItem->nextItem;
        listItem->nextItem = ((tListOfInstr *)i->addr1)->first;
        break;
      case I_CLEAR: // free nad docasnou hodnotou (u stringu jeste samotny string) -> provede se az pri uklidu na konci, kvuli jumpum...
        //if (i->type == k_string) free(((string *)i->addr1)->str);
        //free(i->addr1);
        break;
      case I_MUL: // jak resit int * real?
        if (i->type == k_int) *(int *)i->addr3 = *(int *)i->addr1 * *(int *)i->addr2;
        else if (i->type == k_real) *(double *)i->addr3 = *(double *)i->addr1 * *(double *)i->addr2;
        else return EXIT_RUNTIME_ERROR;
        break;
      case I_DIV:
        if (i->type == k_int) *(int *)i->addr3 = *(int *)i->addr1 / *(int *)i->addr2;
        else if (i->type == k_real) *(double *)i->addr3 = *(double *)i->addr1 / *(double *)i->addr2;
        else return EXIT_RUNTIME_ERROR;
        break;
      case I_ADD:
        if (i->type == k_int) *(int *)i->addr3 = *(int *)i->addr1 +*(int *)i->addr2;
        else if (i->type == k_real) *(double *)i->addr3 = *(double *)i->addr1 + *(double *)i->addr2;
        else if (i->type == k_string)
        {
          ((string *)i->addr3)->alloc = (((string *)i->addr1)->alloc + ((string *)i->addr2)->alloc);
          if ((((string *)i->addr3)->str = malloc(sizeof(char) * ((string *)i->addr3)->alloc)) == NULL)
            return EXIT_INTERNAL_ERROR;
          strcpy(((string *)i->addr3)->str, ((string *)i->addr1)->str);
          strcat(((string *)i->addr3)->str, ((string *)i->addr2)->str);
        }
        else return EXIT_RUNTIME_ERROR;
        break;
      case I_SUB:
        if(i->type == k_int) *(int *)i->addr3 = *(int *)i->addr1 - *(int *)i->addr2;
        else if(i->type == k_real) *(double *)i->addr3 = *(double *)i->addr1 - *(double *)i->addr2;
        else return EXIT_RUNTIME_ERROR;
        break;
      case I_LESS:
        switch(i->type)
        {
          case k_int: *(bool *)i->addr3 = *(int *)i->addr1 < *(int *)i->addr2; break;
          case k_real: *(bool *)i->addr3 = *(double *)i->addr1 < *(double *)i->addr2; break;
          case k_string: *(bool *)i->addr3 = (strcmp(((string *)i->addr1)->str, ((string *)i->addr2)->str) < EXIT_SUCCESS); break;
          case k_bool: *(bool *)i->addr3 = *(bool *)i->addr1 < *(bool *)i->addr2; break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_GREATER:
        switch(i->type)
        {
          case k_int: *(bool *)i->addr3 = *(int *)i->addr1 > *(int *)i->addr2; break;
          case k_real: *(bool *)i->addr3 = *(double *)i->addr1 > *(double *)i->addr2; break;
          case k_string: *(bool *)i->addr3 = (strcmp(((string *)i->addr1)->str, ((string *)i->addr2)->str) > EXIT_SUCCESS); break;
          case k_bool: *(bool *)i->addr3 = *(bool *)i->addr1 > *(bool *)i->addr2; break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_LESS_EQUAL:
        switch(i->type)
        {
          case k_int: *(bool *)i->addr3 = *(int *)i->addr1 <= *(int *)i->addr2; break;
          case k_real: *(bool *)i->addr3 = *(double *)i->addr1 <= *(double *)i->addr2; break;
          case k_string: *(bool *)i->addr3 = (strcmp(((string *)i->addr1)->str, ((string *)i->addr2)->str) <= EXIT_SUCCESS); break;
          case k_bool: *(bool *)i->addr3 = *(bool *)i->addr1 <= *(bool *)i->addr2; break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_GREATER_EQUAL:
        switch(i->type)
        {
          case k_int: *(bool *)i->addr3 = *(int *)i->addr1 >= *(int *)i->addr2; break;
          case k_real: *(bool *)i->addr3 = *(double *)i->addr1 >= *(double *)i->addr2; break;
          case k_string: *(bool *)i->addr3 = (strcmp(((string *)i->addr1)->str, ((string *)i->addr2)->str) >= EXIT_SUCCESS); break;
          case k_bool: *(bool *)i->addr3 = *(bool *)i->addr1 >= *(bool *)i->addr2; break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_EQUAL:
        switch(i->type)
        {
          case k_int: *(bool *)i->addr3 = *(int *)i->addr1 == *(int *)i->addr2; break;
          case k_real: *(bool *)i->addr3 = *(double *)i->addr1 == *(double *)i->addr2; break;
          case k_string: *(bool *)i->addr3 = (strcmp(((string *)i->addr1)->str, ((string *)i->addr2)->str) == EXIT_SUCCESS); break;
          case k_bool: *(bool *)i->addr3 = *(bool *)i->addr1 == *(bool *)i->addr2; break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_NOT_EQUAL:
        switch(i->type)
        {
          case k_int: *(bool *)i->addr3 = *(int *)i->addr1 != *(int *)i->addr2; break;
          case k_real: *(bool *)i->addr3 = *(double *)i->addr1 != *(double *)i->addr2; break;
          case k_string: *(bool *)i->addr3 = (strcmp(((string *)i->addr1)->str, ((string *)i->addr2)->str) != EXIT_SUCCESS); break;
          case k_bool: *(bool *)i->addr3 = *(bool *)i->addr1 != *(bool *)i->addr2; break;
          default:
            return EXIT_TYPE_ERROR;
        }
        break;
      case I_COPY:
        if (((string *)i->addr1)->length < (*((struct srange *)i->addr2)->length + *((struct srange *)i->addr2)->start)) return EXIT_RUNTIME_ERROR;
        if ((((string *)i->addr3)->str = realloc(((string *)i->addr3)->str, *((struct srange *)i->addr2)->length * sizeof(char))) == NULL)
          return EXIT_INTERNAL_ERROR;
        strncpy(&((string *)i->addr3)->str[*((struct srange *)i->addr2)->start], ((string *)i->addr1)->str, *((struct srange *)i->addr2)->length);
        ((string *)i->addr3)->length = *((struct srange *)i->addr2)->length;
        break;
      case I_FIND:
        if(!strlen(((string *)i->addr2)->str) || !strlen(((string *)i->addr1)->str) || 
          ((strlen(((string *)i->addr1)->str)) < (strlen(((string *)i->addr2)->str)))) return EXIT_RUNTIME_ERROR;
        *(int *)i->addr3 = findSubString(((string *)i->addr2)->str, ((string *)i->addr1)->str);
        break;
      case I_SORT:
        if (((string *)i->addr1)->length <= 1) return EXIT_INTERNAL_ERROR; //zkopirovat string
        else
        {
          //alloc na cilovy string
          if (((string *)i->addr3)->str != NULL) free(((string *)i->addr3)->str);
          if ((((string *)i->addr3)->str = malloc(sizeof(char) * ((string *)i->addr1)->alloc)) == NULL)
            return EXIT_INTERNAL_ERROR;

          // zkopiruju string a seradim ho
          ((string *)i->addr3)->length = ((string *)i->addr1)->length;
          strcpy(((string *)i->addr3)->str, ((string *)i->addr1)->str);
          shellSort(((string *)i->addr3)->str, ((string *)i->addr3)->length);
        }
        break;
      case I_TABLE_BACKUP:
        stackPUSH((stack *)i->addr3, (btree *)i->addr1);
        break;
      case I_TABLE_RESTORE:
        stackPOP((stack *)i->addr3, (btree *)i->addr1, (char *)i->addr2);
        break;
      default:
        return EXIT_INTERNAL_ERROR;
    }
    listItem = listItem->nextItem;
  }
  return EXIT_SUCCESS;
}
bool VirtualKinectCapture::parseFileList(const std::string vkDatas)
{
    std::ifstream fs(vkDatas.c_str());

    if (fs.is_open())
    {           
        do 
        {
            std::string line;
            std::getline(fs, line);

            if (line.empty())
                continue;

            int found = -1;
            found = line.find_first_not_of(" │:");
            if (found>=0)
            {
                line = line.substr(found);
            }

            if (line[line.length()-1] == '\n')
                line = line.substr(0, line.length()-1);

            found = findSubString(line, "depth");
            if (found>=0 && isFileReadable(line))
            {
                found = line.find_last_of('.');
                if (found>=0)
                {
                    std::string fmt = line.substr(found+1, line.length());
                    std::transform(fmt.begin(), fmt.end(), fmt.begin(), ::tolower);

                    VK_DEPTH_FILE_TYPE type = VK_DEPTH_FILE_UNKOWN; 
                    if (fmt.compare("avi") == 0)
                    {
                        type = VK_DEPTH_FILE_VIDEO;
                    }
                    else if (fmt.compare("png") == 0)
                    {
                        type = VK_DEPTH_FILE_IMAGE;
                    }

                    if (type != VK_DEPTH_FILE_UNKOWN)
                    {
                        if (depthFileType_ == VK_DEPTH_FILE_UNKOWN)
                            depthFileType_ = type;

                        // ensure that the format of depth file is unique
                        if (type == depthFileType_) 
                            depthFile_.push_back(line);
                    }
                }
            }

            found = findSubString(line, "color");
            if (found>=0 && isFileReadable(line))
            {
                found = line.find_last_of('.');
                if (found>=0)
                {
                    std::string fmt = line.substr(found+1, line.length());
                    std::transform(fmt.begin(), fmt.end(), fmt.begin(), ::tolower);

                    VK_DEPTH_FILE_TYPE type = VK_COLOR_FILE_UNKOWN;
                    if (fmt.compare("avi") == 0)
                    {
                        type = VK_COLOR_FILE_VIDEO;
                    }
                    else if (fmt.compare("png") == 0)
                    {
                        type = VK_COLOR_FILE_IMAGE;
                    }

                    if (type != VK_COLOR_FILE_UNKOWN)
                    {
                        if (colorFileType_ == VK_COLOR_FILE_UNKOWN)
                            colorFileType_ = type;

                        // ensure that the format of depth file is unique
                        if (type == colorFileType_)
                            colorFile_.push_back(line);
                    }
                }
            }

        } while (!fs.eof());
    }
    else
    {
        showError( cv::format("Failed to open %s", vkDatas.c_str()) );
    }

    if (!depthFile_.empty() && !colorFile_.empty())
    {
        //std::ofstream ofs(vkDatas.c_str(), std::ios::out);
        //if (ofs.is_open())
        //{
        //    for (int i = 0; i < depthFile_.size(); i++)
        //        ofs << depthFile_[i] << std::endl;

        //    for (int j = 0; j < colorFile_.size(); j++)
        //        ofs << colorFile_[j] << std::endl;

        //    ofs.close();
        //}

        return true;
    }
    else
        return false;
}