Beispiel #1
0
Datei: main.c Projekt: zeryx/CMG
	void main(void) {
	ConfigEverything();
	TIMERCONFIG();
	ConfigureMotorsStep_16();

	unsigned short datx = 0, daty = 0, countx;
	Queue ratio_x, ratio_y, dirqx, dirqy, xcnt;
	unsigned char dirx = 0, diry = 0;

	//==========================================
	//configure data handler



	xcnt =CreateQueue(STACKSIZE);
	ratio_x = CreateQueue(STACKSIZE); 	// change STACKSIZE in define, dictates how big the queue can be.
	ratio_y = CreateQueue(STACKSIZE); 	//
	dirqx = CreateQueue(STACKSIZE); 	//
	dirqy = CreateQueue(STACKSIZE); 	//



	while(1)//main loop start
	{
			ResetMotors();
			int x = 0;
			HandShake();
			LaserWait();
			while (!IsFull(ratio_y)) // while queue is not full, fill er up
			{
				variant_t combine;
				x++;


				if (x & 1) {
					read_var(&combine);
					countx = (combine.val.n);
					Enqueue(countx, xcnt); //put length of step cycle in xcnt
					read_var(&combine);
					dirx = combine.val.n >> 15;
					datx = (combine.val.n & ~0x8000);
					Enqueue(datx, ratio_x);
					Enqueue(dirx, dirqx);
				} else {
					read_var(&combine);
					diry = combine.val.n >> 15;
					daty = (combine.val.n & ~0x8000);
					Enqueue(daty, ratio_y); // put buffer byte in queue y
					Enqueue(diry, dirqy);
				}

			}
Beispiel #2
0
unsigned char init_check()
{
    _e_read = read_var(0, 0);
    if (_e_read != 0x19)
        return 1;
    _e_read = read_var(0, 1);
    if (_e_read != 0x08)
        return 1;
    _e_read = read_var(0, 2);
    if (_e_read != 0x1E)
        return 1;
    return 0;
}
static void trigger_tests(void)
{
	int len, local, global, i;
	char val;
	int ret;

	ret = ptrace(PTRACE_TRACEME, 0, NULL, 0);
	if (ret) {
		perror("Can't be traced?\n");
		return;
	}

	
	kill(getpid(), SIGUSR1);

	
	for (local = 0; local < 2; local++) {
		for (global = 0; global < 2; global++) {
			if (!local && !global)
				continue;

			for (i = 0; i < 4; i++) {
				dummy_funcs[i]();
				check_trapped();
			}
		}
	}

	
	for (len = 1; len <= sizeof(long); len <<= 1) {
		for (local = 0; local < 2; local++) {
			for (global = 0; global < 2; global++) {
				if (!local && !global)
					continue;
				write_var(len);
			}
		}
	}

	
	for (len = 1; len <= sizeof(long); len <<= 1) {
		for (local = 0; local < 2; local++) {
			for (global = 0; global < 2; global++) {
				if (!local && !global)
					continue;
				read_var(len);
			}
		}
	}

	
	asm(".byte 0xf1\n");
	check_trapped();

	
	asm("int $3\n");
	check_trapped();

	kill(getpid(), SIGUSR1);
}
Beispiel #4
0
Datei: var.c Projekt: samv/git
int main(int argc, char **argv)
{
	const char *val;
	int nongit;
	if (argc != 2) {
		usage(var_usage);
	}

	git_extract_argv0_path(argv[0]);

	setup_git_directory_gently(&nongit);
	val = NULL;

	if (strcmp(argv[1], "-l") == 0) {
		git_config(show_config, NULL);
		list_vars();
		return 0;
	}
	git_config(git_default_config, NULL);
	val = read_var(argv[1]);
	if (!val)
		usage(var_usage);

	printf("%s\n", val);

	return 0;
}
Beispiel #5
0
void PropertyEnum::init()
{
	read_var();

	if (StringUtils::is_number(value))
		combobox->setCurrentIndex(StringUtils::str_to_numeric<int>(value));
}
Beispiel #6
0
void LoadCommandMap( const char* path ){
	StringOutputStream strINI( 256 );
	strINI << path << "shortcuts.ini";

	FILE* f = fopen( strINI.c_str(), "r" );
	if ( f != 0 ) {
		fclose( f );
		globalOutputStream() << "loading custom shortcuts list from " << makeQuoted( strINI.c_str() ) << "\n";

		Version version = version_parse( COMMANDS_VERSION );
		Version dataVersion = { 0, 0 };

		{
			char value[1024];
			if ( read_var( strINI.c_str(), "Version", "number", value ) ) {
				dataVersion = version_parse( value );
			}
		}

		if ( version_compatible( version, dataVersion ) ) {
			globalOutputStream() << "commands import: data version " << dataVersion << " is compatible with code version " << version << "\n";
			ReadCommandMap visitor( strINI.c_str() );
			GlobalShortcuts_foreach( visitor );
			globalOutputStream() << "parsed " << Unsigned( visitor.count() ) << " custom shortcuts\n";
		}
		else
		{
			globalOutputStream() << "commands import: data version " << dataVersion << " is not compatible with code version " << version << "\n";
		}
	}
	else
	{
		globalOutputStream() << "failed to load custom shortcuts from " << makeQuoted( strINI.c_str() ) << "\n";
	}
}
Beispiel #7
0
/*
 * Read in one track from the file, and return an element tree
 * describing it.
 * 
 *  Arguments:
 *    msp       - Midi state
 */
static struct trackElement *
read_track(struct midistate *msp)
{
	int  status, laststatus;
	int  head;
	int  length;
	int  delta_time;
	struct trackElement *track;
	int  i;

	laststatus = 0;
	head = read_int(msp, 4);
	if (head != MIDI_TRACK_MAGIC)
		except(formatError,
			"Bad track header (%x), probably not a midi file",
			head);

	length = read_int(msp, 4);
	msp->chunk_size = length;
	msp->chunk_count = 0;	/* nothing read yet */

	track = md_track_new();

	msp->current_time = 0;
	while (msp->chunk_count < msp->chunk_size) {

		delta_time = read_var(msp);
		msp->current_time += delta_time;

		status = read_int(msp, 1);
		if ((status & 0x80) == 0) {
			
			/*
			 * This is not a status byte and so running status is being
			 * used.  Re-use the previous status and push back this byte.
			 */
			put_back(msp, status);
			status = laststatus;
		} else {
			laststatus = status;
		}

		handle_status(msp, track, status);
	}

  restart:
	for (i = 0; i < msp->notes->len; i++) {
		struct noteElement *ns;
		ns = g_ptr_array_index(msp->notes, i);
		msp->device = MD_ELEMENT(ns)->device_channel;
printf("Left over note, finishing\n");
		finish_note(msp, ns->note, 0);
		goto restart;
	}

	msp->track_count++;

	return track;
}
Beispiel #8
0
/*
 * Dispatches the data based on the state.
 */
static int dispatch(JSONRD_T *jsonrd, const char *chunk, size_t size) {
  int consumed;
  if (jsonrd->state <= PS_FIND_START) {
    switch (jsonrd->state) {
      case PS_FIND_LANDMARK:
        consumed = find_landmark(jsonrd, chunk, size);
        break;
      case PS_READ_VAR:
        consumed = read_var(jsonrd, chunk, size);
        break;
      case PS_FIND_START:
        consumed = find_start(jsonrd, chunk, size);
        break;
      case PS_ERROR:
        consumed = size;
        break;
      default:
        consumed = 0;
        die("Bad state");
    }
  } else {
    consumed = next_token(jsonrd, chunk, size);
    if (jsonrd->token.state == TS_FOUND_TOKEN) {
      switch (jsonrd->state) {
        case PS_PROPERTY_OR_ENDOBJ:
          expect_property_or_endobj(jsonrd);
          break;
        case PS_COLON:
          expect_colon(jsonrd);
          break;
        case PS_PROPERTY_VALUE:
          expect_property_value(jsonrd);
          break;
        case PS_COMMA_OR_ENDOBJ:
          expect_comma_or_endobj(jsonrd);
          break;
        case PS_PROPERTY:
          expect_property(jsonrd);
          break;
        case PS_VALUE_OR_ENDLST:
          expect_value_or_endlst(jsonrd);
          break;
        case PS_COMMA_OR_ENDLST:
          expect_comma_or_endlst(jsonrd);
          break;
        case PS_LIST_VALUE:
          expect_list_value(jsonrd);
          break;
        default:
          die("Bad state");
      }
    }
  }
  assert(consumed >= 0);
  assert(consumed <= size);
  return consumed;
}
Beispiel #9
0
float WINAPI profile_load_float (const char *filename, const char *section, const char *key, float default_value)
{
  char value[1024];

  if (read_var (filename, section, key, value))
    return atof (value);
  else
    return default_value;
}
Beispiel #10
0
int profile_load_int (const char *filename, const char *section, const char *key, int default_value)
{
    char value[1024];

    if (read_var (filename, section, key, value))
        return atoi (value);
    else
        return default_value;
}
Beispiel #11
0
float profile_load_float (const char *filename, const char *section, const char *key, float default_value)
{
    char value[1024];

    if (read_var (filename, section, key, value))
        return static_cast<float>(atof(value));
    else
        return default_value;
}
Beispiel #12
0
void init_sh(char **profile)
{
  char *path = read_var(profile, "HOME");
  if(chdir(path)==0)
  {
    setenv("HOME", path, 1);
  }
  else
    perror("init error");
}
Beispiel #13
0
void fetch_data(Arg &op)
{
	switch (op.addr)
	{
		case ARG_REG:		op = ACC; break;
		case ARG_STACK:		op = pop(); break;
		case ARG_MEMORY:	read_var(op); break;
		case ARG_IMMEDIATE:	break;
		default: EXCEPTION("Invalid addressing mode: 0x%02x", op.addr);
	}
}
Beispiel #14
0
char* profile_load_string (const char *filename, const char *section, const char *key, const char *default_value)
{
    static Str ret;
    char value[1024];

    if (read_var (filename, section, key, value))
        ret = value;
    else
        ret = default_value;

    return (char*)ret.GetBuffer();
}
Beispiel #15
0
 parse_result read_lvl(string input, int from, int lvl) {
     from = skipSpaces(input,from);
     if (from >= (int)input.length()) {
         throw "End of input reached before the parsing finished";
     }
     if (lvl <= 0) { // parens or variable
         if (input[from] == '(') {
             parse_result pr = read_lvl(input,from+1,START_LVL);
             pr.idx = skipSpaces(input, pr.idx);
             if (pr.idx >= (int)input.length()) {
                 throw "End of input reached before the parsing finished";
             } else if (input[pr.idx] != ')') {
                 throw "'(' at character "+pr.idx;
             }
             pr.idx = pr.idx+1;
             return pr;
         } else {
             return read_var(input, from);
         }
     } else {
         operateur op = operateur_for_level(lvl);
         string s_op = operateur2string(op);
         if (is_binary(op)) {
             parse_result pr1 = read_lvl(input,from,lvl-1);
             pr1.idx = skipSpaces(input,pr1.idx);
             if ( input.compare(pr1.idx, s_op.length(), s_op) == 0 ) {
                 parse_result pr2 = read_lvl(input,pr1.idx+(int)s_op.length(), lvl);
                 parse_result res;
                 res.f = new formule();
                 res.f -> op = op;
                 res.f -> arg1 = pr1.f;
                 res.f -> arg2 = pr2.f;
                 res.idx = pr2.idx;
                 return res;
             } else {
                 return pr1;
             }
         } else {
             if ( input.compare(from, s_op.length(), s_op) == 0 )  {
                 parse_result pr = read_lvl(input,from + (int)s_op.length(),lvl);
                 parse_result res;
                 res.idx = pr.idx;
                 res.f = new formule();
                 res.f->op = op;
                 res.f->arg = pr.f;
                 return res;
             } else {
                 return read_lvl(input,from,lvl-1);
             }
         }
     }
 }
Beispiel #16
0
int INIGetInt( const char *key, int def ){
#if defined( __linux__ ) || defined( __APPLE__ )
	char value[1024];

	if ( read_var( INIfn, CONFIG_SECTION, key, value ) ) {
		return atoi( value );
	}
	else{
		return def;
	}
#else
	return GetPrivateProfileInt( CONFIG_SECTION, key, def, INIfn );
#endif
}
Beispiel #17
0
static bool load_cached_font_list(struct serializer *s)
{
	bool success = true;
	int count;

	success = read_var(s, count);
	if (!success) return false;

	da_init(font_list);
	da_resize(font_list, count);

#define do_read(var) \
	success = read_var(s, var); \
	if (!success) break

	for (int i = 0; i < count; i++) {
		struct font_path_info *info = &font_list.array[i];

		success = read_str(s, &info->face_and_style);
		if (!success) break;

		do_read(info->full_len);
		do_read(info->face_len);
		do_read(info->is_bitmap);
		do_read(info->num_sizes);

		info->sizes = bmalloc(sizeof(int) * info->num_sizes);
		success = read_data(s, info->sizes,
				sizeof(int) * info->num_sizes);
		if (!success) break;

		do_read(info->bold);

		success = read_str(s, &info->path);
		if (!success) break;

		do_read(info->italic);
		do_read(info->index);
	}

#undef do_read

	if (!success) {
		free_os_font_list();
		return false;
	}

	return true;
}
Beispiel #18
0
t_pattern read_pattern(unsigned char num)
{
    t_pattern patt;

    #asm("cli")
    lcd_clear();
    lcd_puts("Memory read");
    addr = 3 + num * (MAX_ITEMS + 1);
    block = addr / 256;
    addr = addr % 256;
    
    patt.length = read_var(block, addr);
    
    addr++;
    check_ab();
    
    lcd_gotoxy(0, 1);
    lcd_puts(t_preset);
    lcd_putchar(' ');
    LCDWriteInt(num, 0);
    lcd_putchar(' ');
    lcd_puts(t_item);
    lcd_putchar(' ');

    for(j = 0; j < MAX_ITEMS; j++)                
    {                          
        lcd_gotoxy(14, 1);
        LCDWriteInt(j, 0);
        lcd_putchar(' ');
        patt.out[j] = read_var(block, addr);
        addr++;
        check_ab();
    }          
    #asm("sei")
    return patt;
}
Beispiel #19
0
int main(int argc, char **argv)
{
	struct fb_var_screeninfo var;
	char res[4096];

	if (read_var("/dev/fb0", &var))
		return 1;

	bzero(res, sizeof(res));
	snprintf(res+4, sizeof(res)-1,
		"NeTVBrowser|~|SetResolution|~|%d|~|%d|~|%d",
		var.xres, var.yres, var.bits_per_pixel);
	((long *)res)[0] = htonl(strlen(res+4)+1);
	send_message("NeTVBr", res, strlen(res+4)+5);

	return 0;
}
Beispiel #20
0
static bool read_str(struct serializer *s, char **p_str)
{
	uint32_t size;
	char *str;

	if (!read_var(s, size))
		return false;

	str = bmalloc(size + 1);
	if (size && !read_data(s, str, size)) {
		bfree(str);
		return false;
	}

	str[size] = 0;
	*p_str = str;
	return true;
}
Beispiel #21
0
	/* This function returns the next character to be included in
	 * parameters, it interprets special characters, for each sequence of
	 * non-escaped white-space characters returns exactly one -2 and
	 * returns -1 when processing of parameters for current command should
	 * stop. */
	int next_char()
	{
		char c;
		if (*var_value) {
			c = *(var_value++);
			if (quot) return c;
		} else {
			if (++(*pos) >= length) return -1;

			c = data[*pos];
			last_space = last_space && isspace(c);

			if (c == '\'' || c == '"') {
				if (quot == 0) quot = c;
				else if (quot == c) quot = 0;
				else return c;
				return next_char();
			}

			if (!quot || quot == '"') {
				if (c == '\\' && (*pos) < length-1)
					return data[++(*pos)];
				if (c == '$') {
					read_var();
					return next_char();
				}
			}

			if (quot) return c;

			if (c == '\n' || c == '{' || c == '}' || c == '#')
				return -1;
		}

		if (isspace(c)) {
			if (last_space) return next_char();
			else {
				last_space = true;
				return -2;
			}
		}

		return c;
	}
Beispiel #22
0
int cmd_var(int argc, const char **argv, const char *prefix)
{
	const char *val = NULL;
	if (argc != 2)
		usage(var_usage);

	if (strcmp(argv[1], "-l") == 0) {
		git_config(show_config, NULL);
		list_vars();
		return 0;
	}
	git_config(git_default_config, NULL);
	val = read_var(argv[1]);
	if (!val)
		usage(var_usage);

	printf("%s\n", val);

	return 0;
}
Beispiel #23
0
void visit( const char* name, Accelerator& accelerator ){
	char value[1024];
	if ( read_var( m_filename, "Commands", name, value ) ) {
		if ( string_empty( value ) ) {
			accelerator.key = 0;
			accelerator.modifiers = (GdkModifierType)0;
			return;
		}

		gtk_accelerator_parse( value, &accelerator.key, &accelerator.modifiers );
		accelerator = accelerator; // fix modifiers

		if ( accelerator.key != 0 ) {
			++m_count;
		}
		else
		{
			globalOutputStream() << "WARNING: failed to parse user command " << makeQuoted( name ) << ": unknown key " << makeQuoted( value ) << "\n";
		}
	}
}
Beispiel #24
0
  void visit(const char* name, Accelerator& accelerator)
  {
    char value[1024];
    if (read_var(m_filename, "Commands", name, value ))
    {
      if(string_empty(value))
      {
        accelerator.key = 0;
        accelerator.modifiers = (GdkModifierType)0;
        return;
      }
      int modifiers = 0;
      const char* last = value + string_length(value);
      const char* keyEnd = stringrange_find(value, last, '+');
      for(const char* modifier = keyEnd; modifier != last;)
      {
        const char* next = stringrange_find(modifier + 1, last, '+');
        if(next - modifier == 4
          && string_equal_nocase_n(modifier, "+alt", 4))
        {
          modifiers |= GDK_MOD1_MASK;
        }
        else if(next - modifier == 5
          && string_equal_nocase_n(modifier, "+ctrl", 5) != 0)
        {
          modifiers |= GDK_CONTROL_MASK;
        }
        else if(next - modifier == 6
          && string_equal_nocase_n(modifier, "+shift", 6) != 0)
        {
          modifiers |= GDK_SHIFT_MASK;
        }
        else
        {
          globalOutputStream() << "WARNING: failed to parse user command " << makeQuoted(value) << ": unknown modifier " << makeQuoted(StringRange(modifier, next)) << "\n";
        }
        modifier = next;
      }
      accelerator.modifiers = (GdkModifierType)modifiers;


      // strBuff has been cleaned of it's modifiers .. switch between a regular key and a virtual one
      // based on length
      if(keyEnd - value == 1) // most often case.. deal with first
      {
        accelerator.key = std::toupper(value[0]);
        ++m_count;
      }
      else // special key
      {
        CopiedString keyName(StringRange(value, keyEnd));
        accelerator.key = global_keys_find(keyName.c_str());
        if(accelerator.key != 0)
        {
          ++m_count;
        }
        else
        {
          globalOutputStream() << "WARNING: failed to parse user command " << makeQuoted(value) << ": unknown key " << makeQuoted(keyName.c_str()) << "\n";
        }
      }
    }
  }
Beispiel #25
0
void print_prompt_sign(char ** profile)
{
  char * sign = read_var(profile, "SIGN");
  printf("[%s] %s ", getcwd(pathname, sizeof(pathname)/sizeof(char)), sign);
  fflush(stdout); // flush in case the output is cached by os
}
Beispiel #26
0
PropertyEnum::PropertyEnum(GParamSpec* param_spec,
		const Glib::RefPtr<Gst::Element>& element)
: Property(param_spec, element)
{
	read_var();
}
Beispiel #27
0
bool midifile::parse (perform * a_perf)
{
    printf("FIXME midifile::parse()\n");
#if 0

    /* open binary file */
    ifstream file(m_name.c_str(), ios::in | ios::binary | ios::ate);

    if (!file.is_open ()) {
        fprintf(stderr, "Error opening MIDI file\n");
        return false;
    }

    int file_size = file.tellg ();

    /* run to start */
    file.seekg (0, ios::beg);

    /* alloc data */
    m_d = (unsigned char *) new char[file_size];
    if (m_d == NULL) {
        fprintf(stderr, "Memory allocation failed\n");
        return false;
    }
    file.read ((char *) m_d, file_size);
    file.close ();

    /* set position to 0 */
    m_pos = 0;

    /* chunk info */
    unsigned long ID;
    unsigned long TrackLength;

    /* time */
    unsigned long Delta;
    unsigned long RunningTime;
    unsigned long CurrentTime;

    unsigned short Format;			/* 0,1,2 */
    unsigned short NumTracks;
    unsigned short ppqn;
    unsigned short perf;
    int c;

    /* track name from file */
    char TrackName[256];

    /* used in small loops */
    int i;

    /* sequence pointer */
    sequence * seq;
    event e;

    /* read in header */
    ID = read_long ();
    TrackLength = read_long ();
    Format = read_short ();
    NumTracks = read_short ();
    ppqn = read_short ();

    //printf( "[%8lX] len[%ld] fmt[%d] num[%d] ppqn[%d]\n",
    //      ID, TrackLength, Format, NumTracks, ppqn );

    /* magic number 'MThd' */
    if (ID != 0x4D546864) {
        fprintf(stderr, "Invalid MIDI header detected: %8lX\n", ID);
        delete[]m_d;
        return false;
    }

    /* we are only supporting format 1 for now */
    if (Format != 1) {
        fprintf(stderr, "Unsupported MIDI format detected: %d\n", Format);
        delete[]m_d;
        return false;
    }

    /* We should be good to load now   */
    /* for each Track in the midi file */
    for (int curTrack = 0; curTrack < NumTracks; curTrack++)
    {
        /* done for each track */
        bool done = false;
        perf = 0;

        /* events */
        unsigned char status = 0, type, data[2], laststatus;
        long len;
        unsigned long proprietary = 0;

        /* Get ID + Length */
        ID = read_long ();
        TrackLength = read_long ();
        //printf( "[%8lX] len[%8lX]\n", ID,  TrackLength );


        /* magic number 'MTrk' */
        if (ID == 0x4D54726B)
        {
            /* we know we have a good track, so we can create
               a new sequence to dump it to */
            seq = new sequence ();
            if (seq == NULL) {
                fprintf(stderr, "Memory allocation failed\n");
                delete[]m_d;
                return false;
            }
            seq->set_master_midi_bus (&a_perf->m_master_bus);

            /* reset time */
            RunningTime = 0;

            /* this gets each event in the Trk */
            while (!done)
            {
                /* get time delta */
                Delta = read_var ();

                /* get status */
                laststatus = status;
                status = m_d[m_pos];

                /* is it a status bit ? */
                if ((status & 0x80) == 0x00)
                {
                    /* no, its a running status */
                    status = laststatus;
                }
                else
                {
                    /* its a status, increment */
                    m_pos++;
                }

                /* set the members in event */
                e.set_status (status);

                RunningTime += Delta;
                /* current time is ppqn according to the file,
                   we have to adjust it to our own ppqn.
                   PPQN / ppqn gives us the ratio */
                CurrentTime = (RunningTime * c_ppqn) / ppqn;

                //printf( "D[%6ld] [%6ld] %02X\n", Delta, CurrentTime, status);
                e.set_timestamp (CurrentTime);

                /* switch on the channelless status */
                switch (status & 0xF0)
                {
                    /* case for those with 2 data bytes */
                    case EVENT_NOTE_OFF:
                    case EVENT_NOTE_ON:
                    case EVENT_AFTERTOUCH:
                    case EVENT_CONTROL_CHANGE:
                    case EVENT_PITCH_WHEEL:

                        data[0] = m_d[m_pos++];
                        data[1] = m_d[m_pos++];

                        // some files have vel=0 as note off
                        if ((status & 0xF0) == EVENT_NOTE_ON && data[1] == 0)
                        {
                            e.set_status (EVENT_NOTE_OFF);
                        }

                        //printf( "%02X %02X\n", data[0], data[1] );

                        /* set data and add */
                        e.set_data (data[0], data[1]);
                        seq->add_event (&e);

                        /* set midi channel */
                        seq->set_midi_channel (status & 0x0F);
                        break;

                        /* one data item */
                    case EVENT_PROGRAM_CHANGE:
                    case EVENT_CHANNEL_PRESSURE:

                        data[0] = m_d[m_pos++];
                        //printf( "%02X\n", data[0] );

                        /* set data and add */
                        e.set_data (data[0]);
                        seq->add_event (&e);

                        /* set midi channel */
                        seq->set_midi_channel (status & 0x0F);
                        break;

                        /* meta midi events ---  this should be FF !!!!!  */
                    case 0xF0:

                        if (status == 0xFF)
                        {
                            /* get meta type */
                            type = m_d[m_pos++];
                            len = read_var ();

                            //printf( "%02X %08X ", type, (int) len );

                            switch (type)
                            {
                                /* proprietary */
                                case 0x7f:

                                    /* FF 7F len data  */
                                    if (len > 4)
                                    {
                                        proprietary = read_long ();
                                        len -= 4;
                                    }

                                    if (proprietary == c_midibus)
                                    {
                                        seq->set_midi_bus (m_d[m_pos++]);
                                        len--;
                                    }

                                    else if (proprietary == c_midich)
                                    {
                                        seq->set_midi_channel (m_d[m_pos++]);
                                        len--;
                                    }

                                    else if (proprietary == c_timesig)
                                    {
                                        seq->set_bpm (m_d[m_pos++]);
                                        seq->set_bw (m_d[m_pos++]);
                                        len -= 2;
                                    }

                                    else if (proprietary == c_triggers)
                                    {
                                        int num_triggers = len / 4;

                                        for (int i = 0; i < num_triggers; i += 2)
                                        {
                                            unsigned long on = read_long ();
                                            unsigned long length = (read_long () - on);
                                            len -= 8;
                                            seq->add_trigger(on, length, 0, false);
                                        }
                                    }

                                    else if (proprietary == c_triggers_new)
                                    {
                                        int num_triggers = len / 12;

                                        //printf( "num_triggers[%d]\n", num_triggers );
                                        for (int i = 0; i < num_triggers; i++)
                                        {
                                            unsigned long on = read_long ();
                                            unsigned long off = read_long ();
                                            unsigned long length = off - on + 1;
                                            unsigned long offset = read_long ();

                                            //printf( "< start[%d] end[%d] offset[%d]\n",
                                            //        on, off, offset );

                                            len -= 12;
                                            seq->add_trigger (on, length, offset, false);
                                        }
                                    }

                                    /* eat the rest */
                                    m_pos += len;
                                    break;

                                    /* Trk Done */
                                case 0x2f:

                                    // If delta is 0, then another event happened at the same time
                                    // as the track end.  the sequence class will discard the last
                                    // note.  This is a fix for that.   Native Seq42 file will always
                                    // have a Delta >= 1
                                    if ( Delta == 0 ){
                                        CurrentTime += 1;
                                    }

                                    seq->set_length (CurrentTime, false);
                                    seq->zero_markers ();
                                    done = true;
                                    break;

                                    /* Track name */
                                case 0x03:
                                    for (i = 0; i < len; i++)
                                    {
                                        TrackName[i] = m_d[m_pos++];
                                    }

                                    TrackName[i] = '\0';

                                    //printf("[%s]\n", TrackName );
                                    seq->set_name (TrackName);
                                    break;

                                    /* sequence number */
                                case 0x00:
                                    if (len == 0x00)
                                        perf = 0;
                                    else
                                        perf = read_short ();

                                    //printf ( "perf %d\n", perf );
                                    break;

                                default:
                                    for (i = 0; i < len; i++)
                                    {
                                        c = m_d[m_pos++];
                                        //printf( "%02X ", c  );
                                    }
                                    //printf("\n");
                                    break;
                            }
                        }
                        else if(status == 0xF0)
                        {
                            /* sysex */
                            len = read_var ();

                            /* skip it */
                            m_pos += len;

                            fprintf(stderr, "Warning, no support for SYSEX messages, discarding.\n");
                        }
                        else
                        {
                            fprintf(stderr, "Unexpected system event : 0x%.2X", status);
                            delete[]m_d;
                            return false;
                        }

                        break;

                    default:
                        fprintf(stderr, "Unsupported MIDI event: %hhu\n", status);
                        delete[]m_d;
                        return false;
                        break;
                }

            }			/* while ( !done loading Trk chunk */

            /* the sequence has been filled, add it  */
            a_perf->add_sequence (seq);
        }

        /* dont know what kind of chunk */
        else
        {
            /* its not a MTrk, we dont know how to deal with it,
               so we just eat it */
            fprintf(stderr, "Unsupported MIDI header detected: %8lX\n", ID);
            m_pos += TrackLength;
            done = true;
        }

    }				/* for(eachtrack) */

    //printf ( "file_size[%d] m_pos[%d]\n", file_size, m_pos );

    if ((file_size - m_pos) > (int) sizeof (unsigned long))
    {
        ID = read_long ();

        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_midiclocks)
        {
            TrackLength = read_long ();
            /* TrackLength is nyumber of buses */
            for (unsigned int x = 0; x < TrackLength; x++)
            {
                int bus_on = m_d[m_pos++];
                a_perf->get_master_midi_bus ()->set_clock (x, (clock_e) bus_on);
            }
        }
    }

    if ((file_size - m_pos) > (int) sizeof (unsigned int))
    {
        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_bpmtag)
        {
            long bpm = read_long ();
            a_perf->set_bpm (bpm);
        }
    }

    // *** ADD NEW TAGS AT END **************/

    delete[]m_d;
    return true;
    //printf ( "done\n");
#endif
}
Beispiel #28
0
int main(int argc, char ** argv)
{
	int opt;
	char *out = NULL; 
	char *in = NULL;
	char *inp = NULL;
	int amount = 0;
	int freq = 0;
	char *format;
	char *progname = argv[0];
	
	while ((opt = getopt(argc,argv,"r:k:m:n:f:o:")) != -1)
	{
		switch(opt)
		{
			case 'r': in = optarg; break;
			case 'k': out = optarg; break;
			case 'm': inp = optarg; break;
			case 'n': amount = atoi(optarg); break;
			case 'f': freq = atoi(optarg); break;
			case 'o': format = optarg; break;
			default : printf("Bad parameters\n"); exit( EXIT_FAILURE );
		}
	}
	if (optind < argc)
	{
		printf("Bad parameters\n");
		printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n");
		exit( EXIT_FAILURE );
	}

	if(in == NULL)
	{
		printf("No input file name\n");
		printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n");
		exit( EXIT_FAILURE );
	}

	if(inp == NULL)
	{
		printf("No image file name\n");
		printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n");
		exit( EXIT_FAILURE );
	}
	
	if (format == NULL)
	{
		printf("No format name\n");
		printf("Usage of app: ./game_life -r input_file_name -k output_file_name -m output_image_name -n amout_of_iterations -f frequency_of_drawing_images -o .image_format\n");
		exit( EXIT_FAILURE);
	}
	
	FILE *a = fopen(in,"r");
	life_t main = malloc(sizeof*main);
	life_t pom = malloc(sizeof*pom);
	read_var(a,main);
	pom->rows = main->rows;
	pom->cols = main->cols;
	alloc_matrix(main);
	alloc_matrix(pom);
	read_matrix(a,main);
	int i,j,k;
	char name[100];
	int n =freq;
	//FILE *b = fopen(out,"w");
	char text[100];	
	for (i =0; i <= amount ; i++)
	{
		strcpy(name,inp);
		strcpy(text,out);
		if ( i == freq)
		{
			char number[10];
			sprintf(number,"%d",i);
			strcat(name,number);
			strcat(name,format);
			strcat(text,number);
			freq += n;
		}
		game_life (main,pom,name);
		for (j = 0; j < main->rows; j++)
		{
			for ( k = 0 ; k< main->cols; k++)
				main->tab[j][k] = pom->tab[j][k];
		}
		save_matrix(text,main);
	}	
	return 0;
	
}
Beispiel #29
0
/*
 * Complete the reading of the status byte. The parsed midi
 * command will be added to the specified track .
 * 
 *  Arguments:
 *    msp       - Current midi file status
 *    track     - Current track
 *    status    - Status byte, ie. current command
 */
static void 
handle_status(struct midistate *msp, struct trackElement *track, int status)
{
	int  ch;
	int  type;
	int  device;
	int  length;
	short note, vel, control;
	int  val;
	unsigned char *data;
	struct element *el;

	ch = status & 0x0f;
	type = status & 0xf0;

	/*
	 * Do not set the device if the type is 0xf0 as these commands are
	 * not channel specific
	 */
	device = 0;
	if (type != 0xf0)
		device = (msp->port<<4) + ch;
	msp->device = device;

	el = NULL;

	switch (type) {	
	case MIDI_NOTE_OFF:
		note = read_int(msp, 1);
		vel = read_int(msp, 1);

		finish_note(msp, note, vel);
		break;

	case MIDI_NOTE_ON:
		note = read_int(msp, 1);
		vel = read_int(msp, 1);

		if (vel == 0) {
			/* This is really a note off */
			finish_note(msp, note, vel);
		} else {
			/* Save the start, so it can be matched with the note off */
			el = save_note(msp, note, vel);
		}
		break;

	case MIDI_KEY_AFTERTOUCH:
		note = read_int(msp, 1);
		vel = read_int(msp, 1);

		/* new aftertouchElement */
		el = MD_ELEMENT(md_keytouch_new(note, vel));
		break;

	case MIDI_CONTROLER:
		control = read_int(msp, 1);
		val = read_int(msp, 1);
		el = MD_ELEMENT(md_control_new(control, val));

		break;
	
	case MIDI_PATCH:
		val = read_int(msp, 1);
		el = MD_ELEMENT(md_program_new(val));
		break;

	case MIDI_CHANNEL_AFTERTOUCH:
		val = read_int(msp, 1);
		el = MD_ELEMENT(md_pressure_new(val));
		break;
	case MIDI_PITCH_WHEEL:
    {
		val = read_int(msp, 1);
        int val2 = read_int(msp, 1);
		val |=  val2 << 7;
		val -= 0x2000;	/* Center it around zero */
		el = MD_ELEMENT(md_pitch_new(val));
		break;
    }
	/* Now for all the non-channel specific ones */
	case 0xf0:
		/* Deal with the end of track event first */
		if (ch == 0x0f) {
			type = read_int(msp, 1);
			if (type == 0x2f) {
				/* End of track - skip to end of real track */
				track->final_time = msp->current_time;
				skip_chunk(msp);
				return;
			}
		}

		/* Get the length of the following data */
		length = read_var(msp);
		data = read_data(msp, length);
		if (ch == 0x0f) {
			el = (struct element *)handle_meta(msp, type, data);
		} else {
			el = (struct element *)md_sysex_new(status, data, length);
		}
		break;
	default:
		except(formatError, "Bad status type 0x%x", type);
		/*NOTREACHED*/
	}

	if (el != NULL) {
		el->element_time = msp->current_time;
		el->device_channel = device;

		md_add(MD_CONTAINER(track), el);
	}
}
Beispiel #30
0
bool midifile::parse (perform * a_perf, int a_screen_set)
{
    /* open binary file */
    ifstream file(m_name.c_str(), ios::in | ios::binary | ios::ate);

    if (!file.is_open ())
    {
        error_message_gtk("Error opening MIDI file");
        return false;
    }

    unsigned int file_size = file.tellg ();

    if(file_size < sizeof(unsigned long))
    {
        Glib::ustring message = "Error - Invalid file size: ";
        message += NumberToString(file_size);
        error_message_gtk(message);
        file.close ();
        return false;
    }

    /* run to start */
    file.seekg (0, ios::beg);

    /* alloc data */
    try
    {
        m_d.resize(file_size);
    }
    catch(std::bad_alloc& ex)
    {
        error_message_gtk("Memory allocation failed");
        return false;
    }
    file.read ((char *) &m_d[0], file_size);
    file.close ();

    /* set position to 0 */
    m_pos = 0;

    /* chunk info */
    unsigned long ID;
    unsigned long TrackLength;

    /* time */
    unsigned long Delta;
    unsigned long RunningTime;
    unsigned long CurrentTime;

    unsigned short Format;			/* 0,1,2 */
    unsigned short NumTracks;
    unsigned short ppqn;
    unsigned short perf;

    /* track name from file */
    char TrackName[256];

    /* used in small loops */
    int i;

    /* sequence pointer */
    sequence * seq;
    event e;

    /* read in header */
    ID = read_long ();
    TrackLength = read_long ();
    Format = read_short ();
    NumTracks = read_short ();
    ppqn = read_short ();

    //printf( "[%8lX] len[%ld] fmt[%d] num[%d] ppqn[%d]\n",
    //      ID, TrackLength, Format, NumTracks, ppqn );

    /* magic number 'MThd' */
    if (ID != 0x4D546864)
    {
        Glib::ustring message = "Invalid MIDI header detected: ";
        message += Ulong_To_String_Hex(ID);
        error_message_gtk(message);
        return false;
    }

    /* we are only supporting format 1 for now */
    if (Format != 1)
    {
        Glib::ustring message = "Unsupported MIDI format detected: ";
        message += NumberToString(Format);
        error_message_gtk(message);
        return false;
    }

    /* We should be good to load now   */
    /* for each Track in the midi file */
    for (int curTrack = 0; curTrack < NumTracks; curTrack++)
    {
        /* done for each track */
        bool done = false;
        perf = 0;

        /* events */
        unsigned char status = 0, type, data[2], laststatus;
        long len;
        unsigned long proprietary = 0;

        /* Get ID + Length */
        ID = read_long ();
        TrackLength = read_long ();

        /* magic number 'MTrk' */
        if (ID == 0x4D54726B)
        {
            /* we know we have a good track, so we can create
               a new sequence to dump it to */
            seq = new sequence ();
            if (seq == NULL)
            {
                error_message_gtk("Memory allocation failed");
                return false;
            }
            seq->set_master_midi_bus (&a_perf->m_master_bus);

            /* reset time */
            RunningTime = 0;

            /* this gets each event in the Trk */
            while (!done)
            {
                /* get time delta */
                Delta = read_var ();

                /* get status */
                laststatus = status;
                status = m_d[m_pos];

                /* is it a status bit ? */
                if ((status & 0x80) == 0x00)
                {
                    /* no, its a running status */
                    status = laststatus;
                }
                else
                {
                    /* its a status, increment */
                    m_pos++;
                }

                /* set the members in event */
                e.set_status (status);

                RunningTime += Delta;
                /* current time is ppqn according to the file,
                   we have to adjust it to our own ppqn.
                   PPQN / ppqn gives us the ratio */
                CurrentTime = (RunningTime * c_ppqn) / ppqn;

                //printf( "D[%6ld] [%6ld] %02X\n", Delta, CurrentTime, status);
                e.set_timestamp (CurrentTime);

                /* switch on the channelless status */
                switch (status & 0xF0)
                {
                /* case for those with 2 data bytes */
                case EVENT_NOTE_OFF:
                case EVENT_NOTE_ON:
                case EVENT_AFTERTOUCH:
                case EVENT_CONTROL_CHANGE:
                case EVENT_PITCH_WHEEL:

                    data[0] = read_byte();
                    data[1] = read_byte();

                    // some files have vel=0 as note off
                    if ((status & 0xF0) == EVENT_NOTE_ON && data[1] == 0)
                    {
                        e.set_status (EVENT_NOTE_OFF);
                    }

                    //printf( "%02X %02X\n", data[0], data[1] );

                    /* set data and add */
                    e.set_data (data[0], data[1]);
                    seq->add_event (&e);

                    /* set midi channel */
                    seq->set_midi_channel (status & 0x0F);
                    break;

                /* one data item */
                case EVENT_PROGRAM_CHANGE:
                case EVENT_CHANNEL_PRESSURE:

                    data[0] = read_byte();
                    //printf( "%02X\n", data[0] );

                    /* set data and add */
                    e.set_data (data[0]);
                    seq->add_event (&e);

                    /* set midi channel */
                    seq->set_midi_channel (status & 0x0F);
                    break;

                /* meta midi events ---  this should be FF !!!!!  */
                case 0xF0:

                    if (status == 0xFF)
                    {
                        /* get meta type */
                        type = read_byte();
                        len = read_var ();

                        //printf( "%02X %08X ", type, (int) len );

                        switch (type)
                        {
                        /* proprietary */
                        case 0x7f:

                            /* FF 7F len data  */
                            if (len > 4)
                            {
                                proprietary = read_long ();
                                len -= 4;
                            }

                            if (proprietary == c_midibus)
                            {
                                seq->set_midi_bus (read_byte());
                                len--;
                            }
                            else if (proprietary == c_midich)
                            {
                                seq->set_midi_channel (read_byte());
                                len--;
                            }
                            else if (proprietary == c_timesig)
                            {
                                seq->set_bp_measure (read_byte());
                                seq->set_bw (read_byte());
                                len -= 2;
                            }
                            else if (proprietary == c_transpose)
                            {
                                seq->set_transposable (read_byte ());
                                len--;
                            }
                            else if (proprietary == c_triggers)
                            {
                                int num_triggers = len / 4;

                                for (int i = 0; i < num_triggers; i += 2)
                                {
                                    unsigned long on = read_long ();
                                    unsigned long length = (read_long () - on);
                                    len -= 8;
                                    seq->add_trigger(on, length, 0, false);
                                }
                            }
                            else if (proprietary == c_triggers_new)
                            {
                                int num_triggers = len / 12;

                                //printf( "num_triggers[%d]\n", num_triggers );
                                for (int i = 0; i < num_triggers; i++)
                                {
                                    unsigned long on = read_long ();
                                    unsigned long off = read_long ();
                                    unsigned long length = off - on + 1;
                                    unsigned long offset = read_long ();

                                    //printf( "< start[%d] end[%d] offset[%d]\n",
                                    //        on, off, offset );

                                    len -= 12;
                                    seq->add_trigger (on, length, offset, false);
                                }
                            }

                            /* eat the rest */
                            m_pos += len;
                            break;

                        case 0x58:    /* Time Signature  bp_measure / bw */
                            /*
                                If the midi file contains both proprietary (c_timesig)
                                and Midi type 0x58 then it came from seq42 or seq24 (Stazed versions).
                                In this case the Midi type is parsed first (because it is listed first)
                                then it gets overwritten by the proprietary, above.
                            */
                            if (len == 4)
                            {
                                int bp_measure = int(read_byte());  // nn
                                int logbase2 = int(read_byte());    // dd

                                read_byte();                        // cc eat it
                                read_byte();                        // bb eat it

                                long bw = long(pow2(logbase2));     // convert dd to bw

                                if(bp_measure == 0 || bw == 0)      // spec assumes 4 x 4 as we do
                                    break;

                                if(curTrack == 0)                   // set main perform if first track
                                {
                                    a_perf->set_bp_measure(bp_measure);
                                    a_perf->set_bw(bw);
                                }

                                seq->set_bp_measure(bp_measure);    // set the sequence each time
                                seq->set_bw(bw);

                                /*printf
                                (
                                   "Time Signature set to %d/%d\n",
                                    int(seq->get_bp_measure()),
                                    int(seq->get_bw())
                                );*/
                            }
                            else
                                m_pos += len;           /* eat it           */
                            break;

                        case 0x51:                      /* Set Tempo  = bpm      */
                            if (len == 3)
                            {
                                unsigned tempo = unsigned(read_byte());
                                tempo = (tempo * 256) + unsigned(read_byte());
                                tempo = (tempo * 256) + unsigned(read_byte());

                                if(tempo == 0)          /* Midi spec assumes 120 bpm as we do */
                                    break;

                                int bpm = (double) 60000000.0 / tempo;

                                if(curTrack == 0)  // only if first track - we don't support tempo change
                                    a_perf->set_bpm(bpm);
                                //printf("BPM set to %d\n", bpm);
                            }
                            else
                                m_pos += len;           /* eat it           */
                            break;

                        /* Trk Done */
                        case 0x2f:

                            // If delta is 0, then another event happened at the same time
                            // as the track end.  the sequence class will discard the last
                            // note.  This is a fix for that.   Native Seq24 file will always
                            // have a Delta >= 1
                            if ( Delta == 0 )
                            {
                                CurrentTime += 1;
                            }

                            seq->set_length (CurrentTime, false);
                            seq->zero_markers ();
                            done = true;
                            break;

                        /* Track name */
                        case 0x03:
                            for (i = 0; i < len; i++)
                            {
                                TrackName[i] = read_byte();
                            }

                            TrackName[i] = '\0';

                            //printf("[%s]\n", TrackName );
                            seq->set_name (TrackName);
                            break;

                        /* sequence number */
                        case 0x00:
                            if (len == 0x00)
                                perf = 0;
                            else
                                perf = read_short ();

                            //printf ( "perf %d\n", perf );
                            break;

                        default:
                            for (i = 0; i < len; i++)
                            {
                                read_byte();
                            }
                            break;
                        }
                    }
                    else if(status == 0xF0)
                    {
                        /* sysex */
                        len = read_var ();

                        /* skip it */
                        m_pos += len;

                        fprintf(stderr, "Warning, no support for SYSEX messages, discarding.\n");
                    }
                    else
                    {
                        Glib::ustring message = "Unexpected system event : ";
                        message += Ulong_To_String_Hex((unsigned long)status);
                        error_message_gtk(message);
                        return false;
                    }

                    break;

                default:
                    Glib::ustring message = "Unsupported MIDI event:  ";
                    message += Ulong_To_String_Hex((unsigned long)status);
                    error_message_gtk(message);
                    return false;
                    break;
                }
            }			/* while ( !done loading Trk chunk */

            /* the sequence has been filled, add it  */
            //printf ( "add_sequence( %d )\n", perf + (a_screen_set * c_seqs_in_set));
            a_perf->add_sequence (seq, perf + (a_screen_set * c_seqs_in_set));
        }

        /* dont know what kind of chunk */
        else
        {
            /* its not a MTrk, we dont know how to deal with it,
               so we just eat it */
            fprintf(stderr, "Unsupported MIDI header detected: %8lX\n", ID);
            m_pos += TrackLength;
            done = true;
        }
    }				/* for(eachtrack) */

    //printf ( "file_size[%d] m_pos[%d]\n", file_size, m_pos );

    if ((file_size - m_pos) > (int) sizeof (unsigned long))
    {
        ID = read_long ();
        if (ID == c_midictrl)
        {
            unsigned long seqs = read_long ();

            for (unsigned int i = 0; i < seqs; i++)
            {
                a_perf->get_midi_control_toggle (i)->m_active = read_byte();
                a_perf->get_midi_control_toggle (i)->m_inverse_active =
                    read_byte();
                a_perf->get_midi_control_toggle (i)->m_status = read_byte();
                a_perf->get_midi_control_toggle (i)->m_data = read_byte();
                a_perf->get_midi_control_toggle (i)->m_min_value = read_byte();
                a_perf->get_midi_control_toggle (i)->m_max_value = read_byte();

                a_perf->get_midi_control_on (i)->m_active = read_byte();
                a_perf->get_midi_control_on (i)->m_inverse_active =
                    read_byte();
                a_perf->get_midi_control_on (i)->m_status = read_byte();
                a_perf->get_midi_control_on (i)->m_data = read_byte();
                a_perf->get_midi_control_on (i)->m_min_value = read_byte();
                a_perf->get_midi_control_on (i)->m_max_value = read_byte();

                a_perf->get_midi_control_off (i)->m_active = read_byte();
                a_perf->get_midi_control_off (i)->m_inverse_active =
                    read_byte();
                a_perf->get_midi_control_off (i)->m_status = read_byte();
                a_perf->get_midi_control_off (i)->m_data = read_byte();
                a_perf->get_midi_control_off (i)->m_min_value = read_byte();
                a_perf->get_midi_control_off (i)->m_max_value = read_byte();
            }
        }

        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_midiclocks)
        {
            TrackLength = read_long ();
            /* TrackLength is nyumber of buses */
            for (unsigned int x = 0; x < TrackLength; x++)
            {
                int bus_on = read_byte();
                a_perf->get_master_midi_bus ()->set_clock (x, (clock_e) bus_on);
            }
        }
    }

    if ((file_size - m_pos) > (int) sizeof (unsigned long))
    {
        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_notes)
        {
            unsigned int screen_sets = read_short ();

            for (unsigned int x = 0; x < screen_sets; x++)
            {
                /* get the length of the string */
                unsigned int len = read_short ();
                string notess;

                for (unsigned int i = 0; i < len; i++)
                    notess += read_byte();

                a_perf->set_screen_set_notepad (x, &notess);
            }
        }
    }

    if ((file_size - m_pos) > (int) sizeof (unsigned int))
    {
        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_bpmtag)
        {
            long bpm = read_long ();
            a_perf->set_bpm (bpm);
        }
    }

    // read in the mute group info.
    if ((file_size - m_pos) > (int) sizeof (unsigned long))
    {
        ID = read_long ();
        if (ID == c_mutegroups)
        {
            long length = read_long ();

            if(length != 0) // 0 means it came from SEQ42 so ignore
            {
                if (c_gmute_tracks != length)
                {
                    printf( "corrupt data in mutegroup section\n" );
                }
                for (int i = 0; i < c_seqs_in_set; i++)
                {
                    a_perf->select_group_mute(read_long ());
                    for (int k = 0; k < c_seqs_in_set; ++k)
                    {
                        a_perf->set_group_mute_state(k, read_long ());
                    }
                }
            }
        }
    }
    if ((file_size - m_pos) > (int) sizeof (unsigned int))
    {
        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_bp_measure)
        {
            long bp_mes = read_long ();
            a_perf->set_bp_measure(bp_mes);
        }
    }

    if ((file_size - m_pos) > (int) sizeof (unsigned int))
    {
        /* Get ID + Length */
        ID = read_long ();
        if (ID == c_beat_width)
        {
            long bw = read_long ();
            a_perf->set_bw(bw);
        }
    }

    // *** ADD NEW TAGS AT END **************/

    return true;
    //printf ( "done\n");
}