示例#1
0
//----------------------------------------------------------------
bool knob::on_scroll_event(GdkEventScroll* event)
{
	if (event->direction == GDK_SCROLL_UP) value += scroll_wheel_speed;
	if (event->direction == GDK_SCROLL_DOWN) value -= scroll_wheel_speed;

	value = ((float)roundf(value*100))/100;

	if (value < min) value = min;
	if (value > max) value = max;
	set_value(value);


	if (invert)
	{
		float inverted_value = max - value;
		write_function( controller, port_number, sizeof(float), 0, (const void*)&inverted_value);
	}
	else
	{
		write_function( controller, port_number, sizeof(float), 0, (const void*)&value);
	}

	// ask GTK to redraw when it suits
	Glib::RefPtr<Gdk::Window> win = get_window();
	if (win)
	{
		Gdk::Rectangle r(0,0,get_allocation().get_width(), get_allocation().get_height() );
		win->invalidate_rect(r, false);
	}
}
示例#2
0
int main(int argc,char *argv[])
{
    pthread_t pthd;
    pthread_mutex_init(&mut,NULL);
    pthread_create(&pthd, NULL,(void *)&read_function, NULL);
    write_function();
    return 0;
}
示例#3
0
文件: widget.cpp 项目: dafx/guitarix
// write (UI) controller value changes to the host->engine
void Widget::on_value_changed(uint32_t port_index)
{
  Gxw::Regler *regler = static_cast<Gxw::Regler*>(
                                    get_controller_by_port(port_index));
  if (regler)
  {
    float value = regler->cp_get_value();
    write_function(controller, port_index, sizeof(float), 0,
                                    static_cast<const void*>(&value));
    if (port_index == TUNEMODE) set_tuning(value);
    if (port_index == TEMPERAMENT) set_temperament();
    if (port_index == REFFREQ) m_tuner.set_reference_pitch(value);
  } 
  
  if (port_index == RESET) {
      write_function(controller, RESET, sizeof(float), 0,
                                    static_cast<const void*>(&reset));
  }
}
示例#4
0
文件: widget.cpp 项目: dafx/guitarix
// write (UI) controller value changes to the host->engine
void Widget::on_value_changed(uint32_t port_index)
{
  Gxw::Regler *regler = static_cast<Gxw::Regler*>(
                                    get_controller_by_port(port_index));
  if (regler)
  {
    float value = regler->cp_get_value();
    Glib::ustring v = regler->cp_get_var();
    if (v.empty()) {
        //fprintf(stderr,"value set %f\n get %f\n",value,pow(10.0,value));
        value = pow(10.0,value);
        write_function(controller, port_index, sizeof(float), 0,
                                    static_cast<const void*>(&value));
    } else {
       write_function(controller, port_index, sizeof(float), 0,
                                    static_cast<const void*>(&value));
    }
  }
}
示例#5
0
文件: widget.cpp 项目: dafx/guitarix
// write (UI) controller value changes to the host->engine
void Widget::on_value_changed(uint32_t port_index)
{
  Gxw::Regler *regler = static_cast<Gxw::Regler*>(
                                    get_controller_by_port(port_index));
  if (regler)
  {
    float value = regler->cp_get_value();
    write_function(controller, port_index, sizeof(float), 0,
                                    static_cast<const void*>(&value));
  }
}
bool toggle::on_button_release_event(GdkEventButton* event)
{

		val = 1 - val;

	float new_value = (float)val;

	// here we use the LV2UI_Controller and LV2UI_write_function "things"
	// to write some data to a port
	write_function( controller, port_number, sizeof(float), 0, (const void*)&new_value);
	
	queue_draw();
  
  return true;
}
示例#7
0
void write_statement(CppWriter& writer, Term* term)
{
    if (is_comment(term)) {
        if (term->stringProp("comment") != "") {
            writer.write("//");
            writer.write(term->stringProp("comment"));
        }
    } else if (is_function(term)) {
        write_function(writer, term);
    } else if (is_statement(term)) {
        if (term->name != "") {
            write_type_name(writer, term->type);
            writer.write(" ");
            writer.write(term->name);
            writer.write(" = ");
        }
        write_expression(writer, term);
        writer.write(";");
    }
}
示例#8
0
void write_fluffy_decls(FILE *output, const translation_unit_t *unit)
{
	out            = output;
	global_scope = &unit->scope;

	print_to_file(out);
	fprintf(out, "/* WARNING: Automatically generated file */\n");

	/* write structs,unions + enums */
	entity_t *entity = unit->scope.entities;
	for( ; entity != NULL; entity = entity->base.next) {
		if (entity->kind != ENTITY_TYPEDEF)
			continue;

		type_t *type = entity->typedefe.type;
		if(type->kind == TYPE_COMPOUND_STRUCT
				|| type->kind == TYPE_COMPOUND_UNION) {
			write_compound(entity->base.symbol, &type->compound);
		} else if(type->kind == TYPE_ENUM) {
			write_enum(entity->base.symbol, &type->enumt);
		}
	}

	/* write global variables */
	entity = unit->scope.entities;
	for( ; entity != NULL; entity = entity->base.next) {
		if (entity->kind != ENTITY_VARIABLE)
			continue;

		write_variable(entity);
	}

	/* write functions */
	entity = unit->scope.entities;
	for( ; entity != NULL; entity = entity->base.next) {
		if (entity->kind != ENTITY_FUNCTION)
			continue;

		write_function(entity);
	}
}
示例#9
0
void write_term(SourceWriter* writer, Term* term)
{
    if (is_comment(term)) {
        if (is_empty_comment(term))
            return;

        writer->write("// ");
        writer->write(term->stringProp("comment","").c_str());
        writer->newline();
        return;
    }

    if (is_function(term)) {
        write_function(writer, term);
        return;
    }

    writer->write(get_unique_name(term));
    writer->write(" = ");

    if (is_value(term)) {
        write_term_value(writer, term);
    } else {
        // function call syntax
        writer->write(term->function->name.c_str());
        writer->write("(");

        // write inputs
        for (int i=0; i < term->numInputs(); i++) {
            if (i > 0) {
                writer->write(", ");
            }
            writer->write(get_unique_name(term));
        }
    }

    writer->write(";");
    writer->newline();
}
示例#10
0
static void write_doc(buffer_t buffer, VALUE hash, VALUE check_keys, VALUE move_id) {
    buffer_position start_position = buffer_get_position(buffer);
    buffer_position length_location = buffer_save_space(buffer, 4);
    buffer_position length;
    int allow_id;
    int (*write_function)(VALUE, VALUE, VALUE) = NULL;
    VALUE id_str = rb_str_new2("_id");
    VALUE id_sym = ID2SYM(rb_intern("_id"));

    if (length_location == -1) {
        rb_raise(rb_eNoMemError, "failed to allocate memory in buffer.c");
    }

    // write '_id' first if move_id is true. then don't allow an id to be written.
    if(move_id == Qtrue) {
        allow_id = 0;
        if (rb_funcall(hash, rb_intern("has_key?"), 1, id_str) == Qtrue) {
            VALUE id = rb_hash_aref(hash, id_str);
            write_element_with_id(id_str, id, pack_extra(buffer, check_keys));
        } else if (rb_funcall(hash, rb_intern("has_key?"), 1, id_sym) == Qtrue) {
            VALUE id = rb_hash_aref(hash, id_sym);
            write_element_with_id(id_sym, id, pack_extra(buffer, check_keys));
        }
    }
    else {
        allow_id = 1;
        // Ensure that hash doesn't contain both '_id' and :_id
        if ((rb_obj_classname(hash), "Hash") == 0) {
            if ((rb_funcall(hash, rb_intern("has_key?"), 1, id_str) == Qtrue) &&
                   (rb_funcall(hash, rb_intern("has_key?"), 1, id_sym) == Qtrue)) {
                      VALUE oid_sym = rb_hash_delete(hash, id_sym);
                      rb_funcall(hash, rb_intern("[]="), 2, id_str, oid_sym);
            }
        }
    }

    if(allow_id == 1) {
        write_function = write_element_with_id;
    }
    else {
        write_function = write_element_without_id;
    }

    // we have to check for an OrderedHash and handle that specially
    if (strcmp(rb_obj_classname(hash), "BSON::OrderedHash") == 0) {
        VALUE keys = rb_funcall(hash, rb_intern("keys"), 0);
        int i;
                for(i = 0; i < RARRAY_LEN(keys); i++) {
            VALUE key = rb_ary_entry(keys, i);
            VALUE value = rb_hash_aref(hash, key);

            write_function(key, value, pack_extra(buffer, check_keys));
        }
    } else if (rb_obj_is_kind_of(hash, RB_HASH) == Qtrue) {
        rb_hash_foreach(hash, write_function, pack_extra(buffer, check_keys));
    } else {
        bson_buffer_free(buffer);
        rb_raise(InvalidDocument, "BSON.serialize takes a Hash but got a %s", rb_obj_classname(hash));
    }

    // write null byte and fill in length
    SAFE_WRITE(buffer, &zero, 1);
    length = buffer_get_position(buffer) - start_position;

    // make sure that length doesn't exceed 4MB
    if (length > max_bson_size) {
      bson_buffer_free(buffer);
      rb_raise(InvalidDocument, "Document too large: BSON documents are limited to %d bytes.", max_bson_size);
      return;
    }
    SAFE_WRITE_AT_POS(buffer, length_location, (const char*)&length, 4);
}
示例#11
0
void write_jna_decls(FILE *output, const translation_unit_t *unit)
{
	out          = output;
	global_scope = &unit->scope;

	pset_new_init(&avoid_symbols);

	print_to_file(out);
	fprintf(out, "/* WARNING: Automatically generated file */\n");
	fputs("import com.sun.jna.Native;\n", out);
	fputs("import com.sun.jna.Pointer;\n", out);
	fputs("\n", out);

	const char *register_libname = libname;
	if (register_libname == NULL)
		register_libname = "library";

	/* TODO: where to get the name from? */
	fputs("public class binding {\n", out);
	fputs("\tstatic {\n", out);
	fprintf(out, "\t\tNative.register(\"%s\");\n", register_libname);
	fputs("\t}\n", out);
	fputs("\n", out);

	/* read the avoid list */
	FILE *avoid = fopen("avoid.config", "r");
	if (avoid != NULL) {
		for (;;) {
			char buf[1024];
			char *res = fgets(buf, sizeof(buf), avoid);
			if (res == NULL)
				break;
			if (buf[0] == 0)
				continue;

			size_t len = strlen(buf);
			if (buf[len-1] == '\n')
				buf[len-1] = 0;

			char *str = malloc(len+1);
			memcpy(str, buf, len+1);
			symbol_t *symbol = symbol_table_insert(str);
			pset_new_insert(&avoid_symbols, symbol);
		}
		fclose(avoid);
	}

	/* write structs,unions + enums */
	entity_t *entity = unit->scope.entities;
	for ( ; entity != NULL; entity = entity->base.next) {
		if (entity->kind == ENTITY_ENUM) {
			if (find_enum_typedef(&entity->enume) != NULL)
				continue;
			write_enum(entity->base.symbol, &entity->enume);
		} else if (entity->kind == ENTITY_TYPEDEF) {
			type_t *type = entity->declaration.type;
			if (type->kind == TYPE_ENUM) {
				write_enum(entity->base.symbol, type->enumt.enume);
			}
		}

#if 0
		if (is_type_compound(type)) {
			write_compound(entity->base.symbol, &type->compound);
		}
#endif
	}

	/* write functions */
	entity = unit->scope.entities;
	for ( ; entity != NULL; entity = entity->base.next) {
		if (entity->kind != ENTITY_FUNCTION)
			continue;
		if (entity->base.pos.is_system_header)
			continue;
		if (entity->function.elf_visibility != ELF_VISIBILITY_DEFAULT)
			continue;
		if (output_limits != NULL) {
			bool              in_limits  = false;
			char const *const input_name = entity->base.pos.input_name;
			for (output_limit *limit = output_limits; limit != NULL;
			     limit = limit->next) {
			    if (streq(limit->filename, input_name)) {
					in_limits = true;
					break;
				}
			}
			if (!in_limits)
				continue;
		}

		if (pset_new_contains(&avoid_symbols, entity->base.symbol))
			continue;
		write_function(entity);
	}

	fputs("}\n", out);

	pset_new_destroy(&avoid_symbols);
}
示例#12
0
static void write_variable( Transport *tpt, lua_State *L, int var_index )
{
  int stack_at_start = lua_gettop( L );
  
  switch( lua_type( L, var_index ) )
  {
    case LUA_TNUMBER:
      transport_write_uint8_t( tpt, RPC_NUMBER );
      transport_write_number( tpt, lua_tonumber( L, var_index ) );
      break;

    case LUA_TSTRING:
    {
      const char *s;
      uint32_t len;
      transport_write_uint8_t( tpt, RPC_STRING );
      s = lua_tostring( L, var_index );
      len = lua_strlen( L, var_index );
      transport_write_uint32_t( tpt, len );
      transport_write_string( tpt, s, len );
      break;
    }

    case LUA_TTABLE:
      transport_write_uint8_t( tpt, RPC_TABLE );
      write_table( tpt, L, var_index );
      transport_write_uint8_t( tpt, RPC_TABLE_END );
      break;

    case LUA_TNIL:
      transport_write_uint8_t( tpt, RPC_NIL );
      break;

    case LUA_TBOOLEAN:
      transport_write_uint8_t( tpt,RPC_BOOLEAN );
      transport_write_uint8_t( tpt, ( uint8_t )lua_toboolean( L, var_index ) );
      break;

    case LUA_TFUNCTION:
      transport_write_uint8_t( tpt, RPC_FUNCTION );
      write_function( tpt, L, var_index );
      transport_write_uint8_t( tpt, RPC_FUNCTION_END );
      break;

    case LUA_TUSERDATA:
      if( lua_isuserdata( L, var_index ) && ismetatable_type( L, var_index, "rpc.helper" ) )
      {
        transport_write_uint8_t( tpt, RPC_REMOTE );
        helper_remote_index( ( Helper * )lua_touserdata( L, var_index ) );        
      } else
        luaL_error( L, "userdata transmission unsupported" );
      break;

    case LUA_TTHREAD:
      luaL_error( L, "thread transmission unsupported" );
      break;

    case LUA_TLIGHTUSERDATA:
      luaL_error( L, "light userdata transmission unsupported" );
      break;
  }
  MYASSERT( lua_gettop( L ) == stack_at_start );
}
void knob::draw_slider(int x, int y)
{

	
	if (drag==false && max>1)
	{
		if (y > get_allocation().get_height()/2 && value > min) { value -= 1; }
		if (y < get_allocation().get_height()/2 && value < max) { value += 1; }
	}

	if (drag==false && max==1)
	{
		if (y > get_allocation().get_height()/2 && value > min) { value -= 0.001; }
		if (y < get_allocation().get_height()/2 && value < max) { value += 0.001; }
	}


	float width = get_allocation().get_width();
	float height = (get_allocation().get_height() / 1.5);

	if (drag==true)
	{
		// converty mouse y to knob value
		y-=(get_allocation().get_height()/6);
		knob_value = (height-y)/height;	

		if (knob_value < 0) { knob_value = 0; }
		if (knob_value > 1) { knob_value = 1; }

		if (max > min)
		{
			value =  min + (knob_value*(max-min));
	    	}
	
		if (max <= min)
		{
			value =  max + ((1-knob_value)*(min-max));
	    	}

	}	


	if (snap)
	{
		value = int(value);
		set_value(value);
	}



	// which port to write to, check your .ttl file for the index of
	// each port
   
	// here we use the LV2UI_Controller and LV2UI_write_function "things"
	// to write some data to a port
	if (invert)
	{
		float inverted_value = max - value;
		write_function( controller, port_number, sizeof(float), 0, (const void*)&inverted_value);
	}
	else
	{
		write_function( controller, port_number, sizeof(float), 0, (const void*)&value);
	}

	// ask GTK to redraw when it suits
	Glib::RefPtr<Gdk::Window> win = get_window();
	if (win)
	{
		Gdk::Rectangle r(0,0,get_allocation().get_width(), get_allocation().get_height() );
		win->invalidate_rect(r, false);
	}
}