Exemplo n.º 1
0
obj_t::obj_t( const char * objname ) 
{
    // long name
    fullpath = realname( objname ); 

    // model handle
    const char * shortname = strip_path_and_extension( objname );
    name = copy_string( shortname );

    // memory map file
    mmfile_t mm( fullpath ); 
    index = 0;
    size = mm.size;
    data = mm.data;
    
    
    while ( index < size ) 
    {
        strip_white_space();

        switch( data[i] ) 
        {
        case 'm':
            if ( check_name( "mtllib" ) )
                consume_line();
            break;
        case 'u':
            if ( check_name( "usemtl" ) )
                consume_line();
            break;
        case 'g':
            consume_line();
            break;
        case '#':
            strip_white_space();
            break;
        case 'v':
            if ( check_name( "vn" ) )
                add_normal();
            else if ( check_name( "vt" ) )
                add_texcoord();
            else if ( data[index+1] == ' ' )
                add_vertex();
            else
                core.warn( "obj_t: straggling v in objfile: %s", name );
            break;
        case 'f':
            if ( data[index+1] == ' ' ) 
                add_face();
            break;
        case 's':
        default:
            ++index;
            break;
        }
    }
}
Exemplo n.º 2
0
bool
Audio_File_SF::open ( void )
{
    SF_INFO si;

    assert( _in == NULL );

    memset( &si, 0, sizeof( si ) );

    if ( ! ( _in = sf_open( realname( _filename ), SFM_READ, &si ) ) )
        return false;

    _current_read = 0;
    _length       = si.frames;
    _samplerate   = si.samplerate;
    _channels     = si.channels;

//    seek( 0 );
    return true;
}
Exemplo n.º 3
0
Audio_File_SF *
Audio_File_SF::create ( const char *filename, nframes_t samplerate, int channels, const char *format )
{
    SF_INFO si;
    SNDFILE *out;

    memset( &si, 0, sizeof( si ) );

    const Audio_File::format_desc *fd = Audio_File::find_format( Audio_File_SF::supported_formats, format );

    if ( ! fd )
        return (Audio_File_SF *)1;

    si.samplerate =  samplerate;
    si.channels   =  channels;
    si.format = fd->id;

    char *name;
    asprintf( &name, "%s.%s", filename, fd->extension );

    if ( ! ( out = sf_open( realname( name ), SFM_WRITE, &si ) ) )
    {
        printf( "couldn't create soundfile.\n" );
        free( name );
        return NULL;
    }

    Audio_File_SF *c = new Audio_File_SF;

    c->_filename   = name;
    c->_length     = 0;
    c->_samplerate = samplerate;
    c->_channels   = channels;

    c->_in         = out;

    c->_peaks.prepare_for_writing();

    return c;
}
Exemplo n.º 4
0
Audio_File_SF *
Audio_File_SF::from_file ( const char *filename )
{
    SNDFILE *in;
    SF_INFO si;

    Audio_File_SF *c = NULL;

    memset( &si, 0, sizeof( si ) );

    if ( ! ( in = sf_open( realname( filename ), SFM_READ, &si ) ) )
        return NULL;

/*     if ( si.samplerate != timeline->sample_rate() ) */
/*     { */
/*         printf( "error: samplerate mismatch!\n" ); */
/*         goto invalid; */
/*     } */

    c = new Audio_File_SF;

//    c->_peak_writer  = NULL;
    c->_current_read = 0;
    c->_filename     = strdup( filename );
    c->_length       = si.frames;
    c->_samplerate   = si.samplerate;
    c->_channels     = si.channels;

    c->_in = in;
//    sf_close( in );

    return c;

invalid:

    sf_close( in );
    return NULL;
}
Exemplo n.º 5
0
const char *
Audio_File::filename ( void ) const
{
    return realname( _filename );
}
Exemplo n.º 6
0
static void
hprf(const char *fmt, int mesg, FILE *f, int threaded, const char *attrlist)
{
	struct message	*mp = &message[mesg-1];
	char	*headline = NULL, *subjline, *name, *cp, *pbuf = NULL;
	struct headline	hl;
	size_t	headsize = 0;
	const char	*fp;
	int	B, c, i, n, s;
	int	headlen = 0;
	struct str	in, out;
	int	subjlen = scrnwidth, fromlen, isto = 0, isaddr = 0;
	FILE	*ibuf;

	if ((mp->m_flag & MNOFROM) == 0) {
		if ((ibuf = setinput(&mb, mp, NEED_HEADER)) == NULL)
			return;
		if ((headlen = readline(ibuf, &headline, &headsize)) < 0)
			return;
	}
	if ((subjline = hfield("subject", mp)) == NULL)
		subjline = hfield("subj", mp);
	if (subjline == NULL) {
		out.s = NULL;
		out.l = 0;
	} else {
		in.s = subjline;
		in.l = strlen(subjline);
		mime_fromhdr(&in, &out, TD_ICONV | TD_ISPR);
		subjline = out.s;
	}
	if ((mp->m_flag & MNOFROM) == 0) {
		pbuf = ac_alloc(headlen + 1);
		parse(headline, headlen, &hl, pbuf);
	} else {
		hl.l_from = /*fakefrom(mp);*/NULL;
		hl.l_tty = NULL;
		hl.l_date = fakedate(mp->m_time);
	}
	if (value("datefield") && (cp = hfield("date", mp)) != NULL)
		hl.l_date = fakedate(rfctime(cp));
	if (Iflag) {
		if ((name = hfield("newsgroups", mp)) == NULL)
			if ((name = hfield("article-id", mp)) == NULL)
				name = "<>";
		name = prstr(name);
	} else if (value("show-rcpt") == NULL) {
		name = name1(mp, 0);
		isaddr = 1;
		if (value("showto") && name && is_myname(skin(name))) {
			if ((cp = hfield("to", mp)) != NULL) {
				name = cp;
				isto = 1;
			}
		}
	} else {
		isaddr = 1;
		if ((name = hfield("to", mp)) != NULL)
			isto = 1;
	}
	if (name == NULL) {
		name = "";
		isaddr = 0;
	}
	if (isaddr) {
		if (value("showname"))
			name = realname(name);
		else {
			name = prstr(skin(name));
		}
	}
	for (fp = fmt; *fp; fp++) {
		if (*fp == '%') {
			if (*++fp == '-') {
				fp++;
			} else if (*fp == '+')
				fp++;
			while (digitchar(*fp&0377))
				fp++;
			if (*fp == '\0')
				break;
		} else {
#if defined (HAVE_MBTOWC) && defined (HAVE_WCWIDTH)
			if (mb_cur_max > 1) {
				wchar_t	wc;
				if ((s = mbtowc(&wc, fp, mb_cur_max)) < 0)
					n = s = 1;
				else {
					if ((n = wcwidth(wc)) < 0)
						n = 1;
				}
			} else
#endif  /* HAVE_MBTOWC && HAVE_WCWIDTH */
			{
				n = s = 1;
			}
			subjlen -= n;
			while (--s > 0)
				fp++;
		}
	}
	for (fp = fmt; *fp; fp++) {
		if (*fp == '%') {
			B = 0;
			n = 0;
			s = 1;
			if (*++fp == '-') {
				s = -1;
				fp++;
			} else if (*fp == '+')
				fp++;
			if (digitchar(*fp&0377)) {
				do
					n = 10*n + *fp - '0';
				while (fp++, digitchar(*fp&0377));
			}
			if (*fp == '\0')
				break;
			n *= s;
			switch (*fp) {
			case '%':
				putc('%', f);
				subjlen--;
				break;
			case '>':
			case '<':
				c = dot == mp ? *fp&0377 : ' ';
				putc(c, f);
				subjlen--;
				break;
			case 'a':
				c = dispc(mp, attrlist);
				putc(c, f);
				subjlen--;
				break;
			case 'm':
				if (n == 0) {
					n = 3;
					if (threaded)
						for (i=msgCount; i>999; i/=10)
							n++;
				}
				subjlen -= fprintf(f, "%*d", n, mesg);
				break;
			case 'f':
				if (n <= 0)
					n = 18;
				fromlen = n;
				if (isto)
					fromlen -= 3;
				fprintf(f, "%s%s", isto ? "To " : "",
						colalign(name, fromlen, 1));
				subjlen -= n;
				break;
			case 'd':
				if (n <= 0)
					n = 16;
				subjlen -= fprintf(f, "%*.*s", n, n, hl.l_date);
				break;
			case 'l':
				if (n == 0)
					n = 4;
				if (mp->m_xlines)
					subjlen -= fprintf(f, "%*ld", n,
							mp->m_xlines);
				else {
					subjlen -= n;
					while (n--)
						putc(' ', f);
				}
				break;
			case 'o':
				if (n == 0)
					n = -5;
				subjlen -= fprintf(f, "%*lu", n,
						(long)mp->m_xsize);
				break;
			case 'i':
				if (threaded)
					subjlen -= putindent(f, mp,
							scrnwidth - 60);
				break;
			case 'S':
				B = 1;
				/*FALLTHRU*/
			case 's':
				n = n>0 ? n : subjlen - 2;
				if (B)
					n -= 2;
				if (subjline != NULL && n >= 0) {
					/* pretty pathetic */
					fprintf(f, B ? "\"%s\"" : "%s",
						colalign(subjline, n, 0));
				}
				break;
			case 'U':
				if (n == 0)
					n = 9;
				subjlen -= fprintf(f, "%*lu", n, mp->m_uid);
				break;
			case 'e':
				if (n == 0)
					n = 2;
				subjlen -= fprintf(f, "%*u", n, threaded == 1 ?
						mp->m_level : 0);
				break;
			case 't':
				if (n == 0) {
					n = 3;
					if (threaded)
						for (i=msgCount; i>999; i/=10)
							n++;
				}
				fprintf(f, "%*ld", n, threaded ?
						mp->m_threadpos : mesg);
				subjlen -= n;
				break;
			case 'c':
				if (n == 0)
					n = 6;
				subjlen -= fprintf(f, "%*g", n, mp->m_score);
				break;
			}
		} else
			putc(*fp&0377, f);
	}
	putc('\n', f);
	if (out.s)
		free(out.s);
	if (headline)
		free(headline);
	if (pbuf)
		ac_free(pbuf);
}