void main(){
	SET_BIT(DDRB, 0);
	ini_lcd();
	clr_lcd();
	for(;;){
	pos_lcd(0,0);
	put_str_lcd("Press 1. Saria's...");
	pos_lcd(1,0);
	put_str_lcd("Press 2. Mary...");
		if (get_key() == 16)
		{
			clr_lcd();
			pos_lcd(0,2);
			put_str_lcd("Saria's Song");
			pos_lcd(1, 0);
			put_str_lcd("Press B to stop.");
			play_song(saria, 85);
			clr_lcd();
		}
		else if (get_key() == 15)
		{
			clr_lcd();
			pos_lcd(0,2);
			put_str_lcd("Mary Had A");
			pos_lcd(1, 2);
			put_str_lcd("Little Lamb");
			play_song(mary, 26);
			clr_lcd();
		}	
		wait_avr(50);
	}
}
Ejemplo n.º 2
0
void updateCScreen(CScreen *cscreen, Hammer *hammer, int *numberPCs, int *score, double mili){
	switch (cscreen->state) {
		case WINDOWS:
			if(cscreen->nextCrashTime == -1)
				cscreen->nextCrashTime = rand() % crashTimeMax;
			else {
				cscreen->nextCrashTime -= mili;
				if (cscreen->nextCrashTime <= 0) {
					cscreen->nextCrashTime = -1;
					cscreen->state = BSOD;
					cscreen->deathTime = bsodTime;
					cscreen->sprite->imgIndex++;
					play_song(cscreen->crash);
				}
			}
			// verificar colisoes com o cd
			if (hammer->state == CD_HIT && collidesSprite(hammer->sprite, cscreen->sprite))
				cscreen->state = REINSTALLED;
			break;
		case BSOD:
			cscreen->deathTime -= mili;
			if (cscreen->deathTime <= 0) {
				cscreen->state = DEATH;
				cscreen->sprite->imgIndex += 3;
				*score -= scoreDeath;
			}
			else if (hammer->state == HIT
			&& collidesSpriteRect(cscreen->sprite,
			hammer->sprite->x, hammer->sprite->y + hammer->sprite->height/2,
			hammer->sprite->width/2, hammer->sprite->height/2))
			{
				cscreen->state = WINDOWS;
				cscreen->sprite->imgIndex--;
				*score += scoreSaved;
				countedSavesUntilCD--;
				if (countedSavesUntilCD <= 0) {
					countedSavesUntilCD = savesUntilCD;
					hammer->state = GET_CD;
				}
			} else if (hammer->state == CD_HIT && collidesSprite(hammer->sprite, cscreen->sprite))
				cscreen->state = REINSTALLED;
			break;
		case REINSTALLED:
			cscreen->sprite->imgIndex = 2 + rand() % 2;
			play_song(cscreen->reinstall);
			hammer->state = GET_HAMMER;
		case DEATH:
			(*numberPCs)--;
			// aumenta dificuldade
			savesUntilCD++;
			crashTimeMax -= crashTimeDecrease;
			cscreen->state = INACTIVE;
			break;
		case INACTIVE:
			break;
		default:
			break;
	}
}
Ejemplo n.º 3
0
void super_dead_mode(){
    uint16_t counter = 0;
    while(!config.health){
        handle_music();
        // Manage base station comms
        uint8_t b;
        if(CHECK_CHAR()){
            b=AVAIL_CHAR();
            if(b == 0x10) {
                control_transfer();
            }
        }
        counter++;
        delay_1_ms();
        if(counter > config.death_period){
            counter = 0;
            led_off();
            Send_Byte(config.id);
            play_song((uint16_t*)dead_song,sizeof(dead_song)/sizeof(uint16_t),10000,0);
        }
        if(counter == config.death_period-50){
            red_led_on();
        }
    }
}
Ejemplo n.º 4
0
/******************************************************************************
* Calls the Roomba interface function given some serialized function call
******************************************************************************/
void deserialize(uint8_t* function)
{
	switch(function[0])
	{
	case INITIALIZE_ROOMBA:
		initialize_roomba();
		break;
	case SET_MODE:
		set_mode((roomba_mode_t)(function[1] - ASCII_OFFSET));
		break;
	case START_CLEAN:
		start_clean((clean_mode_t)(function[1] - ASCII_OFFSET));
		break;
	case SEND_DOCK:
		send_dock();
		break;
	case SET_WHEEL_SPEEDS:
	{
		/* high byte right, low byte right, high byte left, low byte left */
		int16_t left, right;
		right = (function[1] << 8) & function[2];
		left = (function[3] << 8) & function[4];
		set_wheel_speeds(right, left);
	}
    break;
	case TEST_MOVE:
		test_move();
		break;
    case PLAY_SONG:
        play_song(function[1] - ASCII_OFFSET);
        break;
	}
}
Ejemplo n.º 5
0
static int select_plisttrack(struct menulist *ml)
{
	atracks *at = ml->user;
	struct track *t = (*at)[0];
	play_song(ml, t);

	return 0;
}
Ejemplo n.º 6
0
//handles the music/sfx playing for the sketch
void update_sound()
{
  switch (music_state)
  {
  case SONG_PLAYING:
  case SONG_PLAYING_ONCE:
  case SONG_PLAYING_SFX:
    static long next_note_start_time = 0;
    if (millis() >= next_note_start_time)
    {
      if (current_note == song_end_pos)
      {
         switch (music_state)
         {
	    //it's the end of the song, so we can contine
	    case SONG_PLAYING:
	         music_state = SONG_ENDED;
                  break;
			  
	    case SONG_PLAYING_ONCE:
                 music_state = MUSIC_STOPPED;
                 break;	

           case SONG_PLAYING_SFX:
		//restore the old state of the music and continue
		song_note_len = old_song_note_len;
		song_end_pos = old_song_end_pos;
		current_note = old_current_note;
		music_state = old_music_state; 
                current_song = old_current_song;
                break;		   
	 }
      }
      
     //determine the current note duration
      int note_duration = ( song_note_len / pgm_read_byte_near(duration + current_note));
  	  
      next_note_start_time = millis()+note_duration;
	  
	  //play the note
      tone(9,pgm_read_word_near(melody + current_note), note_duration); 
  	
      current_note++;  
    }
    break;
	
   case SONG_ENDED:
     //start the same song over automatically
     play_song(current_song);
	 break;
   
   case MUSIC_STOPPED:
     //we are idle, until a new play action is initiated
     break;
  }
}
Ejemplo n.º 7
0
void Controller::play_current_song(const std::string &playlist_name, bool update_playlist_first) {
	if (playlist.songs.empty() || update_playlist_first) {
		// Flag to let controller know to fetch current song after fetching playlist
		should_fetch_playlist_single = true;
		fetch_playlist(playlist_name);
		return;
	}

	playlist.name = playlist_name;
	fetching_playlist_single = true;
	should_fetch_playlist_single = false;

	requests.get(build_api("/playlists/" + playlist.name), [&](const std::string &response, bool success) -> void {
		rapidjson::Document json;
		fetching_playlist_single = false;

		if (json.Parse(response.c_str()).HasParseError()) {
			log_text("json error!");
			return;
		}

		if (json.HasMember("current_song") && json.HasMember("song_start_time") && json.HasMember("requested_time")) {
			int id = json["current_song"].GetInt();

			if (playlist.songs.find(id) == playlist.songs.end()) {
				add_message("Cant find song in playlist - recache?");
			}
			else {
				int requested_time = json["requested_time"].GetInt();
				int song_start_time = json["song_start_time"].GetInt();

				int elapsed_seconds = requested_time - song_start_time;
				int time_left = playlist.songs[id].duration - elapsed_seconds;

				if (time_left < 3) {
					// nearing end. call self again since probably will want next song instead.
					should_fetch_playlist_single = true;
					return;
				}

				// assume if only a bit of time has passed, that we're still at the start (?)
				if (elapsed_seconds > 5) add_message("Seeking to %d seconds", elapsed_seconds);

				timer.reset(time_left);
				play_song(playlist.songs[id], elapsed_seconds);
			}
		}
	});
}
Ejemplo n.º 8
0
//plays a sound effect
void play_sfx(char song)
{
  //saves the current state of the song to be restored
  //when the sound effect is finished playing
  old_song_note_len = song_note_len;
  old_song_end_pos = song_end_pos;
  old_current_note = current_note;
  old_music_state = music_state;
  old_current_song = current_song;
  
  play_song(song);
  
  //override the state to a single time through
  music_state = SONG_PLAYING_SFX;
}
Ejemplo n.º 9
0
/*
Wrapper function that will play the song and also accept an input
from the A3BU keyboard buttons
*/
static void play_song_with_input(struct SongNote song[], uint8_t song_length) {
	struct keyboard_event key;
	
	while(true) {
		keyboard_get_key_state(&key);

		if((key.keycode == KEYBOARD_ENTER)
			&& (key.type == KEYBOARD_RELEASE))
		{
			break;
		}

		play_song(song, song_length);
	}
}
Ejemplo n.º 10
0
/*
 * Our main function we start of here...
 * we should make sure that we never return from here, or vectrex will
 * be surely bothered!
 */
int main(void)
{
  unsigned char anim_state;           /* our animation state counter */
  signed char pacman_x;               /* where is the pacman? */
  signed char pacman_y;
  pacman_x = 0;
  pacman_y = 0;
  anim_state = 0;
  setup();                            /* setup our program */

  while (true)                        /* never to return... */
  {
    start_one_vectrex_round();        /* start 'de round */
    intensity(MAX_BRIGHTNESS);        /* set some brightness */
    set_scale(MOVE_SCALE);            /* set scale factor */
    print_str(-128,100, "JOYTICK 1 TO MOVE PACMAN!"); /* a message! */
    move_to(pacman_x, pacman_y);      /* position pacman */
    set_scale(PACMAN_SCALE);          /* set scale factor for the sprite */
    draw_vector_list(pacman[anim_state]); /* draw the current pacman */
    anim_state++;                     /* next time the next animation */
    if (anim_state == MAX_ANIM)       /* could do a % MAXANIM, but this is */
       anim_state = 0;                /* more optimized */
    if (!read_ram(Vec_Music_Flag))    /* music finished? */
       play_song(SCRAMBLE_MUSIC);     /* if so ... restart */
    if (joystick1_x>0)                /* check the joystick and */
    {                                 /* update position */
      pacman_x++;
    }
    else if (joystick1_x<0)
    {
      pacman_x--;
    }
    if (joystick1_y>0)
    {
      pacman_y++;
    }
    else if (joystick1_y<0)
    {
      pacman_y--;
    }
    if (pacman_x>=100) pacman_x = 100;    /* make sure pacman is not */
    if (pacman_x<=-100) pacman_x = -100;  /* out of bounds */
    if (pacman_y>=100) pacman_y = 100;
    if (pacman_y<=-100) pacman_y = -100;
    joy_digital();                        /* call once per round, to insure */
  } /* while (true) */                    /* joystick information is up to date */
}
Ejemplo n.º 11
0
void reset_level_data() 
{
	// reload all data into RAM
	if (load_game_data(data)) {
		frame_handler = frame_error;
		return;
	}
	
	sprites_reset();
	player_reset();
	interpret_spritetypes();

	// apply mapper just once
	uint8_t mapper = data[255*256];
	switch (mapper) {
		case 0 : 
			black_mapper(); 
			break;

		case TRANSPARENT : 
			// null mapper
			break;

		default: 
			message("Unknown mapper ! ");
			frame_handler = frame_error;
			return;
	}

	// interpret level after mapper
	get_level_boundingbox();
	get_level_start();

	memcpy(hud,"B0 F0G0 C0 E000 D00  ",sizeof(hud));
	
	hud[1]='0'+lives;
	hud[6]='0'+level+1; 
	

	move_camera(); // avoid being negative
	
	play_song(); // start playing song

	vga_frame=0;
	coins=0;
}
Ejemplo n.º 12
0
uint8_t handle_fire(){
    static uint16_t timer = 0; // for holdoff
    static uint16_t counter = 0; // for power
    uint16_t a;

    a=ADC_read();
    if (a > config.fire_cheating){
        cheat();
    }
    if (a > config.fire_threshold && a < config.fire_cheating)
    {
        while(!my_random_number){
            my_random_number = TMR0;
        }
        if(timer < config.fire_holdoff)
        {
            timer ++;
        }
        else
        {
            if(!config.power || counter <= config.power)
            {
                if(!counter)
                {
                    green_led_on();
                    play_song((uint16_t*)fire_song,sizeof(fire_song)/sizeof(uint16_t),3000,!(config.power));
                }
                Send_Byte(config.id);
                counter++;
            }
            else
            {
                led_off();
            }
        }
    }
    else
    {
        led_off();
        if(!config.power && counter) stop_song();
        timer = 0;
        counter = 0;
        return 0;
    }
    return 1;
}
Ejemplo n.º 13
0
/**
 * Compares two times and acts on match (deadline)
 */
static void check_for_deadline(Time* current_time_struct, Time* target_time_struct)
{
    if ((current_time_struct->hours == target_time_struct->hours) 
            && (current_time_struct->minutes == target_time_struct->minutes)
            && (current_time_struct->seconds == target_time_struct->seconds)) {

        debug_printf (DEBUG_INFO, "* Alarm has been activated, decide what action to take!");

        /* Decide what action to take from the selected item in the combo */
        switch (cfg_get_single_value_as_int_with_default (config, "alarm-plugin", "action-id", 0)) {
            case 0:
                debug_printf (DEBUG_INFO, "* Attempting to play/pause");
                play_song ();
                break;
            case 1:
                debug_printf (DEBUG_INFO, "* Attempting to stop");
                stop_song ();
                break;
            case 2:
                debug_printf (DEBUG_INFO, "* Stopping and closing gmpc");
                stop_song ();
                main_quit ();
                break;
            case 3:
                debug_printf (DEBUG_INFO, "* Closing gmpc only");
                /* Friendly way of closing gmpc */
                main_quit ();
                break;
            case 4:
                debug_printf (DEBUG_INFO, "* Shutting down system");
                /* TODO: Nice way of halting a system */
                break;
            case 5:
                debug_printf (DEBUG_INFO, "* Toggling random");
                random_toggle ();
                break;
        }

        /* Disable timer, and thus the ticking timeout */
        alarm_stop();
    }
}
Ejemplo n.º 14
0
void hit_by(uint8_t who)
{
  uint16_t respawn_timer;

  add_to_hitlist(who);
  Save(FLASH_HITLIST,(uint16_t*)&hitlist,HITLIST_SIZE);

  config.health --;
  Save(FLASH_CONFIG,(uint16_t*)&config, CONFIG_SIZE);

  play_song((uint16_t*)death_song,sizeof(death_song)/sizeof(uint16_t),60000,0);

  if(!config.health)
  {
    red_led_on();
    super_dead_mode();
    return;
  }

  respawn_timer = config.respawn_delay;
  while(respawn_timer)
  {
    respawn_timer--;
    red_led_on();
    for(uint8_t i=0;i<50;i++)
    {
        handle_music();
        delay_1_ms();
    }

    if(respawn_timer < 30)
    {
        led_off();
    }
    for(uint8_t i=0;i<50;i++)
    {
        handle_music();
        delay_1_ms();
    }
  }
}
Ejemplo n.º 15
0
/* Text is an array of strings terminated by a NULL */
void scroller_sine( const struct about_text_type text[] )
{
    bool ale = mt_rand() % 2;

    int visible_lines = vga_height / LINE_HEIGHT + 1;
    int current_line = -visible_lines;
    int y = 0;
    bool fade_in = true;

    struct coin_type {
        int x, y, vel, type, cur_frame;
        bool backwards;
    } coins[MAX_COINS];
    struct {
        int x, y, ay, vx, vy;
    } beer[MAX_BEER];

    if (ale)
    {
        memset(beer, 0, sizeof(beer));
    } else {
        for (int i = 0; i < MAX_COINS; i++)
        {
            coins[i].x = mt_rand() % (vga_width - 12);
            coins[i].y = mt_rand() % (vga_height - 20 - 14);

            coins[i].vel = (mt_rand() % 4) + 1;
            coins[i].type = mt_rand() % COUNTOF(coin_defs);
            coins[i].cur_frame = mt_rand() % coin_defs[coins[i].type].frame_count;
            coins[i].backwards = false;
        }
    }

    fade_black(10);

    wait_noinput(true, true, true);

    play_song(40); // BEER

    while (!JE_anyButton())
    {
        setdelay(3);

        JE_clr256(VGAScreen);

        if (!ale)
        {
            for (int i = 0; i < MAX_COINS/2; i++)
            {
                struct coin_type *coin = &coins[i];
                blit_sprite2(VGAScreen, coin->x, coin->y, eShapes5, coin_defs[coin->type].shape_num + coin->cur_frame);
            }
        }

        for (int i = 0; i < visible_lines; i++)
        {
            if (current_line + i >= 0)
            {
                if (text[current_line + i].text == NULL)
                {
                    break;
                }

                int line_x = VGAScreen->w / 2;
                int line_y = i * LINE_HEIGHT - y;

                // smooths edges on sine-wave text
                if (text[i + current_line].effect & 0x20)
                {
                    draw_font_hv(VGAScreen, line_x + 1, line_y, text[i + current_line].text, normal_font, centered, text[i + current_line].effect & 0x0f, -10);
                    draw_font_hv(VGAScreen, line_x - 1, line_y, text[i + current_line].text, normal_font, centered, text[i + current_line].effect & 0x0f, -10);
                }

                draw_font_hv(VGAScreen, line_x, line_y, text[i + current_line].text, normal_font, centered, text[i + current_line].effect & 0x0f, -4);

                if (text[i + current_line].effect & 0x10)
                {
                    for (int j = 0; j < LINE_HEIGHT; j++)
                    {
                        if (line_y + j >= 10 && line_y + j <= vga_height - 10)
                        {
                            int waver = sinf((((line_y + j) / 2) % 10) / 5.0f * M_PI) * 3;
                            memmove(&((Uint8 *)VGAScreen->pixels)[VGAScreen->pitch * (line_y + j) + waver],
                                    &((Uint8 *)VGAScreen->pixels)[VGAScreen->pitch * (line_y + j)],
                                    VGAScreen->pitch);
                        }
                    }
                }
            }
        }

        if (++y == LINE_HEIGHT)
        {
            y = 0;

            if (current_line < 0 || text[current_line].text != NULL)
                ++current_line;
            else
                current_line = -visible_lines;
        }

        if (!ale)
        {
            for (int i = MAX_COINS/2; i < MAX_COINS; i++)
            {
                struct coin_type *coin = &coins[i];
                blit_sprite2(VGAScreen, coin->x, coin->y, eShapes5, coin_defs[coin->type].shape_num + coin->cur_frame);
            }
        }

        fill_rectangle_xy(VGAScreen, 0, 0, vga_width - 1, 14, 0);
        fill_rectangle_xy(VGAScreen, 0, vga_height - 14, vga_width - 1, vga_height - 1, 0);

        if (!ale)
        {
            for (int i = 0; i < MAX_COINS; i++)
            {
                struct coin_type *coin = &coins[i];

                if (coin->backwards)
                {
                    coin->cur_frame--;
                } else {
                    coin->cur_frame++;
                }
                if (coin->cur_frame == coin_defs[coin->type].frame_count)
                {
                    if (coin_defs[coin->type].reverse_anim)
                    {
                        coin->backwards = true;
                        coin->cur_frame -= 2;
                    } else {
                        coin->cur_frame = 0;
                    }
                }
                if (coin->cur_frame == -1)
                {
                    coin->cur_frame = 1;
                    coin->backwards = false;
                }

                coin->y += coin->vel;
                if (coin->y > vga_height - 14)
                {
                    coin->x = mt_rand() % (vga_width - 12);
                    coin->y = 0;

                    coin->vel = (mt_rand() % 4) + 1;
                    coin->type = mt_rand() % COUNTOF(coin_defs);
                    coin->cur_frame = mt_rand() % coin_defs[coin->type].frame_count;
                }
            }
        } else {
            for (uint i = 0; i < COUNTOF(beer); i++)
            {
                while (beer[i].vx == 0)
                {
                    beer[i].x = mt_rand() % (vga_width - 24);
                    beer[i].y = mt_rand() % (vga_height - 28 - 50);

                    beer[i].vx = (mt_rand() % 5) - 2;
                }

                beer[i].vy++;

                if (beer[i].x + beer[i].vx > vga_width - 24 || beer[i].x + beer[i].vx < 0) // check if the beer hit the sides
                {
                    beer[i].vx = -beer[i].vx;
                }
                beer[i].x += beer[i].vx;

                if (beer[i].y + beer[i].vy > vga_height - 28) // check if the beer hit the bottom
                {
                    if ((beer[i].vy) < 8) // make sure the beer bounces!
                    {
                        beer[i].vy += mt_rand() % 2;
                    } else if (beer[i].vy > 16) { // make sure the beer doesn't bounce too high
                        beer[i].vy = 16;
                    }
                    beer[i].vy = -beer[i].vy + (mt_rand() % 3 - 1);

                    beer[i].x += (beer[i].vx > 0 ? 1 : -1) * (i % 2 ? 1 : -1);
                }
                beer[i].y += beer[i].vy;

                blit_sprite2x2(VGAScreen, beer[i].x, beer[i].y, eShapes5, BEER_SHAPE);
            }
        }

        JE_showVGA();

        if (fade_in)
        {
            fade_in = false;
            fade_palette(colors, 10, 0, 255);

            SDL_Color white = { 255, 255, 255 };
            set_colors(white, 254, 254);
        }

        wait_delay();
    }

    fade_black(10);
}
Ejemplo n.º 16
0
int main(int argc, char **argv) {

	char filename[BUFSIZ]="intro2.ym";
	int result;
	int c;
	int next_song,first_song;

	/* Setup control-C handler to quiet the music	*/
	/* otherwise if you force quit it keeps playing	*/
	/* the last tones */
	signal(SIGINT, quiet_and_exit);

	/* Set to have highest possible priority */
	display_enable_realtime();

	/* Parse command line arguments */
	while ((c = getopt(argc, argv, "dDmhvmsnitr"))!=-1) {
		switch (c) {
			case 'd':
				/* Debug messages */
				printf("Debug enabled\n");
				dump_info=1;
				break;
			case 'D':
				/* diff mode */
				printf("Diff mode\n");
				diff_mode=1;
				break;
			case 'h':
				/* help */
				print_help(0,argv[0]);
				break;
			case 'v':
				/* version */
				print_help(1,argv[0]);
				break;
			case 'm':
				/* mono sound */
				shift_size=8;
				break;
			case 's':
				/* stereo sound */
				shift_size=16;
				break;
			case 'n':
				/* no sound */
				play_music=0;
				break;
			case 'i':
				/* i2c visualization */
				display_type=DISPLAY_I2C;
				break;
			case 't':
				/* text visualization */
				display_type=DISPLAY_TEXT;
				break;
			case 'r':
				/* repeat */
				music_repeat=1;
				break;
			default:
				print_help(0,argv[0]);
				break;
		}
	}

	first_song=optind;
	next_song=0;

	/* Initialize the Chip interface */
	if (play_music) {
		result=initialize_ay_3_8910(0);
		if (result<0) {
			printf("Error initializing bcm2835!\n");
			printf("Maybe try running as root?\n\n");
			exit(0);
		}
		result=max98306_init();
		if (result<0) {
			printf("Error initializing max98306 amp\n");
			exit(0);
		}

		printf("Headphone is: %d\n",
			max98306_check_headphone());

		if (amp_disable) {
			result=max98306_disable();
		}
		else {
			result=max98306_enable();
		}

	}

	/* Initialize the displays */
	if (visualize) {
		result=display_init(display_type);
		if (result<0) {
			printf("Error initializing display!\n");
			printf("Turning off display for now!\n");
			display_type=0;
		}
	}

	while(1) {

		if (argv[first_song+next_song]!=NULL) {
			strcpy(filename,argv[first_song+next_song]);
			next_song++;
		}
		else {
			break;
		}

		/* Play the song */
		result=play_song(filename);
		if (result==CMD_EXIT_PROGRAM) {
			break;
		}

		if (result==CMD_BACK) {
			next_song-=2;
			if (next_song<0) next_song=0;
		}
		if (result==CMD_NEXT) {
			/* already point to next song */
		}


		/* Quiet down the chips */
		if (play_music) {
			quiet_ay_3_8910(shift_size);
		}

		usleep(500000);

	}

	/* Get ready to shut down */

	/* Quiet down the chips */
	if (play_music) {
		quiet_ay_3_8910(shift_size);
		close_ay_3_8910();
		max98306_free();
	}

	/* Clear out display */
	if (visualize) {
		display_shutdown(display_type);
	}

	return 0;
}
Ejemplo n.º 17
0
int main(void){
    setup();	
	tone_length = 5;
    while(1){
    	update_status(); 
		if (sw == 0) {
	        if (btns & 0x1) {
				tone = tone_frq[btn1_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x2) {
				tone = tone_frq[btn2_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x4) {
				tone = tone_frq[btn3_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		} else if (sw == 0x1) {
			modify_pitch1(1);
		} else if (sw == 0x3) {
			modify_pitch1(-1);
		} else if (sw == 0x8) {
	        if (btns & 0x1) {
				tone = tone_frq[btn1_set2];
				play_tone(tone, tone_length);
	        } if (btns & 0x2) {
				tone = tone_frq[btn2_set2];
				play_tone(tone, tone_length);
	        } if (btns & 0x4) {
				tone = tone_frq[btn3_set2];
				play_tone(tone, tone_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set2];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set2];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set2];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set2];
				play_tone(tone, tone_length);      
			}
		} else if (sw == 0x9) {
			modify_pitch2(1);
		} else if (sw == 0xb) {
			modify_pitch2(-1);
		} else if (sw == 0xc) {
			if (btns & 0x1) {
				melody_arabix();
			} else if (btns & 0x2) {
				melody_small();
			} if (btns & 0x4) {
				tone = tone_frq[btn3_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		} else if (sw == 0xd) {
			if (btns & 0x1) {
				tone = tone_frq[btn1_set1];
				play_tone(tone, tone_length);
			} else if (btns & 0x2) {
				melody_happy();
			} else if (btns & 0x4) {
				melody_sad();
			} else if (btns & 0x8) {
				play_song();
			} if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		} else if (sw == 0xa) {
			if (btns & 0x1) {
				melody_sad();
			} if (btns & 0x2) {
				tone = tone_frq[btn2_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x4) {
				tone = tone_frq[btn3_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		}  else if (sw == 0xe) {
			if (btns & 0x1) {
				melody_slow();
			} if (btns & 0x2) {
				tone = tone_frq[btn2_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x4) {
				tone = tone_frq[btn3_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		} else if (sw == 0xf) {
			if (btns & 0x1) {
				melody_arabix();
			} if (btns & 0x2) {
				play_example(example_twinkle, twinkle_length);
	        } if (btns & 0x4) {
				play_example(example_imperial, imperial_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		} else {
	        if (btns & 0x1) {
				tone = tone_frq[btn1_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x2) {
				tone = tone_frq[btn2_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x4) {
				tone = tone_frq[btn3_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x8) {
				tone = tone_frq[btn4_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x10) {
				tone = tone_frq[btn5_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x20) {
				tone = tone_frq[btn6_set1];
				play_tone(tone, tone_length);
	        } if (btns & 0x40) {
				tone = tone_frq[btn7_set1];
				play_tone(tone, tone_length);      
			}
		}
        // Clear tones etc.
		PORTECLR = 0xff;
    }
	return 0;
}
Ejemplo n.º 18
0
void restart_song( void )
{
	unsigned int temp = song_playing;
	song_playing = -1;
	play_song(temp);
}
Ejemplo n.º 19
0
static int select_tracklist(struct menulist *ml)
{
	play_song(ml, ((struct tracklist *)ml->user)->track);
	return 0;
}
Ejemplo n.º 20
0
int main()
{

struct douban_radio* douban;
douban=(struct douban_radio*) malloc (sizeof(struct douban_radio));
memset(douban, 0, sizeof(struct douban_radio));

douban->channel=2;

douban_radio_playlist_load(douban);

int mp3_out = 0;
char com_temp[1];

init_dev(22050);
uart_fd = Uart_Init(uart_dev);

printf("douban channel %d \n", douban->channel);

while(1)													//主消息循环
{
	if(uart_read(uart_fd, protocol_buff, 1, 0) > 0)
	//if((mp3_out == 1) || (uart_read(uart_fd, protocol_buff, 1, 0) > 0))
	{
		//mp3_out = 0;
		//printf("get data\n");
		switch(protocol_buff[0])
		{	
			case COM_START:
				com_temp[0] = COM_END;
				write(uart_fd, com_temp, 1);
				break;
			case COM_TITLE:
				printf("send title!\n");
				send_title(uart_fd, douban);
				break;
			case COM_ARTIST:
				printf("send artist!\n");
				send_artist(uart_fd, douban);	
				break;
			case COM_JPG:
				printf("send jpg!\n");
				send_jpg(uart_fd, douban);
				break;
			case COM_PLAY:
				printf("douban channel %d \n", douban->channel);
				play_song(uart_fd, douban);
				//printf("play song1\n");
				//ice_mp3("http://190.220.157.52:8000");
				//mp3("/song1.mp3");
				//mp3_out = 1;								
				break;
			case NEW_LIST:
				load_list(uart_fd, douban);
			case COM_STOP:
				stop(uart_fd);
				printf("stop!\n");
				break;			
			default:
				break;
		}
	}
}

/*

int index;
struct douban_radio* douban;
douban=(struct douban_radio*) malloc (sizeof(struct douban_radio));
memset(douban, 0, sizeof(struct douban_radio));
douban->channel=2;

douban_radio_playlist_load(douban);
printf("items:\t%d\n",douban->size );
	for (index = 0; index < douban->size; index ++)
	{
		printf("picture: \t%s\n", douban->items[index].picture);
		printf("title  : \t%s\n", douban->items[index].title);
		printf("artist : \t%s\n", douban->items[index].artist);
		printf("url    : \t%s\n\n", douban->items[index].url);
		printf("index %d \n", index);
	}

free(douban);
printf("\n\n\n\n\n");


douban=(struct douban_radio*) malloc (sizeof(struct douban_radio));
memset(douban, 0, sizeof(struct douban_radio));
douban->channel=2;
douban_radio_playlist_load(douban);
//load_list(douban);


printf("items:\t%d\n",douban->size );
	for (index = 0; index < douban->size; index ++)
	{
		printf("picture: \t%s\n", douban->items[index].picture);
		printf("title  : \t%s\n", douban->items[index].title);
		printf("artist : \t%s\n", douban->items[index].artist);
		printf("url    : \t%s\n\n", douban->items[index].url);
		printf("index %d \n", index);
	}
*/

return 0;



}
Ejemplo n.º 21
0
int main()
{	
WINDOW *menu_win;
int highlight = 1,nphighlight=1;
int choice = -1,npchoice = 0;
int c,z=0,i=0,j=0;
char *line;
char *buff;
char read;
bool pause_id = false;
char *pid;
char pause[20];
FILE *f;
/////////////////////////////////////////////////// FILE START ///////////////////////////////////////////////////////////
 FILE *fp;   
   start: 
   z=0;
   fp = fopen("currentplay.txt", "r");
   while(!feof(fp))
   {
   	buff = (char *)malloc(200*sizeof(char));
   fgets(buff,80,fp);
   choices[z]=buff;
   z++;
   }
   n_choices = z;
   fclose(fp);
/////////////////////////////////////////////////// FILE END /////////////////////////////////////////////////////////////
initscr();
clear();
noecho();
cbreak();	/* Line buffering disabled. pass on everything */
startx = (80 - WIDTH) / 2;
starty = (24 - HEIGHT) / 2;
getmaxyx(stdscr,row,col);
menu_win = newwin(HEIGHT, WIDTH, starty, startx);
keypad(menu_win, TRUE);

/////////////////////////////////////////////////////////// PAINT BLACK //////////////////////////////////////////////////
start_color();
init_pair(2,COLOR_WHITE,COLOR_BLACK);
////////////////////////////////////////////////////////// PAINT BLACK //////////////////////////////////////////////////
mvprintw(0, 0, "Use arrow keys to go up and down, left and right, Press enter to select a song and space to selct lower menu choice.");
// mvprintw(1, 0, "%d %d",row,col);
refresh();
p:
print_menu(menu_win, highlight, nphighlight);
/*************************************************************************************************************/
while(1)
{	
	c = wgetch(menu_win);
	switch(c)
	{
		case KEY_UP:
			if(highlight == 1)
				highlight = n_choices-1;
			else
				--highlight;
			break;
		case KEY_DOWN:
			if(highlight == n_choices-1)
				highlight = 1;
			else
				++highlight;
			break;
		case KEY_RIGHT:
			if (nphighlight == npn_choices)
				nphighlight = 1;
			else
				nphighlight++;
			break;
		case KEY_LEFT:
			if (nphighlight == 1)
				nphighlight = npn_choices;
			else
				nphighlight--;
			break;
		case 10:
			choice = highlight;
			break;
		case 32:
			npchoice = nphighlight;
			break;
		default:
			refresh();
			break;
	}
	print_menu(menu_win, highlight, nphighlight);
	if(choice != -1 || npchoice !=0)	/* User did a choice come out of the infinite loop */
	break;
}
/*************************************************************************************************************/	


/*--------------------------------------- SONG PLAYING START------------------------------------------------------*/

if (choice != -1)
{
	curr_song= choice-1;
	play_song(menu_win);
	choice=-1;
	goto p;
}

/*--------------------------------------- SONG PLAYING ENDS------------------------------------------------------*/

else
{
	if (npchoice == 1)
	{
		system("./AddSongs.sh");
		npchoice =0;
		goto start;
	}
	else if (npchoice == 2)
	{
			f = popen("pidof mpg123", "r");
			if (f==NULL){
				printf("No song to pause!");
			}
			else {
				fgets(pid, 10, f);
			if (!pause_id){
				sprintf(pause, "kill -STOP %s", pid);
				wprintw(menu_win,"%s",pause);
				strcpy(npchoices[1], "Resume");
				system(pause);
				pause_id = true;
			}
			else {
				sprintf(pause, "kill -CONT %s", pid);
				strcpy(npchoices[1], "Pause ");	
				system(pause);
				pause_id = false;
			}
			pclose(f);
			npchoice = 0;
			goto p;
			}
	}
	else if (npchoice == 3)
	{
		system("killall mpg123 2>/dev/null");
		npchoice=0;
		curr_song = -1;
		goto p;
	}
	else if (npchoice == 4)
	{
		if (curr_song == n_choices-2)
			curr_song = 0;
		else
			curr_song++;

		npchoice = 0;
		play_song(menu_win);
		goto p;
	}
	else if (npchoice == 5)
	{
		system("./SavePlaylist.sh");
		npchoice =0;
		goto p;
	}
	else if (npchoice == 7)
	{
		clear();
		choice = -1;
		echo();
		return 0;
	}
}
clrtoeol();
refresh();
endwin();
echo();
return 0;
}
Ejemplo n.º 22
0
RoomElement hitElf(RoomElement element)
{
  //hit by a monster
  if (element.type < 50)
  {
    //check the counter, so hearts are not
    //removed unless the monster has not been 'hit'
    //already
    if (element.counter == 0)
    {
      element.counter = COUNTER_START;
      elf.hearts--;
      if (elf.hearts < 1)
      {
        //game over
        elf.state = ELFSTATE_DEAD;
      }
    }

    //when the elf and a monster 'bump,' move the monster
    //in the opposite direction
    switch (element.state)
    {
        case STATE_MOVE_UP:
            element.state = STATE_MOVE_DOWN;
            break;

        case STATE_MOVE_DOWN:
            element.state = STATE_MOVE_UP;
            break;

        case STATE_MOVE_LEFT:
            element.state = STATE_MOVE_RIGHT;
            break;

        case STATE_MOVE_RIGHT:
            element.state = STATE_MOVE_LEFT;
            break;
    }
  } else {
    switch (element.type)
    {
        case ITEM_HEART:
            if (elf.hearts < MAX_HEARTS) elf.hearts++;
            //handle the rest of the item hit
            element = hitItem(element);
            play_sfx(5);
            break;

        case ITEM_CRYSTAL:
        case ITEM_ORB:
        case ITEM_ARMOR:
        case ITEM_STAFF:
            addElfItem(element.type);
            //handle the rest of the item hit
            element = hitItem(element);
            break;

        case ITEM_PORTAL:
            //handle the rest of the item hit
            element = hitItem(element);

            if (getMapCurrentRoom() > 63)
            {
                //go to the bottom half of the map (underworld)
                setMapRoom(0);
                play_song(0);
            } else {
                //back to top half of the map (overworld)
                setMapRoom(64);
                play_song(1);
            }
            elf.x = 36;
            elf.y = 24;
            elf.facing = FACING_DOWN;
            showElf();
            break;
    }
  }

  //update the display
  updateDisplay(elf);

  return element;
}
Ejemplo n.º 23
0
//plays a song only once
void play_song_once(char song)
{
  play_song(song);
  //override the state to a single time through
  music_state = SONG_PLAYING_ONCE;
}
Ejemplo n.º 24
0
void jukebox( void )
{
	bool trigger_quit = false,  // true when user wants to quit
	     quitting = false;
	
	bool hide_text = false;

	bool fade_looped_songs = true, fading_song = false;
	bool stopped = false;

	bool fx = false;
	int fx_num = 0;

	int palette_fade_steps = 15;

	int diff[256][3];
	init_step_fade_palette(diff, vga_palette, 0, 255);

	JE_starlib_init();

	int fade_volume = tyrMusicVolume;
	
	for (; ; )
	{
		if (!stopped && !audio_disabled)
		{
			if (songlooped && fade_looped_songs)
				fading_song = true;

			if (fading_song)
			{
				if (fade_volume > 5)
				{
					fade_volume -= 2;
				}
				else
				{
					fade_volume = tyrMusicVolume;

					fading_song = false;
				}

				set_volume(fade_volume, fxVolume);
			}

			if (!playing || (songlooped && fade_looped_songs && !fading_song))
				play_song(mt_rand() % MUSIC_NUM);
		}

		setdelay(1);

		SDL_FillRect(VGAScreenSeg, NULL, 0);

		// starlib input needs to be rewritten
		JE_starlib_main();

		push_joysticks_as_keyboard();
		service_SDL_events(true);

		if (!hide_text)
		{
			char buffer[60];
			
			if (fx)
				snprintf(buffer, sizeof(buffer), "%d %s", fx_num + 1, soundTitle[fx_num]);
			else
				snprintf(buffer, sizeof(buffer), "%d %s", song_playing + 1, musicTitle[song_playing]);
			
			const int x = VGAScreen->w / 2;
			
#ifdef ANDROID
			draw_font_hv(VGAScreen, x, 170, "Press the Back button to quit the jukebox.",           small_font, centered, 1, 0);
			draw_font_hv(VGAScreen, x, 180, "Touch to change the song being played.", small_font, centered, 1, 0);
#else
			draw_font_hv(VGAScreen, x, 170, "Press ESC to quit the jukebox.",           small_font, centered, 1, 0);
			draw_font_hv(VGAScreen, x, 180, "Arrow keys change the song being played.", small_font, centered, 1, 0);
#endif
			draw_font_hv(VGAScreen, x, 190, buffer,                                     small_font, centered, 1, 4);
		}

		if (palette_fade_steps > 0)
			step_fade_palette(diff, palette_fade_steps--, 0, 255);
		
		JE_showVGA();

		wait_delay();

#ifdef ANDROID
		if (mousedown)
		{
			wait_noinput(true, true, true);
			newkey = true;
			if (mouse_x < 160)
				lastkey_sym = SDLK_LEFT;
			else
				lastkey_sym = SDLK_RIGHT;
		}
#else
		// quit on mouse click
		Uint16 x, y;
		if (JE_mousePosition(&x, &y) > 0)
			trigger_quit = true;
#endif

		if (newkey)
		{
			switch (lastkey_sym)
			{
			case SDLK_ESCAPE: // quit jukebox
			case SDLK_q:
				trigger_quit = true;
				break;

			case SDLK_SPACE:
				hide_text = !hide_text;
				break;

			case SDLK_f:
				fading_song = !fading_song;
				break;
			case SDLK_n:
				fade_looped_songs = !fade_looped_songs;
				break;

			case SDLK_SLASH: // switch to sfx mode
				fx = !fx;
				break;
			case SDLK_COMMA:
				if (fx && --fx_num < 0)
					fx_num = SAMPLE_COUNT - 1;
				break;
			case SDLK_PERIOD:
				if (fx && ++fx_num >= SAMPLE_COUNT)
					fx_num = 0;
				break;
			case SDLK_SEMICOLON:
				if (fx)
					JE_playSampleNum(fx_num + 1);
				break;

			case SDLK_LEFT:
			case SDLK_UP:
			case SDLK_LCTRL:
				play_song((song_playing > 0 ? song_playing : MUSIC_NUM) - 1);
				stopped = false;
				break;
			case SDLK_RETURN:
			case SDLK_RIGHT:
			case SDLK_DOWN:
			case SDLK_LALT:
				play_song((song_playing + 1) % MUSIC_NUM);
				stopped = false;
				break;
			case SDLK_s: // stop song
				stop_song();
				stopped = true;
				break;
			case SDLK_r: // restart song
				restart_song();
				stopped = false;
				break;

			default:
				break;
			}
		}
		
		// user wants to quit, start fade-out
		if (trigger_quit && !quitting)
		{
			palette_fade_steps = 15;
			
			SDL_Color black = { 0, 0, 0 };
			init_step_fade_solid(diff, black, 0, 255);
			
			quitting = true;
		}
		
		// if fade-out finished, we can finally quit
		if (quitting && palette_fade_steps == 0)
			break;
	}

	set_volume(tyrMusicVolume, fxVolume);
}
Ejemplo n.º 25
0
int fm_play_song(char *song_url)
{
	play_song(song_url);
}
Ejemplo n.º 26
0
void opentyrian_menu( void )
{
	typedef enum
	{
		MENU_ABOUT = 0,
		MENU_FULLSCREEN,
		MENU_SCALER,
		// MENU_DESTRUCT,
		MENU_JUKEBOX,
		MENU_RETURN,
		MenuOptions_MAX
	} MenuOptions;

	static const char *menu_items[] =
	{
		"About OpenTyrian",
		"Toggle Fullscreen",
		"Scaler: None",
		// "Play Destruct",
		"Jukebox",
		"Return to Main Menu",
	};
	bool menu_items_disabled[] =
	{
		false,
		!can_init_any_scaler(false) || !can_init_any_scaler(true),
		false,
		// false,
		false,
		false,
	};
	
	assert(COUNTOF(menu_items) == MenuOptions_MAX);
	assert(COUNTOF(menu_items_disabled) == MenuOptions_MAX);

	fade_black(10);
	JE_loadPic(VGAScreen, 13, false);

	draw_font_hv(VGAScreen, VGAScreen->surf->w / 2, 5, opentyrian_str, large_font, centered, 15, -3);

	memcpy(VGAScreen2->surf->pixels, VGAScreen->surf->pixels, VGAScreen2->surf->pitch * VGAScreen2->surf->h);

	JE_showVGA();

	play_song(36); // A Field for Mag

	MenuOptions sel = 0;

	uint temp_scaler = scaler;

	bool fade_in = true, quit = false;
	do
	{
		memcpy(VGAScreen->surf->pixels, VGAScreen2->surf->pixels, VGAScreen->surf->pitch * VGAScreen->surf->h);

		for (MenuOptions i = 0; i < MenuOptions_MAX; i++)
		{
			const char *text = menu_items[i];
			char buffer[100];

			if (i == MENU_SCALER)
			{
				snprintf(buffer, sizeof(buffer), "Scaler: %s", scalers[temp_scaler].name);
				text = buffer;
			}

			int y = i != MENU_RETURN ? i * 16 + 32 : 118;
			draw_font_hv(VGAScreen, VGAScreen->surf->w / 2, y, text, normal_font, centered, 15, menu_items_disabled[i] ? -8 : i != sel ? -4 : -2);
		}

		JE_showVGA();

		if (fade_in)
		{
			fade_in = false;
			fade_palette(colors, 20, 0, 255);
			wait_noinput(true, false, false);
		}

		tempW = 0;
		JE_textMenuWait(&tempW, false);

		if (newkey)
		{
			switch (lastkey_sym)
			{
			case SDLK_UP:
				do
				{
					if (sel-- == 0)
						sel = MenuOptions_MAX - 1;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
			case SDLK_DOWN:
				do
				{
					if (++sel >= MenuOptions_MAX)
						sel = 0;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
				
			case SDLK_LEFT:
				if (sel == MENU_SCALER)
				{
					do
					{
						if (temp_scaler == 0)
							temp_scaler = scalers_count;
						temp_scaler--;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
			case SDLK_RIGHT:
				if (sel == MENU_SCALER)
				{
					do
					{
						temp_scaler++;
						if (temp_scaler == scalers_count)
							temp_scaler = 0;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
				
			case SDLK_RETURN:
				switch (sel)
				{
				case MENU_ABOUT:
					JE_playSampleNum(S_SELECT);

					scroller_sine(about_text);

					memcpy(VGAScreen->surf->pixels, VGAScreen2->surf->pixels, VGAScreen->surf->pitch * VGAScreen->surf->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case MENU_FULLSCREEN:
					JE_playSampleNum(S_SELECT);

					if (!init_scaler(scaler, !fullscreen_enabled) && // try new fullscreen state
						!init_any_scaler(!fullscreen_enabled) &&     // try any scaler in new fullscreen state
						!init_scaler(scaler, fullscreen_enabled))    // revert on fail
					{
						exit(EXIT_FAILURE);
					}
					break;
					
				case MENU_SCALER:
					JE_playSampleNum(S_SELECT);

					if (scaler != temp_scaler)
					{
						if (!init_scaler(temp_scaler, fullscreen_enabled) &&   // try new scaler
							!init_scaler(temp_scaler, !fullscreen_enabled) &&  // try other fullscreen state
							!init_scaler(scaler, fullscreen_enabled))          // revert on fail
						{
							exit(EXIT_FAILURE);
						}
					}
					break;
					
				case MENU_JUKEBOX:
					JE_playSampleNum(S_SELECT);

					fade_black(10);
					jukebox();

					memcpy(VGAScreen->surf->pixels, VGAScreen2->surf->pixels, VGAScreen->surf->pitch * VGAScreen->surf->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case MENU_RETURN:
					quit = true;
					JE_playSampleNum(S_SPRING);
					break;
					
				case MenuOptions_MAX:
					assert(false);
					break;
				}
				break;
				
			case SDLK_ESCAPE:
				quit = true;
				JE_playSampleNum(S_SPRING);
				break;
				
			default:
				break;
			}
		}
	} while (!quit);
}
Ejemplo n.º 27
0
Archivo: play.c Proyecto: tafox/plyr
int main(int argc, char *argv[]) {
    FILE *fp = fopen(argv[1], "r");
    play_song(fp);
    return 0;
}
Ejemplo n.º 28
0
void opentyrian_menu( void )
{
	static const char *menu_items[] =
	{
		"About OpenTyrian",
		"Toggle Fullscreen",
		"Scaler: None",
		// "Play Destruct",
		"Jukebox",
		"Return to Main Menu",
	};
	bool menu_items_disabled[] =
	{
		false,
		!can_init_any_scaler(false) || !can_init_any_scaler(true),
		false,
		// false,
		false,
		false,
	};
	
	fade_black(10);
	JE_loadPic(VGAScreen, 13, false);

	draw_font_hv(VGAScreen, VGAScreen->w / 2, 5, opentyrian_str, large_font, centered, 15, -3);

	memcpy(VGAScreen2->pixels, VGAScreen->pixels, VGAScreen2->pitch * VGAScreen2->h);

	JE_showVGA();

	play_song(36); // A Field for Mag

	int sel = 0;
	const int maxSel = COUNTOF(menu_items) - 1;

	uint32_t temp_scaler = scaler;

	bool fade_in = true, quit = false;
	do
	{
		memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);

		for (int i = 0; i <= maxSel; i++)
		{
			const char *text = menu_items[i];
			char buffer[100];

			if (i == 2) /* Scaler */
			{
				snprintf(buffer, sizeof(buffer), "Scaler: %s", scalers[temp_scaler].name);
				text = buffer;
			}

			int y = i != maxSel ? i * 16 + 32 : 118;
			draw_font_hv(VGAScreen, VGAScreen->w / 2, y, text, normal_font, centered, 15, menu_items_disabled[i] ? -8 : i != sel ? -4 : -2);
		}

		JE_showVGA();

		if (fade_in)
		{
			fade_in = false;
			fade_palette(colors, 20, 0, 255);
			wait_noinput(true, false, false);
		}

		tempW = 0;
		JE_textMenuWait(&tempW, false);

		if (newkey)
		{
			switch (lastkey_sym)
			{
			case SDLK_UP:
				do
				{
					if (--sel < 0)
						sel = maxSel;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
			case SDLK_DOWN:
				do
				{
					if (++sel > maxSel)
						sel = 0;
				}
				while (menu_items_disabled[sel]);
				
				JE_playSampleNum(S_CURSOR);
				break;
				
			case SDLK_LEFT:
				if (sel == 2)
				{
					do
					{
						if (temp_scaler == 0)
							temp_scaler = scalers_count;
						temp_scaler--;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
			case SDLK_RIGHT:
				if (sel == 2)
				{
					do
					{
						temp_scaler++;
						if (temp_scaler == scalers_count)
							temp_scaler = 0;
					}
					while (!can_init_scaler(temp_scaler, fullscreen_enabled));
					
					JE_playSampleNum(S_CURSOR);
				}
				break;
				
			case SDLK_RETURN:
				switch (sel)
				{
				case 0: /* About */
					JE_playSampleNum(S_SELECT);

					scroller_sine(about_text);

					memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case 1: /* Fullscreen */
					JE_playSampleNum(S_SELECT);

					if (!init_scaler(scaler, !fullscreen_enabled) && // try new fullscreen state
						!init_any_scaler(!fullscreen_enabled) &&     // try any scaler in new fullscreen state
						!init_scaler(scaler, fullscreen_enabled))    // revert on fail
					{
						exit(EXIT_FAILURE);
					}
					set_palette(colors, 0, 255); // for switching between 8 bpp scalers
					break;
					
				case 2: /* Scaler */
					JE_playSampleNum(S_SELECT);

					if (scaler != temp_scaler)
					{
						if (!init_scaler(temp_scaler, fullscreen_enabled) &&   // try new scaler
							!init_scaler(temp_scaler, !fullscreen_enabled) &&  // try other fullscreen state
							!init_scaler(scaler, fullscreen_enabled))          // revert on fail
						{
							exit(EXIT_FAILURE);
						}
						set_palette(colors, 0, 255); // for switching between 8 bpp scalers
					}
					break;
					
				case 3: /* Jukebox */
					JE_playSampleNum(S_SELECT);

					fade_black(10);
					jukebox();

					memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);
					JE_showVGA();
					fade_in = true;
					break;
					
				case 4: /* Return to main menu */
					quit = true;
					JE_playSampleNum(S_SPRING);
					break;
				}
				break;
				
			case SDLK_ESCAPE:
				quit = true;
				JE_playSampleNum(S_SPRING);
				break;
				
			default:
				break;
			}
		}
	} while (!quit);
}
Ejemplo n.º 29
0
int main() {
	
	int noteBuffer[SONG_SIZE];
	int accidentals[SONG_SIZE];
	int octaveBuffer[SONG_SIZE];
	
	memcpy(noteBuffer, rom_notes, SONG_SIZE*sizeof(int));
	memcpy(accidentals, rom_accidentals, SONG_SIZE*sizeof(int));
	memcpy(octaveBuffer, rom_octaves, SONG_SIZE*sizeof(int));
	const int buf_size = SONG_SIZE;
    
    //uint8 selected;
	initHardware();
	int start = 0;
	while (1) {
		//glcd_clear();
		glcd_tiny_set_font(Font5x7,5,7,32,127);
		update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
		if (start > 0) {
			glcd_draw_string_xy(13*6,0,"^");
		}
		if (start+4 < buf_size) {
			glcd_draw_string_xy(13*6,5*8,"v");
		}
		glcd_draw_char_xy(13*6,1*8,(start/4+1)/100%10+'0');
		glcd_draw_char_xy(13*6,2*8,(start/4+1)/10%10+'0');
		glcd_draw_char_xy(13*6,3*8,(start/4+1)%10+'0');
		glcd_write();
		/*
		start+=4;
		if (start > 24) start = 0;
		*/
		
		int reading = 0;
		not_scroll:
		reading = Keypad_1_GetButton();
		switch (reading) {
			case 7:
				if (start+4 < buf_size) start+=4;
				break;
			case 15:
				if (start > 0) start-=4;
				break;
			case 3:
				play_song(noteBuffer, accidentals, octaveBuffer, buf_size);
				break;
			case 0:
				for (int i = 0; i < 4; ++i) {
					glcd_invert_area(i*18, 0, 6, 8);
					glcd_write();
					CyDelay(200);
					int button = 7;
					while (button > 6) {
						button = keycode_to_note[Keypad_1_GetButton()];
					}
					noteBuffer[start+i] = button;
					update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
					glcd_invert_area(i*18+6, 0, 6, 8);
					glcd_write();
					CyDelay(200);
					button = 2;
					while (button > 1) {
						button = keycode_to_accidental[Keypad_1_GetButton()];
						if (button == 99) goto cancel_edit;
					}
					accidentals[start+i] = button;
					update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
					glcd_invert_area(i*18+12, 0, 6, 8);
					glcd_write();
					CyDelay(200);
					button = 10;
					while (button > 9) {
						button = keycode_to_octave[Keypad_1_GetButton()];
						if (button == 99) goto cancel_edit;
					}
					octaveBuffer[start+i] = button;
					update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
				}
				cancel_edit:
				break;
			case 1:
				glcd_clear();
				glcd_draw_string_xy(0,0,"Saving...");
				glcd_write();
				int fail = 0;
				fail += CYRET_SUCCESS!=Em_EEPROM_Write((void*)noteBuffer, (void*)rom_notes, SONG_SIZE*sizeof(int));
				fail += CYRET_SUCCESS!=Em_EEPROM_Write((void*)accidentals, (void*)rom_accidentals, SONG_SIZE*sizeof(int));
				fail += CYRET_SUCCESS!=Em_EEPROM_Write((void*)octaveBuffer, (void*)rom_octaves, SONG_SIZE*sizeof(int));
				if (fail) {
					glcd_draw_string_xy(0,8,"Failed!");
					glcd_write();
					CyDelay(1000);
				}
				else {
					glcd_draw_string_xy(0,8,"Success!");
					glcd_write();
					CyDelay(300);
				}
				break;
			default:
				goto not_scroll;
		}
		CyDelay(50);
	}
}
Ejemplo n.º 30
0
static int select_track(struct menulist *ml)
{
	play_song(ml, (struct track *)ml->user);

	return 0;
}