def __init__(self): BlockModel.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "Random" self.label = "Random" self.color = "150:150:250:150" self.ports = [{ "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "label": "Float", "conn_type": "Output", "name": "float" }, { "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "label": "Generate", "conn_type": "Input", "name": "generate" }] self.group = "Interface" self.properties = [{ "name": "min", "label": "Min", "type": MOSAICODE_FLOAT, "lower": -20000, "upper": 20000, "step": 1, "value": 1 }, { "name": "max", "label": "Max", "type": MOSAICODE_FLOAT, "lower": -20000, "upper": 20000, "step": 1, "value": 100 }] self.codes["declaration"] = """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.framework = "opencv" self.label = "Save Image" self.color = "0:64:191:220" self.group = "General" self.ports = [{ "type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image", "conn_type": "Input" }] self.properties = [{ "name": "filename", "label": "File Name", "type": MOSAICODE_SAVE_FILE }] #------------------------------------ C/OpenCv Code -------------------------------------- self.codes["declaration"] = \ """ Mat $port[input_image]$; """ self.codes["execution"] = \ """ if(!$port[input_image]$.empty()){ imwrite("$prop[filename]$", $port[input_image]$); } """ self.codes["deallocation"] = \ """ $port[input_image]$.release(); """ # ----------------------------------------------------------------------------------------
def __init__(self): BlockModel.__init__(self) self.language = "c" self.framework = "opencv" self.label = "Histogram Equalization" self.color = "230:0:50:245" self.group = "Filters and Conversions" self.ports = [{"type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Image", "conn_type": "Input"}, {"type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image", "conn_type":"Output"} ] # --------------------------- C/OpenCV Code --------------------------- # self.codes["declaration"] = \ """ Mat $port[input_image]$; Mat $port[output_image]$; """ self.codes["execution"] = \ """ if(!$port[input_image]$.empty()){ equalizeHist($port[input_image]$, $port[output_image]$); } """ self.codes["deallocation"] = \ """ $port[input_image]$.release(); $port[output_image]$.release(); """ # --------------------------------------------------------------------- #
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "sound" self.help = "MIDI IN" self.label = "MIDI_IN" self.color = "205:178:95:150" self.ports = [{ "type": "mosaicode_lib_c_sound.extensions.ports.midi", "name": "output", "conn_type": "Output", "label": "MIDI message" }] self.properties = [{ "name": "device", "label": "Device", "type": MOSAICODE_STRING, "value": "" }] self.group = "MIDI" self.codes["declaration"] = \ """ mscsound_midi_t *$label$_$id$; midi_callback *$port[output]$; int $port[output]$_size = 0; void $label$_$id$_callback(snd_seq_event_t *ev) { for(int i=0 ; i < $port[output]$_size ; i++){ // Call the stored functions (*($port[output]$[i]))((void*)ev); } } """ self.codes["setup"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "sound" self.help = "Microphone" self.label = "Microphone" self.color = "50:150:250:150" self.ports = [{ "type": "mosaicode_lib_c_sound.extensions.ports.sound", "name": "output0", "conn_type": "Output", "label": "Sound Value" }] self.group = "Sound Sources" self.codes["function_declaration"] = "" self.codes["declaration"] = "mscsound_mic_t *$label$_$id$;\n" self.codes["function"] = "" self.codes[ "execution"] = "$label$_$id$->process(&$label$_$id$, &in);\n" self.codes[ "setup"] = "$label$_$id$ = mscsound_create_mic(FRAMES_PER_BUFFER);\n"
def __init__(self): BlockModel.__init__(self) self.language = "c" self.framework = "opencv" self.label = "Invert Image" self.color = "90:5:10:150" self.group = "Experimental" self.ports = [{"type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "input_image", "label": "Input Match Object Image", "conn_type":"Input"}, {"type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "output_image", "label": "Output Image", "conn_type":"Output"} ] # ---------------------------- C/OpenCV Code ------------------------------- self.codes["declaration"] = \ """ Mat $port[input_image]$; Mat $port[output_image]$; """ self.codes["execution"] = \ """ if(!$port[input_image]$.empty()){ flip($port[input_image]$, $port[output_image]$, 1); } """ self.codes["deallocation"] = \ """ $port[input_image]$.release(); $port[output_image]$.release(); """ # --------------------------------------------------------------------------
def __init__(self): BlockModel.__init__(self) self.language = "c" self.framework = "opencv" self.label = "Image File" self.color = "0:213:255:255" self.group = "Image Source" self.ports = [{ "type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "output_image", "conn_type": "Output", "label": "Output Image" }] self.properties = [{ "label": "File Name", "name": "filename", "type": MOSAICODE_OPEN_FILE, "value": "/usr/share/mosaicode/extensions/c-opencv/images/yellow-house.jpg" }] # ---------------------------- C/OpenCv Code ------------------------- self.codes["declaration"] = \ """ Mat $port[output_image]$; """ self.codes["execution"] = \ """ $port[output_image]$ = imread("$prop[filename]$", IMREAD_COLOR); """ self.codes["deallocation"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "UpKeyboard" self.label = "UpKeyboard" self.color = "50:150:250:150" self.group = "Input Device" self.ports = [{"type":"mosaicode_lib_javascript_webaudio.extensions.ports.float", "label":"Float Output", "conn_type":"Output", "name":"float_output"}, {"type":"mosaicode_lib_javascript_webaudio.extensions.ports.char", "label":"Char Output", "conn_type":"Output", "name":"char_output"} ] self.codes["function"] = """ var keyboard_char_output_up = []; var keyboard_float_output_up = []; document.onkeyup = function(evt){ evt = evt || window.event; var value = evt.keyCode || evt.which; for (var i = 0; i < keyboard_float_output_up.length ; i++) for (var j = 0; j < keyboard_float_output_up[i].length ; j++) keyboard_float_output_up[i][j](value); value = String.fromCharCode(value); for (var i = 0; i < keyboard_char_output_up.length ; i++) for (var j = 0; j < keyboard_char_output_up[i].length ; j++) keyboard_char_output_up[i][j](value); }; """ self.codes["declaration"] = """
def __init__(self): BlockModel.__init__(self) # Appearance self.language = "c" self.framework = "opencv" self.help = "Creates a new Point." self.label = "New Point" self.color = "50:50:200:150" self.out_types = ["mosaicode_lib_c_opencv.extensions.ports.point"] self.ports = [{ "type": "mosaicode_lib_c_opencv.extensions.ports.point", "name": "point", "label": "Point", "conn_type": "Output" }] self.group = "Basic Data Type" self.properties = [{ "name": "x", "label": "X", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1, "value": 0 }, { "name": "y", "label": "Y", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1, "value": 0 }] # -------------------C/OpenCv code------------------------------------ self.codes["execution"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "sound" self.help = "VUBar" self.label = "VUBar" self.color = "67:160:17:150" self.ports = [{ "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "input0", "conn_type": "Input", "label": "Float value" }] self.properties = [{ "name": "x", "label": "X", "type": MOSAICODE_INT, "value": "0" }, { "name": "y", "label": "Y", "type": MOSAICODE_INT, "value": "0" }] self.group = "GUI" self.codes["declaration"] = \ """ mscsound_vubar_t *$label$_$id$; void $port[input0]$(float value){ *($label$_$id$->input0) = value; } """ self.codes["execution"] = "$label$_$id$->process(&$label$_$id$);\n" self.codes["setup"] = \ """
def setUp(self): """Do the test basic setup.""" win = MainWindow() diagram = Diagram(win) blockmodel = BlockModel() source = Block(diagram, blockmodel) # NAO TRATA NONE # source = None source_port = 0 conn_type = None self.connector = Connector(diagram, source, source_port, conn_type)
def __init__(self): BlockModel.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "midi to freq" self.label = "Midi 2 Freq" self.color = "250:250:0:150" self.group = "MIDI" self.ports = [{ "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "name": "midi_value", "conn_type": "Input", "label": "Midi Value" }, { "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "label": "Frequency", "conn_type": "Output", "name": "frequency" }] self.codes["declaration"] = """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.framework = "opengl" self.help = "Not to declare" self.label = "Push" self.color = "179:222:252:150" self.group = "Operations" self.ports = [{ "type": "mosaicode_lib_c_opengl.extensions.ports.flow", "label": "Flow", "conn_type": "Input", "name": "flow" }, { "type": "mosaicode_lib_c_opengl.extensions.ports.flow", "label": "Flow", "conn_type": "Output", "name": "flow" }] self.codes["call"] = """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "base" self.help = "Modulus" self.label = "Modulus" self.color = "103:118:54:230" self.ports = [{"type":"mosaicode_lib_c_base.extensions.ports.integer", "name":"input0", "label":"Integer value", "conn_type":"Input"}, {"type":"mosaicode_lib_c_base.extensions.ports.integer", "name":"input1", "label":"Integer value", "conn_type":"Input"}, {"type":"mosaicode_lib_c_base.extensions.ports.integer", "name":"result", "label":"Integer value", "conn_type":"Output"}] self.group = "Arithmetic" self.properties = [{"name": "input0", "label": "Integer value", "type": MOSAICODE_INT, "lower": -(sys.maxint - 1), "upper": sys.maxint, "step": 1, "value": 0}, {"name": "input1", "label": "Integer value", "type": MOSAICODE_INT, "lower": -(sys.maxint - 1), "upper": sys.maxint, "step": 1, "value": 0}] self.codes["declaration"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "Distortion" self.label = "Distortion" self.color = "50:150:250:150" self.ports = [{ "type": "mosaicode_lib_javascript_webaudio.extensions.ports.sound", "label": "Input", "conn_type": "Input", "name": "input" }, { "type": "mosaicode_lib_javascript_webaudio.extensions.ports.sound", "label": "Output", "conn_type": "Output", "name": "output" }] self.properties = [{ "name": "curve", "label": "Curve", "type": MOSAICODE_FLOAT, "value": 800 }] self.group = "Sound" self.codes["declaration"] = ''' var block_$id$ = context.createWaveShaper(); block_$id$.curve = makeDistortionCurve($prop[curve]$); block_$id$.oversample = '4x'; var $port[input]$ = block_$id$; var $port[output]$ = block_$id$; ''' self.codes["function"] = '''
def __init__(self): BlockModel.__init__(self) self.language = "javascript" self.framework = "webaudio" self.help = "Device Orientation" self.label = "Device Orientation" self.color = "50:50:50:150" self.group = "Input Device" self.out_types = [ "mosaicode_lib_javascript_webaudio.extensions.ports.float", "mosaicode_lib_javascript_webaudio.extensions.ports.float", "mosaicode_lib_javascript_webaudio.extensions.ports.float" ] self.ports = [{ "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "conn_type": "Output", "name": "alpha", "label": "Alpha" }, { "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "conn_type": "Output", "name": "beta", "label": "Beta" }, { "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "conn_type": "Output", "name": "gamma", "label": "Gamma" }] self.codes["onload"] = """ window.addEventListener('deviceorientation', handleDeviceOrientation$id$); """ self.codes["declaration"] = """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "base" self.help = "Pow value" self.label = "Pow" self.color = "103:118:54:230" self.ports = [{"type":"mosaicode_lib_c_base.extensions.ports.float", "name":"input0", "label":"Base value", "conn_type":"Input"}, {"type":"mosaicode_lib_c_base.extensions.ports.float", "name":"input1", "label":"Pow value", "conn_type":"Input"}, {"type":"mosaicode_lib_c_base.extensions.ports.float", "name":"result", "label":"Float value", "conn_type":"Output"}] self.group = "Arithmetic" self.properties = [{"name": "input0", "label":"Float value", "type": MOSAICODE_FLOAT, "lower": -(sys.float_info.max - 1), "upper": sys.float_info.max, "step": 1.0, "value": 0.0}, {"name": "input1", "label":"Step value", "type": MOSAICODE_FLOAT, "lower": -(sys.float_info.max -1 ), "upper": sys.float_info.max, "step": 1.0, "value": 1.0}] self.codes["declaration"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.framework = "opengl" self.help = "Not to declare" self.label = "Increment" self.color = "0:0:255:150" self.group = "Math" self.ports = [{ "type": "mosaicode_lib_c_opengl.extensions.ports.float", "label": "Float", "conn_type": "Input", "name": "input" }, { "type": "mosaicode_lib_c_opengl.extensions.ports.float", "label": "Trigger", "conn_type": "Input", "name": "trigger" }, { "type": "mosaicode_lib_c_opengl.extensions.ports.float", "label": "Result", "conn_type": "Output", "name": "result" }] self.properties = [{ "name": "step", "label": "step", "type": MOSAICODE_FLOAT, "lower": 0.01, "upper": 1.0, "step": 0.01, "value": 0.1, "page_inc": 0.1, "page_size": 0.1, }] self.codes["global"] = """
def __init__(self): BlockModel.__init__(self) self.label = "Not" self.color = "255:102:25:245" self.language = "c" self.framework = "opencv" self.ports = [{ "type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "input_image", "conn_type": "Input", "label": "Input Image" }, { "type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "output_image", "conn_type": "Output", "label": "Output Image" }] #-------------------------------- C/OpenCV Code --------------------------------- self.group = "Arithmetic and Logical Operations" self.codes["declaration"] = \ """ Mat $port[input_image]$; Mat $port[output_image]$; """ self.codes["execution"] = \ """ if(!$port[input_image]$.empty()){ bitwise_not($port[input_image]$, $port[output_image]$); } """ self.codes["deallocation"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "base" self.help = "Less than" self.label = "LessThan" self.color = "232:164:38:200" self.ports = [{"type":"mosaicode_lib_c_base.extensions.ports.float", "name":"input0", "label":"Float value", "conn_type":"Input"}, {"type":"mosaicode_lib_c_base.extensions.ports.float", "name":"input1", "label":"Float value", "conn_type":"Input"}, {"type":"mosaicode_lib_c_base.extensions.ports.float", "name":"result", "label":"Float value", "conn_type":"Output"}] self.group = "Arithmetic Operation" self.properties = [{"name": "input0", "label":"Float value", "type": MOSAICODE_FLOAT, "lower": -(sys.float_info.max-1), "upper": sys.float_info.max, "step": 1, "value": 0}, {"name": "input1", "label":"Float value", "type": MOSAICODE_FLOAT, "lower": -(sys.float_info.max-1), "upper": sys.float_info.max, "step": 1, "value": 0}] self.codes["declaration"] = \ """
def __init__(self): BlockModel.__init__(self) self.help = "Cria uma nova imagem." self.label = "New Image" self.color = "50:100:200:150" self.language = "c" self.framework = "opencv" self.ports = [{ "type": "mosaicode_lib_c_opencv.extensions.ports.image", "name": "output_image", "conn_type": "Output", "label": "Output Image" }] self.group = "Image Source" self.properties = [{ "name": "width", "label": "Width", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1, "value": 800 }, { "name": "height", "label": "Height", "type": MOSAICODE_INT, "lower": 0, "upper": 65535, "step": 1, "value": 600 }] self.codes["declaration"] = \ """ Mat $port[output_image]$; """ self.codes["execution"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "sound" self.help = "RMS" self.label = "RMS" self.color = "140:114:114:150" self.ports = [{ "type": "mosaicode_lib_c_sound.extensions.ports.sound", "name": "input0", "conn_type": "Input", "label": "Sound value" }, { "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "output0", "conn_type": "Output", "label": "Float value" }] self.group = "Conversion" self.codes["declaration"] = \ """ typedef void (*$label$_$id$_callback_t)(float value); $label$_$id$_callback_t* $port[output0]$; int $port[output0]$_size = 0; mscsound_rms_t *$label$_$id$; """ self.codes["execution"] = \ """ $label$_$id$->process(&$label$_$id$); for(int i=0 ; i < $port[output0]$_size ; i++){ // Call the stored functions (*($port[output0]$[i]))(*($label$_$id$->output0)); } """ self.codes[ "setup"] = "$label$_$id$ = mscsound_create_rms(FRAMES_PER_BUFFER);\n"
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "base" self.help = "Integer to float" self.label = "IntegerToFloat" self.color = "167:167:143:200" self.ports = [{ "type": "mosaicode_lib_c_base.extensions.ports.integer", "name": "input0", "label": "Integer value", "conn_type": "Input" }, { "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "result", "label": "Float value", "conn_type": "Output" }] self.group = "Conversion" self.codes["declaration"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "base" self.help = "Round value" self.label = "Round" self.color = "103:118:54:230" self.ports = [{ "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "input0", "label": "Float value", "conn_type": "Input" }, { "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "result", "label": "Float value", "conn_type": "Output" }] self.group = "Arithmetic" self.codes["declaration"] = \ """
def test_save(self): # NÃO TRABALHA COM None # block = None # self.assertTrue(self.blockpersistence.save(block)) diagram = Diagram(MainWindow()) block = Block(diagram, None) self.assertTrue(self.blockpersistence.save(block)) diagram = Diagram(MainWindow()) blockmodel = BlockModel(None) block = Block(diagram, blockmodel) block.type = "teste_blockpersistence" self.assertTrue(self.blockpersistence.save(block))
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "sound" self.help = "Frequency Value to Convert MIDI Note" self.label = "Freq_to_MIDI_Note" self.color = "140:114:114:150" self.ports = [{ "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "midi_note", "conn_type": "Output", "label": "MIDI Note value" }, { "type": "mosaicode_lib_c_base.extensions.ports.float", "name": "freq", "conn_type": "Input", "label": "Frequency value" }] self.group = "Conversion" self.codes["declaration"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "c" self.extension = "base" self.help = "Char to string" self.label = "CharToString" self.color = "167:167:143:200" self.ports = [{ "type": "mosaicode_lib_c_base.extensions.ports.char", "name": "input0", "label": "Char value", "conn_type": "Input" }, { "type": "mosaicode_lib_c_base.extensions.ports.string", "name": "result", "label": "String value", "conn_type": "Output" }] self.group = "Conversion" self.codes["declaration"] = \ """
def __init__(self): BlockModel.__init__(self) self.language = "javascript" self.extension = "webaudio" self.help = "Bool to Float" self.label = "Bool 2 Float" self.color = "200:200:25:150" self.ports = [{ "type": "mosaicode_lib_javascript_webaudio.extensions.ports.bool", "label": "Bool Input", "conn_type": "Input", "name": "bool_input" }, { "type": "mosaicode_lib_javascript_webaudio.extensions.ports.float", "label": "Float Output", "conn_type": "Output", "name": "float_output" }] self.properties = [] self.group = "Conversion" self.codes["declaration"] = """
def paste(self): """ This method paste a block. """ if self.diagram is None: return False replace = {} self.diagram.deselect_all() # interact into blocks, add blocks and change their id clipboard = self.diagram.main_window.main_control.get_clipboard() for widget in clipboard: if not isinstance(widget, BlockModel): continue block = BlockModel(widget) block.x += 20 block.y += 20 block.id = -1 new_block = BlockModel(block) new_block = deepcopy(new_block) new_block = Block(self.diagram, new_block) if not self.add_block(new_block): continue replace[widget.id] = new_block new_block.is_selected = True # interact into connections changing block ids for widget in clipboard: if not isinstance(widget, ConnectionModel): continue # if a connector is copied without blocks if widget.output.id not in replace \ or widget.input.id not in replace: continue output_block = replace[widget.output.id] output_port = widget.output_port input_block = replace[widget.input.id] input_port = widget.input_port self.diagram.start_connection(output_block, output_port) self.diagram.curr_connector.is_selected = True self.diagram.end_connection(input_block, input_port) for widget in clipboard: if not isinstance(widget, CommentModel): continue comment = CommentModel(widget) comment.x += 20 comment.y += 20 comment.is_selected = True comment = self.diagram.main_window.main_control.add_comment(comment) self.diagram.update_flows()
def test_delete_connection(self): from mosaicode.GUI.connector import Connector blockmodel = BlockModel() source = Block(self.diagram, blockmodel) # NOTE: NAO TRATA None # source = None source_port = 0 conn_type = None connection = Connector(self.diagram, source, source_port, conn_type) self.assertIsNone(self.diagram.delete_connection(connection))