⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player.c

📁 本程序为ST公司开发的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  				else  				  dir = XAR_DirParent(dir);  			}  			return b_FALSE;      //we went outside with file from current parent tree		  }		  else  //audo tracks check		  {#ifdef AUDIO_AS_DIRECTORY				    if (1 == volume)          return b_TRUE;  		  else  			  return b_FALSE;					#else        return b_FALSE;#endif		  }		  		case RANGE_VOLUME:		  if (XAR_NodeType(song) != XTYPE_TRACK)    //data track		  {		            song_volume = XAR_VolumeForItem(song);        if (volume == song_volume)          return b_TRUE;  		  else  			  return b_FALSE;							  }		  else  //audo tracks check		  {		    if (1 == volume)          return b_TRUE;  		  else  			  return b_FALSE;							  }  	    		case RANGE_DEVICE:						  if (XAR_NodeType(song) != XTYPE_TRACK)    //data track		  {		            song_volume = XAR_VolumeForItem(song);        song_device = XAR_VolumeDeviceType(song_volume);                if (player_params->device == song_device)          return b_TRUE;  		  else  			  return b_FALSE;					          		  }		  else  //audo tracks check		  {		    if (1 == volume)          return b_TRUE;  		  else  			  return b_FALSE;							  }	  case RANGE_PLAYLIST:	    for (i = 0; i< player_playlist->array_items; i++)	    {	      if (song == (player_playlist->array[i] + player_playlist->first_volume_node))	        return b_TRUE;	    }	    return b_FALSE;	    		case RANGE_ALL_VOLUMES:		  return b_TRUE;          //by defalut		default:		  return b_FALSE;    }}/******************************************************************************//* Function:  player_check_shuffle_range			                            *//*                                                                            *//*! \brief	  checks if during shuffle on selected file is inside range,  *            otherwise erase shuffled marks, recalculate shuffle params *  \param    int16 song, int16 player_song, t_player_params * player_params *            const t_player_playlist * player_playlist *  \return   t_bool b_TRUE - shuffle params changed, b_FALSE - no action   *  \remark *//******************************************************************************/t_bool player_check_shuffle_range(t_XItem song, t_XItem player_song, t_player_params * player_params, t_player_playlist * player_playlist){  t_bool shuffle_success = b_FALSE;    //in case, shuffle off, no action needed  if ((SHUFFLE_OFF == player_params->shuffle) || (0 == song))    return b_FALSE;    if (b_TRUE == player_song_is_in_current_range(song,player_song,player_params, player_playlist))  {    //song is in range, no action needed    return b_FALSE;         }  else    {    //clear current shuffle settings (with marks of played songs)    player_params->shuffle = SHUFFLE_OFF;    player_shuffle_set_params(player_song,player_params, player_playlist);      player_params->shuffle = SHUFFLE_ON;		shuffle_success = player_shuffle_set_params(song,player_params, player_playlist);      if (b_FALSE == shuffle_success)    {        //tbd, report,that shuffle is not possible to set with selected song    }    return b_TRUE;  }}/******************************************************************************//* Function:  player_shuffle_selection			                                  *//*                                                                            *//*! \brief	  generates shuffled song index according to range and repeat *  \param    GRESULT current_song, t_player_params * player_params               t_player_playlist * player_playlist *  \return   int16	 next song index ( 0 - no song,                                 range 1 - 0x8fff )              in case of playlist enabled also player_playlist->prepared_array_index is set *  \remark *//******************************************************************************/t_XItem player_shuffle_selection(t_XItem current_song, t_player_params * player_params, t_player_playlist * player_playlist){	t_XItem song_index;	uint32  volume;	uint32  num_nexts = 0;      	uint32  count = 0;	t_bool  end_reached = b_FALSE;	  // ------------------- Shuffle functionality ------------------  // Notes:  // shuffle mode doesn't care about direction, just generates random file according to range, repeat mode  // if shuffle mode is switched off, use ClearShuffleFlags(t_range range,t_player_params * player_params)  // RANGE_DEVICE: range_num = count of CDCA + CDDA (CDDA are appended to list at the end)   // for addressing CDDA songs, see calcualtion of song_index  if ((player_params->range_num>0) && (player_params->range_num == player_params->shuffle_index))  {      if (player_params->repeat == REPEAT_ON)      {        player_params->shuffle_index = 0;#ifdef PLAYER_DEBUG        printf("player: Clearing shuffle index = 0\r\n");#endif      	                                            ClearSongMarks(current_song, player_params, player_playlist);      }      else        return 0; //all files have been already played in current range (REPEAT OFF)  }  //range exists, choose file    if (player_params->range_num)                 {    switch (player_params->range)    {      case RANGE_DEVICE:                num_nexts = Random(&rndNextSeed ,(player_params->range_num) - 1 ) + 1;  //different func for song choosing(accepts params 1 ~ N)        count = CountFilesForDevice(player_params->device, b_FALSE, SEARCH_PLAYABLE);    //exclude CDDA (audio tracks)        while(1)  //used in case of song has been already played        {          if (num_nexts > count)          //CDDA addressing            song_index = num_nexts - count;          else          //CDCA addressing            song_index = FindIndexForItemNr(num_nexts, player_dir_numbering, player_params->device, SEARCH_PLAYABLE);                    if (b_TRUE == IsSongAlreadyPlayed(song_index, player_playlist))          {            if (num_nexts < player_params->range_num )              num_nexts++;            else            {                              if (b_TRUE == end_reached) //this case shouldn't occur - unsynchonised song marks and shuffle_index!!                return 0;              end_reached = b_TRUE; //prevent everlasting loop              num_nexts = 1;            }          }          else          {            if (XAR_NodeType(song_index) == XTYPE_TRACK)            {                              if (!toc_is_track_rom(song_index))                  //if rom track choosen(range audio but data track is not playable),mark it, choose next song imeediatelly              {                                player_params->device = DEV_CD_ID;                //used for case of all volumes                 return song_index;              }              else              {                           	//if choosen data track in range of audio, mark imeediatelly                   MarkSongAsPlayed(song_index, player_playlist);    //mark rom track, continue selecting another song !!!                              }            }            else            {                              player_params->device = XAR_DeviceTypeForItem(song_index); //used for case of all volumes               return song_index;            }          }        }      case RANGE_DIRECTORY:      case RANGE_SUBDIRS:      case RANGE_VOLUME:        num_nexts = Random(&rndNextSeed ,(player_params->range_num) - 1 );    //for N-times next        song_index = player_params->range_from;                if (XAR_NodeType(song_index) == XTYPE_TRACK)          volume = 1;        else          volume = XAR_VolumeForItem(current_song);                          while(1)  //used in case of song has been already played        {                    for (count = 0; count < num_nexts;count++)    //-1 bcs we re already on first song           {        //do next random times (but in range)            if (volume == 1)              song_index = find_next_track(song_index, FORWARD, FALSE);             else              song_index = XAR_NextSong(volume, song_index,0);          }          if (S_TRUE == IsSongAlreadyPlayed(song_index, player_playlist))           {                            if (num_nexts < ((player_params->range_num) -1))              num_nexts++;                                             else            {                              if (b_TRUE == end_reached) //this case shouldn't occur - unsynchonised song marks and shuffle_index!!                return 0;              end_reached = b_TRUE;//prevent everlasting loop              num_nexts = 0;                              }            song_index = player_params->range_from;                          }            else //we hit still not played file          {            if (volume == 1)            {              if (!toc_is_track_rom(song_index))                  //if rom track choosen,mark it, choose next song imeediatelly              {                return song_index;              }              else              {                              	//if choosen data track in range of audio, mark imeediatelly                   MarkSongAsPlayed(song_index, player_playlist);    //mark rom track              }                            }            else            {              return song_index;            }           }        }                /* There are possible 2 approaches to put marks about already played songs */        /* One is to put marks (already played song into X_array - it causes for playlists to play 1 physical file only once,            also in case that same file is inside playlist more times used */        /* Second approach is to put marks exactly to playlist field */        /* This solution plays exactly amount of found files in playlist (independet from same file occurencies */                   /* Now implemented solution One (marks in X_array) */      case RANGE_PLAYLIST:                  num_nexts = Random(&rndNextSeed ,(player_playlist->array_items) - 1 );    //for N-times next /* JS fix 9.11.2007 issue#16 use playlist count of items instead of player_params, which is only copied (fixing bug of scenario shuffle set, then playlist enabled)*/         song_index = player_playlist->first_volume_node + player_playlist->array[num_nexts];                while(1)  //used in case of song has been already played        {                    if (S_TRUE == IsSongAlreadyPlayed(num_nexts, player_playlist))           {                            if (num_nexts < ((player_playlist->array_items) -1)) /* JS fix 9.11.2007 issue#16 use playlist count of items instead of player_params, which is only copied (fixing bug of scenario shuffle set, then playlist enabled)*/               num_nexts++;                                             else            {                              if (b_TRUE == end_reached)                 return 0;              end_reached = b_TRUE;//prevent everlasting loop              num_nexts = 0;                              }            song_index = player_playlist->first_volume_node + player_playlist->array[num_nexts];              }            else //we hit still not played file          {            player_playlist->prepared_array_index = num_nexts;            return song_index;          }        }      //won't be supporeted at all        case RANGE_ALL_VOLUMES:        return 0;    } //range switch        }  else  {    return 0;      }   return 0;}/******************************************************************************//* Function:  player_song_selection			                                      *//*                                                                            *//*! \brief	  Generates next song index according to direction and range *  \param    int16 current_song, t_direction direction,               t_player_params * player_params, t_player_playlist * player_playlist  *  \return   int16	 next song index ( 0 - no song, range 1 - 0x8fff ) *  \remark *//******************************************************************************/t_XItem player_song_selection(t_XItem current_song, t_direction direction, t_player_params * player_params,  t_player_playlist * player_playlist){	t_XItem next_song = 0;	t_XItem dir,index;	t_XItem parent;	t_XItem tmp  = 0;	t_XItem tmp2 = 0;  t_direction temp_direction = FORWARD;  t_volume_selection_struct volume_selection_struct;	uint32 volume;	uint32 previous_volume = 0;					  //everlasting loop prevention	    //find proper volume for current song  if (XAR_NodeType(current_song) == XTYPE_TRACK)    {        volume = 1;  }  else  {    volume = XAR_VolumeForItem(current_song);  }  //find correct volume according to direction (1st or last one)	if (0 == current_song) 	{    volume_selection_struct.volume = 0;    volume_selection_struct.audio_first = player_params->audio_tracks_first;    volume_selection_struct.repeat = REPEAT_ON;	  		switch(direction) 		{			case FORWARD:			case DIR_SUBDIR:			case DIR_NEXT:        volume_selection_struct.direction = FORWARD;			  if (player_params->range == RANGE_ALL_VOLUMES)			  {          volume_selection_struct.device = DEV_NO_DEVICE;			      				volume = XAR_FindNextVolume(&volume_selection_struct);				//find first valid volume			  			  }			  else			  {          volume_selection_struct.device = player_params->device;			    			      				volume = XAR_FindNextVolume(&volume_selection_struct);				//find first valid volume			  }				break;									case DIR_PARENT:			case DIR_PREVIOUS:			case BACKWARD:        volume_selection_struct.direction = BACKWARD;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -