示例#1
0
文件: tk_c.c 项目: avm/timidity
static int cmsg(int type, int verbosity_level, char *fmt, ...)
{
	char local[2048];
#define TOO_LONG	2000

	va_list ap;
	if ((type==CMSG_TEXT || type==CMSG_INFO || type==CMSG_WARNING) &&
	    ctl.verbosity<verbosity_level)
		return 0;

	va_start(ap, fmt);
	if (strlen(fmt) > TOO_LONG)
		fmt[TOO_LONG] = 0;
	if (!ctl.opened) {
		vfprintf(stderr, fmt, ap);
		fprintf(stderr, "\n");
	} else if (type == CMSG_ERROR) {
		int32 val;
		vsnprintf(local, sizeof(local), fmt, ap);
		k_pipe_printf("CERR %d", type);
		k_pipe_puts(local);
		while (ctl_blocking_read(&val) != RC_NEXT)
			;
	} else {
		vsnprintf(local, sizeof(local), fmt, ap);
		k_pipe_printf("CMSG %d", type);
		k_pipe_puts(local);
	}
	va_end(ap);
	return 0;
}
示例#2
0
/*
 * Read information coming from the window in a non blocking way
 */
static int ctl_read(int32 *valp)
{
  int num;

  /* We don't wan't to lock on reading  */
  num=m_pipe_read_ready();

  if (num==0)
      return RC_NONE;

  return(ctl_blocking_read(valp));
}
示例#3
0
文件: xaw_c.c 项目: 1c0n/xbmc
static void ctl_pass_playing_list(int init_number_of_files,
                  char *init_list_of_files[]) {
  int current_no,command=RC_NONE,i,j;
  int32 val;
  char *p;

  /* Wait prepare 'interface' */
  a_pipe_read(local_buf,sizeof(local_buf));
  if (strcmp("READY",local_buf)) return;
  xaw_ready=1;

  sprintf(local_buf,"%d",
  (opt_modulation_wheel<<MODUL_N)
     | (opt_portamento<<PORTA_N)
     | (opt_nrpn_vibrato<<NRPNV_N)
     | (opt_reverb_control<<REVERB_N)
     | (opt_channel_pressure<<CHPRESSURE_N)
     | (opt_overlap_voice_allow<<OVERLAPV_N)
     | (opt_trace_text_meta_event<<TXTMETA_N));
  a_pipe_write(local_buf);
  sprintf(local_buf,"%d",opt_chorus_control);
  a_pipe_write(local_buf);

  /* Make title string */
  titles=(char **)safe_malloc(init_number_of_files*sizeof(char *));
  list_of_files=(char **)safe_malloc(init_number_of_files*sizeof(char *));
  for (i=0,j=0;i<init_number_of_files;i++) {
    if(check_midi_file(init_list_of_files[i]) >= 0) {
      p=strrchr(init_list_of_files[i],'/');
      if (p==NULL) {
        p=safe_strdup(init_list_of_files[i]);
      } else p++;
      list_of_files[j]= safe_strdup(init_list_of_files[i]);
      titles[j]=(char *)safe_malloc(sizeof(char)*(strlen(p)+ 9));
      sprintf(titles[j],"%d. %s",j+1,p);
      j++; number_of_files = j;
    }
  }
  titles=(char **)safe_realloc(titles,init_number_of_files*sizeof(char *));
  list_of_files=(char **)safe_realloc(list_of_files,init_number_of_files*sizeof(char *));

  /* Send title string */
  sprintf(local_buf,"%d",number_of_files);
  a_pipe_write(local_buf);
  for (i=0;i<number_of_files;i++)
    a_pipe_write(titles[i]);

  /* Make the table of play sequence */
  file_table=(int *)safe_malloc(number_of_files*sizeof(int));
  for (i=0;i<number_of_files;i++) file_table[i]=i;

  /* Draw the title of the first file */
  current_no=0;
  if(number_of_files!=0){
    snprintf(local_buf,sizeof(local_buf),"E %s",titles[file_table[0]]);
    a_pipe_write(local_buf);
    command=ctl_blocking_read(&val);
  }

  /* Main loop */
  for (;;) {
    /* Play file */
    if (command==RC_LOAD_FILE&&number_of_files!=0) {
      char *title;
      snprintf(local_buf,sizeof(local_buf),"E %s",titles[file_table[current_no]]);
      a_pipe_write(local_buf);
      if((title = get_midi_title(list_of_files[file_table[current_no]])) == NULL)
      title = list_of_files[file_table[current_no]];
      snprintf(local_buf,sizeof(local_buf),"e %s", title);
      a_pipe_write(local_buf);
      command=play_midi_file(list_of_files[file_table[current_no]]);
    } else {
      if (command==RC_CHANGE_VOLUME) amplitude+=val;
      if (command==RC_JUMP) ;
      if (command==RC_TOGGLE_SNDSPEC) ;
      /* Quit timidity*/
      if (exitflag & EXITFLG_QUIT) return;
      /* Stop playing */
      if (command==RC_QUIT) {
        sprintf(local_buf,"T 00:00");
        a_pipe_write(local_buf);
        /* Shuffle the table */
        if (randomflag) {
          if(number_of_files == 0) {
            randomflag=0;
            continue;
          }
          current_no=0;
          if (randomflag==1) {
            shuffle(number_of_files,file_table);
            randomflag=0;
            command=RC_LOAD_FILE;
            continue;
          }
          randomflag=0;
          for (i=0;i<number_of_files;i++) file_table[i]=i;
          snprintf(local_buf,sizeof(local_buf),"E %s",titles[file_table[current_no]]);
          a_pipe_write(local_buf);
        }
        /* Play the selected file */
        if (selectflag) {
          for (i=0;i<number_of_files;i++)
            if (file_table[i]==selectflag-1) break;
          if (i!=number_of_files) current_no=i;
          selectflag=0;
          command=RC_LOAD_FILE;
          continue;
        }
        /* After the all file played */
      } else if (command==RC_TUNE_END || command==RC_ERROR) {
        if (current_no+1<number_of_files) {
          current_no++;
          command=RC_LOAD_FILE;
          continue;
        } else if (exitflag & EXITFLG_AUTOQUIT) {
          return;
          /* Repeat */
        } else if (repeatflag) {
          current_no=0;
          command=RC_LOAD_FILE;
          continue;
          /* Off the play button */
        } else {
          a_pipe_write("O");
        }
        /* Play the next */
      } else if (command==RC_NEXT) {
        if (current_no+1<number_of_files) current_no++;
        command=RC_LOAD_FILE;
        continue;
        /* Play the previous */
      } else if (command==RC_REALLY_PREVIOUS) {
        if (current_no>0) current_no--;
        command=RC_LOAD_FILE;
        continue;
      }
      command=ctl_blocking_read(&val);
    }
  }
}
示例#4
0
文件: xaw_c.c 项目: 1c0n/xbmc
static int ctl_read(int32 *valp) {
  if (a_pipe_ready()<=0) return RC_NONE;
  return ctl_blocking_read(valp);
}
示例#5
0
static int ctl_pass_playing_list(int number_of_files, char *list_of_files[])
{
    int i=0;
    char file_to_play[1000];
    int command;
    int32 val;
    int retval;

    motif_ready = 1;

    m_pipe_int_write(MASTERVOL_MESSAGE);
    m_pipe_int_write(amplification);

    /* Pass the list to the interface */
    m_pipe_int_write(FILE_LIST_MESSAGE);
    m_pipe_int_write(number_of_files);
    for (i=0;i<number_of_files;i++)
	m_pipe_string_write(list_of_files[i]);

    /* Ask the interface for a filename to play -> begin to play automatically */
    m_pipe_int_write(NEXT_FILE_MESSAGE);

    command = ctl_blocking_read(&val);

    /* Main Loop */
    for (;;)
	{
	    if (command==RC_LOAD_FILE)
		{
		    /* Read a LoadFile command */
		    m_pipe_string_read(file_to_play);
		    command=play_midi_file(file_to_play);
		}
	    else
		{
		    if (command==RC_QUIT)
			return 0;

		    switch(command)
			{
			case RC_ERROR:
			    m_pipe_int_write(ERROR_MESSAGE);
			    retval=1;
			    break;
			case RC_NONE:
			    break;
			case RC_NEXT:
			    m_pipe_int_write(NEXT_FILE_MESSAGE);
			    break;
			case RC_REALLY_PREVIOUS:
			    m_pipe_int_write(PREV_FILE_MESSAGE);
			    break;
			case RC_TUNE_END:
			    m_pipe_int_write(TUNE_END_MESSAGE);
			    break;
			case RC_CHANGE_VOLUME:
				amplification += val;
				break;
			default:
			    fprintf(stderr,
				    "PANIC !!! OTHER COMMAND ERROR ?!?! %i"
				    NLS, command);
			}

		    command = ctl_blocking_read(&val);
		}
	}
    return retval;
}
示例#6
0
文件: tk_c.c 项目: avm/timidity
static int ctl_pass_playing_list(int number_of_files, char *list_of_files[])
{
	int i=0;
	char local[1000];
	int command;
	int32 val;

	/* Pass the list to the interface */
	k_pipe_printf("LIST %d", number_of_files);
	for (i=0;i<number_of_files;i++)
		k_pipe_puts(list_of_files[i]);

	/* Ask the interface for a filename to play -> begin to play automatically */
	/*k_pipe_puts("NEXT");*/
	command = ctl_blocking_read(&val);

	/* Main Loop */
	for (;;)
	{
		if (command==RC_LOAD_FILE)
		{
			/* Read a LoadFile command */
			k_pipe_gets(local, sizeof(local)-1);
			command=play_midi_file(local);
		}
		else
		{
			if (command==RC_QUIT) {
				/* if really QUIT */
				k_pipe_gets(local, sizeof(local)-1);
				if (*local == 'Z')
					return 0;
				/* only stop playing..*/
			}
			if (command==RC_CHANGE_VOLUME) /* init volume */
				amplification += val;

			switch(command)
			{
			case RC_ERROR:
				k_pipe_puts("ERRR");
				break;
			case RC_NEXT:
				k_pipe_puts("NEXT");
				break;
			case RC_REALLY_PREVIOUS:
				k_pipe_puts("PREV");
				break;
			case RC_TUNE_END:
				k_pipe_puts("TEND");
				break;
			case RC_RESTART:
				k_pipe_puts("RSTA");
				break;
			}

			command = ctl_blocking_read(&val);
		}
	}
	return 0;
}
示例#7
0
static int ctl_pass_playing_list(int number_of_files, char *list_of_files[]) {

  int current_no,command,i;
  int32 val;
  int *file_table;
  char **titles;
  char *p;

  /* Wait prepare 'interface' */
  xskin_pipe_read(local_buf,sizeof(local_buf));
  if (strcmp("READY",local_buf))
    return 0;
  xskin_ready = 1;

  /* receive shared memory buffer */
  xskin_pipe_read(local_buf, sizeof(local_buf));
  if (strcmp("ERROR",local_buf)) {
    int shmid;
    isspeanaenabled=1;
    shmid = atoi(local_buf);
    speana_buf = (unsigned char *)shmat(shmid,0,0);
  } else {
    isspeanaenabled=0;
  }

  /* Make title string */
  titles=(char **)safe_malloc(number_of_files*sizeof(char *));
  for (i=0;i<number_of_files;i++) {
    p=strrchr(list_of_files[i],'/');
    if (p==NULL) {
      p=list_of_files[i];
    } else p++;
    sprintf(local_buf,"%d. %s",i+1,p);
    titles[i]=(char *)safe_malloc(strlen(local_buf)+1);
    strcpy(titles[i],local_buf);
  }

  /* Send title string */
  sprintf(local_buf,"%d",number_of_files);
  xskin_pipe_write(local_buf);
  for (i=0;i<number_of_files;i++) xskin_pipe_write(titles[i]);

  /* Make the table of play sequence */
  file_table=(int *)safe_malloc(number_of_files*sizeof(int));
  for (i=0;i<number_of_files;i++) file_table[i]=i;

  /* Draw the title of the first file */
  current_no=0;
  sprintf(local_buf,"F %s",titles[file_table[0]]);
  xskin_pipe_write(local_buf);

  command=ctl_blocking_read(&val);

  /* Main loop */
  for (;;) {
    /* Play file */
    if (command==RC_LOAD_FILE) {
      sprintf(local_buf,"F %s",titles[file_table[current_no]]);
      xskin_pipe_write(local_buf);
      command=play_midi_file(list_of_files[file_table[current_no]]);
    } else {
      /* Quit timidity*/
      if (exitflag) return 0;
      /* Stop playing */
      if (command==RC_QUIT) {
	sprintf(local_buf,"T 00:00");
	xskin_pipe_write(local_buf);
	/* Shuffle the table */
	if (randomflag) {
	  current_no=0;
	  if (randomflag==1) {
	    shuffle(number_of_files,file_table);
	    randomflag=0;
	    command=RC_LOAD_FILE;
	    continue;
	  }
	  randomflag=0;
	  for (i=0;i<number_of_files;i++) file_table[i]=i;
	  sprintf(local_buf,"F %s",titles[file_table[current_no]]);
	  xskin_pipe_write(local_buf);
	}
	/* Play the selected file */
	if (selectflag) {
	  for (i=0;i<number_of_files;i++)
	    if (file_table[i]==selectflag-1) break;
	  if (i!=number_of_files) current_no=i;
	  selectflag=0;
	  command=RC_LOAD_FILE;
	  continue;
	}
      /* After the all file played */
      } else if (command==RC_TUNE_END || command==RC_ERROR) {
	if (current_no+1<number_of_files) {
	  current_no++;
	  command=RC_LOAD_FILE;
	  continue;
	/* Repeat */
	} else if (repeatflag) {
	  current_no=0;
	  command=RC_LOAD_FILE;
	  continue;
	/* Off the play button */
	} else {
	  xskin_pipe_write("O");
	}
      /* Play the next */
      } else if (command==RC_NEXT) {
	if (current_no+1<number_of_files) current_no++;
	command=RC_LOAD_FILE;
	continue;
      /* Play the previous */
      } else if (command==RC_REALLY_PREVIOUS) {
	if (current_no>0) current_no--;
	command=RC_LOAD_FILE;
	continue;
      }

      command=ctl_blocking_read(&val);
    }
  }
  return 0;
}