コード例 #1
0
ファイル: queueModule.c プロジェクト: KMikalsen/heisprosjekt
int order() {
    int i;
    int isOrder = 0;
    for ( i = 0;  i < N_FLOORS; ++i ) {
        if ( elev_get_button_signal( BUTTON_COMMAND, i ) ) {
            addOrder( BUTTON_COMMAND, i );
            isOrder = 1;
        }
    }
    if ( !isStopped() && !isStoppedObstruction() ) {
        for ( i=0; i < (N_FLOORS-1); ++i ) {
            if ( elev_get_button_signal( BUTTON_CALL_UP, i ) && !isStopped() ) {
                addOrder( BUTTON_CALL_UP, i );
                isOrder = 1;
            }
        }
        for ( i = 1; i < (N_FLOORS); ++i ) {
            if ( elev_get_button_signal( BUTTON_CALL_DOWN, i ) && !isStopped() ) {
                addOrder( BUTTON_CALL_DOWN, i );
                isOrder = 1;
            }
        }
    }
   return isOrder;
}
コード例 #2
0
ファイル: raw.cpp プロジェクト: stohrendorf/ppplay
bool RawPlayer::load(const std::string& filename)
{
    FileStream f(filename);
    if(!f)
        return false;

    // file validation section
    char id[8];
    f.read(id, 8);
    if(!std::equal(id, id + 8, "RAWADATA"))
    {
        return false;
    }

    // load section
    uint16_t clock;
    f >> clock;
    setInitialSpeed(clock);
    setCurrentSpeed(clock);

    BOOST_ASSERT(f.pos() == 10);
    static_assert(sizeof(TrackData) == 2, "Ooops");
    m_data.resize((f.size() - 10) / 2);
    f.read(m_data.data(), m_data.size());

    addOrder(0);

    rewind(0);
    return true;
}
コード例 #3
0
ファイル: mid.cpp プロジェクト: stohrendorf/ppplay
bool MidPlayer::load(const std::string& filename)
{
    FileStream f(filename);
    if(!f)
        return false;

    uint8_t s[6];
    f.read(s, 6);

    FileType good = FileType::Unknown;
    m_subsongs = 0;
    switch(s[0])
    {
        case 'A':
            if(s[1] == 'D' && s[2] == 'L')
                good = FileType::Lucas;
            break;
        case 'M':
            if(s[1] == 'T' && s[2] == 'h' && s[3] == 'd')
                good = FileType::Midi;
            break;
        case 'C':
            if(s[1] == 'T' && s[2] == 'M' && s[3] == 'F')
                good = FileType::Cmf;
            break;
        case 0x84:
            if(s[1] == 0x00 && load_sierra_ins(filename))
            {
                if(s[2] == 0xf0)
                    good = FileType::AdvSierra;
                else
                    good = FileType::Sierra;
            }
            break;
        default:
            if(s[4] == 'A' && s[5] == 'D')
                good = FileType::OldLucas;
            break;
    }

    if(good != FileType::Unknown)
        m_subsongs = 1;
    else
    {
        return false;
    }

    m_type = good;
    f.seek(0);
    m_data.resize(f.size());
    f.read(m_data.data(), m_data.size());

    addOrder(0);
    rewind(0);
    return true;
}
コード例 #4
0
ファイル: Menu.c プロジェクト: vsctiago/LP_EpR
void clientMenu(Client *clients, Order *orders, Product *products,
        int *clientCount, int *orderCounts, int *productCount) {
    int op, posLogged = 0;
    posLogged = loginClient(clients, clientCount);
    if (posLogged != EOF) {
        do {
            clientMenuPrint();
            readInt(&op, MENU_OPT_MIN, MENU_OPT_MAX, MENU_MSG_OPT);
            switch (op) {
                case 0: //exit
                    break;
                case 1:
                    cleanScreen();
                    listProducts(products, productCount);
                    break;
                case 2:
                    cleanScreen();
                    addOrder(orders, orderCounts, products, productCount, clients[posLogged].bi);
                    break;
                case 3:
                    cleanScreen();
                    listMyOrders(orders, orderCounts, clients[posLogged].bi);
                    removeOrderClient(orders, orderCounts, clients[posLogged].bi);
                    break;
                case 4: //
                    cleanScreen();
                    listMyClient(clients[posLogged]);
                    printf("\n\n");
                    break;
                case 5: //
                    cleanScreen();
                    editClient(clients, clientCount, posLogged);
                    printf("\n\n");
                    break;
                case 6: //
                    cleanScreen();
                    listMyOrders(orders, orderCounts, clients[posLogged].bi);
                    printf("\n\n");
                    break;
                case 7: //
                    cleanScreen();
                    listMyOrdersPendingApproval(orders, orderCounts, clients[posLogged].bi);
                    printf("\n\n");
                    break;
                case 8: //
                    cleanScreen();
                    listMyOrdersPendingDelivery(orders, orderCounts, clients[posLogged].bi);
                    printf("\n\n");
                    break;
                default:
                    printf(MENU_MSG_OPT_INVALID);
            }
        } while (op != 0);
    }
}
コード例 #5
0
ファイル: AddressBook.c プロジェクト: timothyong/systems
void addEntry(node ** book, char * name, char * email){
  int i;
  char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  node * entry = (node *)malloc(sizeof(node));
  strcpy(entry->name,name);
  strcpy(entry->email,email);
  for (i = 0; i < 26; i++){
    if (strncmp(alphabet+i, entry->name, 1) == 0){
      addOrder(*(book+i), entry);
      return;
    }
  }
}
コード例 #6
0
ファイル: hsp.cpp プロジェクト: stohrendorf/ppplay
bool HspPlayer::load(const std::string& filename)
{
    FileStream f(filename);
    if(!f || f.extension() != ".hsp")
        return false;

    // file validation section
    auto filesize = f.size();
    uint16_t orgsize;
    f >> orgsize;
    if(orgsize > 59187)
    {
        return false;
    }

    // load section
    std::vector<uint8_t> cmp(filesize);
    f.seek(0);
    f.read(cmp.data(), cmp.size());

    std::vector<uint8_t> org(orgsize);
    for(int i = 0, j = 0; i < filesize; j += cmp[i], i += 2)
    { // RLE decompress
        if(j >= orgsize)
            break; // memory boundary check
        std::fill_n(org.begin() + j, j + cmp[i] < orgsize ? cmp[i] : orgsize - j - 1, cmp[i + 1]);
    }

    memcpy(instrumentData(), org.data(), 128 * 12); // instruments
    for(int i = 0; i < 128; i++)
    { // correct instruments
        instrumentData()[i][2] ^= (instrumentData()[i][2] & 0x40) << 1;
        instrumentData()[i][3] ^= (instrumentData()[i][3] & 0x40) << 1;
        instrumentData()[i][11] >>= 4; // slide
    }
    for(int i = 0; i < 51; ++i)
        addOrder(org[128 * 12 + i]);
    memcpy(patternData(), org.data() + 128 * 12 + 51, orgsize - 128 * 12 - 51); // patterns

    rewind(0);
    return true;
}
コード例 #7
0
ファイル: StrikeBalanceWidget.cpp プロジェクト: YSYou/LADS2
void StrikeBalanceWidget::createActions()
{
    // Add tool tar actions for order list.
    m_addAct          = new QAction(QIcon(":/add"), tr("Add"), this);
    m_deleteAct       = new QAction(QIcon(":/delete"), tr("Delete"), this);
    m_saveAct         = new QAction(QIcon(":/ok"), tr("Save"), this);
    m_cancelAct       = new QAction(QIcon(":/cancel"), tr("Cancel"), this);
    m_findAct         = new QAction(QIcon(":/find"), tr("Find"), this);
    m_findClientAct   = new QAction(QIcon(":/find"), tr("Find Client"), this);
    
    m_deleteAct->setDisabled(true);
    m_saveAct->setDisabled(true);
    m_cancelAct->setDisabled(true);

    connect(m_addAct, SIGNAL(triggered()), this, SLOT(addOrder()));
    connect(m_deleteAct, SIGNAL(triggered()), this, SLOT(deleteOrder()));
    connect(m_saveAct, SIGNAL(triggered()), this, SLOT(saveOrder()));
    connect(m_cancelAct, SIGNAL(triggered()), this, SLOT(cancelModifiedOrder()));
    connect(m_findAct, SIGNAL(triggered()), this, SLOT(findOrder()));
    connect(m_findClientAct, SIGNAL(triggered()), this, SLOT(findClient()));
}
コード例 #8
0
ファイル: MyOrders.cpp プロジェクト: RetroShare/ZeroReserve
ZR::RetVal MyOrders::init()
{
    try {
        OrderList myorders;
        ZrDB::Instance()->loadOrders( &myorders );
        for( OrderIterator it = myorders.begin(); it != myorders.end(); it++) {
            Order * order = *it;
            addOrder( order );
            if( order->m_orderType == Order::ASK ) {
                m_asks->addOrder( order );
            }
            else {
                m_bids->addOrder( order );
            }
        }
    }
    catch( std::runtime_error & e ) {
        g_ZeroReservePlugin->placeMsg( std::string( "Exception caught: " ) + e.what() );
        return ZR::ZR_FAILURE;
    }
    return ZR::ZR_SUCCESS;
}
コード例 #9
0
ファイル: OrderManager.cpp プロジェクト: lawrencereyes/OOP345
void OrderManager::readCSV(string& file, char delim){
	ifstream is;
	vector<string> fields;

	try{
		is.open(file);

		if (is.good()){
			string buf, buf2;
			stringstream ss;

			int line = 0;

			while (getline(is, buf)){
				line++;

				ss << buf;
				while (getline(ss, buf2, delim)){
					buf2.erase(0, buf2.find_first_not_of(' '));
					buf2.erase(buf2.find_last_not_of(' ') + 1);

					if (!buf2.empty())
						fields.push_back(buf2);
				}

				addOrder(fields, line);
				fields.clear();
				ss.clear();
			}
			is.close();
		}
		else
			throw "Failed to open file: " + string(file);
	}
	catch (string err){
		cout << err << endl;
	}
}
コード例 #10
0
ファイル: addOrder.c プロジェクト: Smagen/Esercizi-C
int main ()
{
	int scelta;
	lista *testa;	//puntatore all'inizio della lista

	if (!(testa = (lista *) malloc (sizeof(lista)))) //provo ad allocare il primo elemento
	{
		printf ("Errore di allocazione!\n");
		exit(1); //se non riesce ad allocare esce con error code 1
	}
	testa->next=NULL; //ultimo elemento che punta a NULL

	do //menu
	{
		testa = addOrder(testa);
		printf ("\nVuoi inserire un altro elemento?\n0.No\n1.Si\nRisposta: ");
		scanf ("%d", &scelta);
	} while (scelta == 1);

	printf ("\nAddio!\n");

	return 0; //fine
}
コード例 #11
0
ファイル: cff.cpp プロジェクト: stohrendorf/ppplay
bool CffPlayer::load(const std::string& filename)
{
    FileStream f(filename);
    if(!f)
        return false;
    const uint8_t conv_inst[11] = { 2, 1, 10, 9, 4, 3, 6, 5, 0, 8, 7 };
    const std::array<uint16_t, 12> conv_note = { 0x16B, 0x181, 0x198, 0x1B0, 0x1CA,
        0x1E5, 0x202, 0x220, 0x241, 0x263,
        0x287, 0x2AE };

    // '<CUD-FM-File>' - signed ?
    f >> m_header;
    if(memcmp(m_header.id, "<CUD-FM-File>"
              "\x1A\xDE\xE0",
              16))
    {
        return false;
    }

    std::vector<uint8_t> module(0x10000);

    // packed ?
    if(m_header.packed)
    {
        std::unique_ptr<cff_unpacker> unpacker{ new cff_unpacker() };

        std::vector<uint8_t> packedModule;
        packedModule.resize(m_header.size + 4, 0);

        f.read(packedModule.data(), m_header.size);
        unpacker->unpack(packedModule, module);

        if(module.empty())
        {
            return false;
        }

        if(memcmp(&module[0x5E1], "CUD-FM-File - SEND A POSTCARD -", 31))
        {
            return false;
        }
    }
    else
    {
        f.read(module.data(), m_header.size);
    }

    // init CmodPlayer
    realloc_patterns(36, 64, 9);
    init_notetable(conv_note);
    init_trackord();

    // load instruments
    for(int i = 0; i < 47; i++)
    {
        memcpy(&m_instruments[i], &module[i * 32], sizeof(cff_instrument));

        for(int j = 0; j < 11; j++)
            addInstrument().data[conv_inst[j]] = m_instruments[i].data[j];

        m_instruments[i].name[20] = 0;
    }

    // number of patterns
    const auto patternCount = module[0x5E0];

    // load title & author
    m_title = stringncpy(reinterpret_cast<const char*>(&module[0x614]), 20);
    m_author = stringncpy(reinterpret_cast<const char*>(&module[0x600]), 20);

    // load orders
    {
        static constexpr auto OrderDataOffset = 0x628;
        for(int i = 0; i < 64; i++)
        {
            if(module[OrderDataOffset + i] & 0x80)
                break;

            addOrder(module[OrderDataOffset + i]);
        }
    }

    // load tracks
    int t = 0;
    for(int i = 0; i < patternCount; i++)
    {
        uint8_t old_event_byte2[9];

        memset(old_event_byte2, 0, 9);

        for(int channel = 0; channel < 9; channel++)
        {
            for(int row = 0; row < 64; row++)
            {
                const cff_event* event = reinterpret_cast<const cff_event *>(&module[0x669 + ((i * 64 + row) * 9 + channel) * 3]);
                PatternCell& cell = patternCell(t, row);

                // convert note
                if(event->byte0 == 0x6D)
                    cell.note = 127;
                else if(event->byte0)
                    cell.note = event->byte0;

                if(event->byte2)
                    old_event_byte2[channel] = event->byte2;

                // convert effect
                switch(event->byte1)
                {
                    case 'I': // set instrument
                        cell.instrument = event->byte2 + 1;
                        cell.hiNybble = cell.loNybble = 0;
                        break;

                    case 'H': // set tempo
                        cell.command = Command::SetTempo;
                        if(event->byte2 < 16)
                        {
                            cell.hiNybble = 0x07;
                            cell.loNybble = 0x0D;
                        }
                        break;

                    case 'A': // set speed
                        cell.command = Command::RADSpeed;
                        cell.hiNybble = event->byte2 >> 4;
                        cell.loNybble = event->byte2 & 15;
                        break;

                    case 'L': // pattern break
                        cell.command = Command::PatternBreak;
                        cell.hiNybble = event->byte2 >> 4;
                        cell.loNybble = event->byte2 & 15;
                        break;

                    case 'K': // order jump
                        cell.command = Command::OrderJump;
                        cell.hiNybble = event->byte2 >> 4;
                        cell.loNybble = event->byte2 & 15;
                        break;

                    case 'M': // set vibrato/tremolo
                        cell.command = Command::OplTremoloVibrato;
                        cell.hiNybble = event->byte2 >> 4;
                        cell.loNybble = event->byte2 & 15;
                        break;

                    case 'C': // set modulator volume
                        cell.command = Command::ModulatorVolume;
                        cell.hiNybble = (0x3F - event->byte2) >> 4;
                        cell.loNybble = (0x3F - event->byte2) & 15;
                        break;

                    case 'G': // set carrier volume
                        cell.command = Command::CarrierVolume;
                        cell.hiNybble = (0x3F - event->byte2) >> 4;
                        cell.loNybble = (0x3F - event->byte2) & 15;
                        break;

                    case 'B': // set carrier waveform
                        cell.command = Command::WaveForm;
                        cell.hiNybble = event->byte2;
                        cell.loNybble = 0x0F;
                        break;

                    case 'E': // fine frequency slide down
                        cell.command = Command::FineSlideDown;
                        cell.hiNybble = old_event_byte2[channel] >> 4;
                        cell.loNybble = old_event_byte2[channel] & 15;
                        break;

                    case 'F': // fine frequency slide up
                        cell.command = Command::FineSlideUp;
                        cell.hiNybble = old_event_byte2[channel] >> 4;
                        cell.loNybble = old_event_byte2[channel] & 15;
                        break;

                    case 'D': // fine volume slide
                        if(old_event_byte2[channel] & 15)
                        {
                            // slide down
                            cell.command = Command::SFXFineVolumeDown;
                            cell.loNybble = old_event_byte2[channel] & 15;
                        }
                        else
                        {
                            // slide up
                            cell.command = Command::SFXFineVolumeUp;
                            cell.loNybble = old_event_byte2[channel] >> 4;
                        }
                        break;

                    case 'J': // arpeggio
                        cell.hiNybble = old_event_byte2[channel] >> 4;
                        cell.loNybble = old_event_byte2[channel] & 15;
                        break;
                }
            }

            t++;
        }
    }

    // order loop
    setRestartOrder(0);

    // default tempo
    setInitialTempo(0x7D);

    rewind(0);

    return true;
}
コード例 #12
0
ファイル: modmodule.cpp プロジェクト: stohrendorf/ppplay
bool ModModule::load(Stream* stream, int loadMode)
{
    noConstMetaInfo().filename = stream->name();
    setTempo(125);
    setSpeed(6);
    state().globalVolume = 0x40;
    char modName[20];
    stream->read(modName, 20);
    noConstMetaInfo().title = stringncpy(modName, 20);
    const IdMetaInfo* meta = nullptr;
    if(loadMode != LoadingMode::Smp15)
    {
        // check 31-sample mod
        logger()->info(L4CXX_LOCATION, "Probing meta-info for 31-sample mod...");
        stream->seek(0x438);
        meta = findMeta(stream);
        if(meta == nullptr)
        {
            logger()->warn(L4CXX_LOCATION, "Could not find a valid module ID");
            return false;
        }
    }
    else
    {
        logger()->info(L4CXX_LOCATION, "Trying to load 15-sample mod...");
        meta = &smp15MetaInfo;
    }
    logger()->debug(L4CXX_LOCATION, "%d-channel, ID '%s', Tracker '%s'", int(meta->channels), meta->id, meta->tracker);
    noConstMetaInfo().trackerInfo = meta->tracker;
    for(int i = 0; i < meta->channels; i++)
    {
        m_channels.emplace_back(new ModChannel(this, ((i + 1) & 2) == 0));
    }
    stream->seek(20);
    const int numSamples = loadMode == LoadingMode::Smp15 ? 15 : 31;
    for(int i = 0; i < numSamples; i++)
    {
        ModSample* smp = new ModSample();
        m_samples.push_back(smp);
        if(!smp->loadHeader(stream))
        {
            logger()->warn(L4CXX_LOCATION, "Sample header could not be loaded");
            return false;
        }
    }
    uint8_t maxPatNum = 0;
    {
        // load orders
        uint8_t songLen;
        *stream >> songLen;
        if(songLen > 128)
        {
            songLen = 128;
        }
        logger()->debug(L4CXX_LOCATION, "Song length: %d", int(songLen));
        uint8_t tmp;
        *stream >> tmp; // skip the restart pos
        for(uint_fast8_t i = 0; i < songLen; i++)
        {
            *stream >> tmp;
            if(tmp >= 64)
            {
                continue;
            }
            if(tmp > maxPatNum)
            {
                maxPatNum = tmp;
            }
            logger()->trace(L4CXX_LOCATION, "Order %d index: %d", int(i), int(tmp));
            addOrder(std::make_unique<OrderEntry>(tmp));
        }
        if(loadMode != LoadingMode::Smp31Malformed)
        {
            while(songLen++ < 128)
            {
                *stream >> tmp;
                if(tmp >= 64)
                {
                    continue;
                }
                if(tmp > maxPatNum)
                {
                    maxPatNum = tmp;
                }
            }
        }
        else
        {
            stream->seekrel(128 - songLen);
        }
    }
コード例 #13
0
ファイル: dmo.cpp プロジェクト: stohrendorf/ppplay
bool DmoPlayer::load(const std::string& filename)
{
    FileStream f(filename);
    if(!f || f.extension() != ".dmo")
        return false;

    unsigned char chkhdr[16];
    f.read(chkhdr, 16);

    DMOUnpacker unpacker;
    if(!unpacker.decrypt(chkhdr, 16))
    {
        return false;
    }

    f.seek(0);

    std::vector<uint8_t> packed_module(f.size());

    // load file
    f.read(packed_module.data(), f.size());

    // decrypt
    unpacker.decrypt(packed_module.data(), packed_module.size());

    const auto unpacked_length = 0x2000 * ARRAY_AS_WORD(packed_module.data(), 12);
    std::vector<uint8_t> module(unpacked_length);

    // unpack
    if(!unpacker.unpack(packed_module.data() + 12, module.data(), unpacked_length))
    {
        return false;
    }

    // "TwinTeam" - signed ?
    if(memcmp(module.data(), "TwinTeam Module File"
              "\x0D\x0A",
              22))
    {
        return false;
    }

    // load header
    MemoryStream uf;
    uf.write(module.data(), module.size());
    uf.seek(0);

    S3mHeader header;

    uf.seekrel(22); // ignore DMO header ID string
    uf.read(header.name, 28);

    uf.seekrel(2); // _unk_1
    uf >> header.orderCount >> header.instrumentCount >> header.patternCount;
    uf.seekrel(2); // _unk_2
    uf >> header.initialSpeed >> header.initialTempo;

    header.chanset.fill(0xff);

    for(int i = 0; i < 9; i++)
        header.chanset[i] = 0x10 + i;

    uf.seekrel(32); // ignore panning settings for all 32 channels

    // load orders
    for(int i = 0; i < header.orderCount; ++i)
    {
        uint8_t tmp;
        uf >> tmp;
        addOrder(tmp);
        std::cerr << "ORD=" << int(tmp) << "\n";
    }
    addOrder(0xff);
    uf.seekrel(256 - header.orderCount);

    // load pattern lengths
    uint16_t my_patlen[100];
    uf.read(my_patlen, 100);

    // load instruments
    for(int i = 0; i < header.instrumentCount; i++)
    {
        S3mInstrument instrument;

        uf.read(instrument.name, 28);

        uf >> instrument.volume;
        uf >> instrument.dsk;
        uf >> instrument.c2spd;
        uf >> instrument.type;
        uf >> instrument.d00;
        uf >> instrument.d01;
        uf >> instrument.d02;
        uf >> instrument.d03;
        uf >> instrument.d04;
        uf >> instrument.d05;
        uf >> instrument.d06;
        uf >> instrument.d07;
        uf >> instrument.d08;
        uf >> instrument.d09;
        uf >> instrument.d0a;
        /*
         * Originally, riven sets d0b = d0a and ignores 1 byte in the
         * stream, but i guess this was a typo, so i read it here.
         */
        uf >> instrument.d0b;

        setInstrument(i, instrument);
    }

    // load patterns
    for(int pattern = 0; pattern < header.patternCount; pattern++)
    {
        const auto cur_pos = uf.pos();

        for(int row = 0; row < 64; row++)
        {
            S3mCell* currentChannel = patternChannel(pattern, row);

            while(true)
            {
                uint8_t token;
                uf >> token;

                if(!token)
                    break;

                const auto chan = token & 31;

                // note + instrument ?
                if(token & 32)
                {
                    uint8_t bufbyte;
                    uf >> bufbyte;

                    currentChannel[chan].note = bufbyte & 15;
                    currentChannel[chan].octave = bufbyte >> 4;
                    uf >> currentChannel[chan].instrument;
                }

                // volume ?
                if(token & 64)
                    uf >> currentChannel[chan].volume;

                // command ?
                if(token & 128)
                {
                    uf >> currentChannel[chan].effect;
                    uf >> currentChannel[chan].effectValue;
                }
            }
        }