Beispiel #1
0
int main ()
{

    // SongToPlayPtr* songArray = malloc (sizeof(SongToPlayPtr)*NUM_SONGS); //heap
    SongToPlayPtr songArrayStack[NUM_SONGS]; //Stack version
    QueuePtr  myQueue = malloc(sizeof(QueuePtr));

    for (int i = 0; i <  NUM_SONGS; i++)
    {
        char name[40];
        printf("Name of song to add\n");
        gets(name);
        // scanf("%39c", name);


        SongToPlay *newsong = initSong(name);

        songArrayStack[i] = newsong;

        if (i > 0) {
            if(i == NUM_SONGS)
            {
                songArrayStack[i] = NULL;
            }
            else
            {
                (songArrayStack[i]->next = songArrayStack[i-1]);
            }
        }

        initQueue();

        myQueue->head = songArrayStack[0];
        myQueue->tail = songArrayStack[NUM_SONGS-1];

        //      displaySong (newsong);


        for (int j = 0; j < NUM_SONGS; j++)
        {
            destroySong (songArrayStack[j]);
        }
    }


}
Beispiel #2
0
int main ()
{

  // SongToPlayPtr* songArray = malloc (sizeof(SongToPlayPtr)*NUM_SONGS); //heap
  SongToPlayPtr songArrayStack[NUM_SONGS]; //Stack version
  QueuePtr myQueue;

  myQueue = initQueue();

  for (int i = 0; i <  NUM_SONGS; i++) {
       char name[40]; 
       printf("Name of song to add\n");
       gets(name);
       // scanf("%39c", name);

       SongToPlay *newsong = initSong(name);

         songArrayStack[i] = newsong;
     


     if (i > 0) {
	 songArrayStack[i-1]->next = songArrayStack[i];
         }

    }

   myQueue->head = songArrayStack[0];
   myQueue->tail = songArrayStack[NUM_SONGS-1];

  // go use your queue here

  printQueue (myQueue);

  // destroy your queue
  for (int j = 0; j < NUM_SONGS; j++) {
    destroySong (songArrayStack[j]);
  }
  // last step is to free up the allocated Queue object
  free((void *) myQueue);
}
Beispiel #3
0
int main ()
{

    SongToPlayPtr* songArray = malloc (sizeof(SongToPlayPtr)*NUM_SONGS); //heap
    SongToPlayPtr currSong;


    QueuePtr myQueue;

    myQueue = initQueue();

    for (int i = 0; i <  NUM_SONGS; i++) {
        char name[40];
        printf("Name of song to add\n");
        gets(name);
        // scanf("%39c", name);

        SongToPlay *newsong = initSong(name);


        *songArray = newsong;
        currSong = *songArray;


        SongToPlay *prevsong;



        if (i > 0)
        {

            prevsong->next = currSong;
        }

        prevsong = newsong;
        printf ("%s\n", prevsong->Title);


        if (i == 0) {
            myQueue->head = *songArray;
        }

        if (i == NUM_SONGS) {
            myQueue->tail = *songArray;
        }

        songArray++;

    }


    // go use your queue here

    printQueue (myQueue);

    // destroy your queue
    for (int j = 0; j < NUM_SONGS; j++) {
        //  destroySong (songArrayStack[j]);
    }
    // last step is to free up the allocated Queue object
    free((void *) myQueue);
}
Beispiel #4
0
SongIterator *Sci1SongIterator::handleMessage(Message msg) {
	if (msg._class == _SIMSG_BASE) { /* May extend this in the future */
		switch (msg._type) {

		case _SIMSG_BASEMSG_PRINT: {
			int playmask = 0;
			int i;

			for (i = 0; i < _numChannels; i++)
				playmask |= _channels[i].playmask;

			print_tabs_id(msg._arg.i, ID);
			debugC(2, kDebugLevelSound, "SCI1: chan-nr=%d, playmask=%04x\n",
			        _numChannels, playmask);
		}
		break;

		case _SIMSG_BASEMSG_STOP: {
			songit_id_t sought_id = msg.ID;
			int i;

			if (sought_id == ID) {
				ID = 0;

				for (i = 0; i < _numChannels; i++)
					_channels[i].state = SI_STATE_FINISHED;
			}
			break;
		}

		case _SIMSG_BASEMSG_SET_PLAYMASK:
			if (msg.ID == ID) {
				channel_mask = 0;

				_deviceId
				= sci0_to_sci1_device_map
				  [sci_ffs(msg._arg.i & 0xff) - 1]
				  [sfx_pcm_available()]
				  ;

				if (_deviceId == 0xff) {
					warning("[iterator] Device %d(%d) not supported",
					          msg._arg.i & 0xff, sfx_pcm_available());
				}
				if (_initialised) {
					int i;
					int toffset = -1;

					for (i = 0; i < _numChannels; i++)
						if (_channels[i].state != SI_STATE_FINISHED
						        && _channels[i].total_timepos > toffset) {
							toffset = _channels[i].total_timepos
							          + _channels[i].timepos_increment
							          - _channels[i].delay;
						}

					/* Find an active channel so that we can
					** get the correct time offset  */

					initSong();

					toffset -= _delayRemaining;
					_delayRemaining = 0;

					if (toffset > 0)
						return new_fast_forward_iterator(this, toffset);
				} else {
					initSong();
					_initialised = true;
				}

				break;

			}

		case _SIMSG_BASEMSG_SET_LOOPS:
			if (msg.ID == ID)
				_loops = (msg._arg.i > 32767) ? 99 : 0;
			/* 99 is arbitrary, but we can't use '1' because of
			** the way we're testing in the decoding section.  */
			break;

		case _SIMSG_BASEMSG_SET_HOLD:
			_hold = msg._arg.i;
			break;
		case _SIMSG_BASEMSG_SET_RHYTHM:
			/* Ignore */
			break;

		case _SIMSG_BASEMSG_SET_FADE: {
			fade_params_t *fp = (fade_params_t *) msg._arg.p;
			fade.action = fp->action;
			fade.final_volume = fp->final_volume;
			fade.ticks_per_step = fp->ticks_per_step;
			fade.step_size = fp->step_size;
			break;
		}

		default:
			warning("Unsupported command %d to SCI1 iterator", msg._type);
		}
		return this;
	}
	return NULL;
}
Beispiel #5
0
int Sci1SongIterator::nextCommand(byte *buf, int *result) {

	if (!_initialised) {
		//printf("[iterator] DEBUG: Initialising for %d\n", _deviceId);
		_initialised = true;
		if (initSong())
			return SI_FINISHED;
	}


	if (_delayRemaining) {
		int delay = _delayRemaining;
		_delayRemaining = 0;
		return delay;
	}

	int retval = 0;
	do {	 /* All delays must be processed separately */
		int chan = getCommandIndex();

		if (chan == COMMAND_INDEX_NONE) {
			return SI_FINISHED;
		}

		if (chan == COMMAND_INDEX_PCM) {

			if (_samples.begin()->announced) {
				/* Already announced; let's discard it */
				Audio::AudioStream *feed = getAudioStream();
				delete feed;
			} else {
				int delay = _samples.begin()->delta;

				if (delay) {
					updateDelta(delay);
					return delay;
				}
				/* otherwise we're touching a PCM */
				_samples.begin()->announced = true;
				return SI_PCM;
			}
		} else { /* Not a PCM */

			retval = processMidi(buf, result,
			                     &(_channels[chan]),
			                     PARSE_FLAG_LOOPS_UNLIMITED);

			if (retval == SI_LOOP) {
				_numLoopedChannels++;
				_channels[chan].state = SI_STATE_PENDING;
				_channels[chan].delay = 0;

				if (_numLoopedChannels == _numActiveChannels) {
					int i;

					/* Everyone's ready: Let's loop */
					for (i = 0; i < _numChannels; i++)
						if (_channels[i].state == SI_STATE_PENDING)
							_channels[i].state = SI_STATE_DELTA_TIME;

					_numLoopedChannels = 0;
					return SI_LOOP;
				}
			} else if (retval == SI_FINISHED) {
#ifdef DEBUG
				fprintf(stderr, "FINISHED some channel\n");
#endif
			} else if (retval > 0) {
				int sd ;
				sd = getSmallestDelta();

				if (noDeltaTime() && sd) {
					/* No other channel is ready */
					updateDelta(sd);

					/* Only from here do we return delta times */
					return sd;
				}
			}

		} /* Not a PCM */

	} while (retval > 0);

	return retval;
}