コード例 #1
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "webaudio"
     self.language = "javascript"
     self.description = "Javascript / webaudio code template"
     self.extension = ".html"
     self.command = "chromium-browser $dir_name$$filename$$extension$\n"
     self.code = r"""<html>
コード例 #2
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "joystick"
     self.language = "c"
     self.description = "A full template to generate joystick code"
     self.extension = ".c"
     self.command = "g++ -std=c++11 -g -Wall -pthread $dir_name$$filename$$extension$ -o $dir_name$$filename$\n"
     self.command += "$dir_name$./$filename$"
     self.code_parts = ["global", "declaration"]
     self.code = r"""
コード例 #3
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "webaudio"
     self.language = "javascript"
     self.description = "Javascript / webaudio code template"
     self.extension = ".html"
     self.command = "python -m webbrowser -t $dir_name$$filename$$extension$\n"
     self.code_parts = [
         "onload", "function", "declaration", "execution", "html"
     ]
     self.code = r"""<html>
コード例 #4
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "opengl"
     self.language = "c"
     self.description = "A full template to generate opengl code"
     self.extension = ".c"
     self.command = "g++ -Wall -g $dir_name$$filename$$extension$ -o $dir_name$$filename$ -lGL -lGLU -lglut -lm\n"
     self.command += "$dir_name$./$filename$"
     self.code_parts = [
         "global", "function", "call", "idle", "declaration", "execution"
     ]
     self.code = r"""
コード例 #5
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "opencv"
        self.language = "c"
        self.description = "c / opencv code template"
        self.extension = '.c'
        self.command = "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/;\n"
        self.command += "export PKG_CONFIG_PATH=/lib/pkgconfig/;\n"
        self.command += "g++ $filename$$extension$  -o $filename$ `pkg-config --cflags --libs opencv`\n"
        self.command += "LD_LIBRARY_PATH=/lib/ $dir_name$./$filename$"

        self.code = r"""
コード例 #6
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "gtk"
     self.language = "c"
     self.description = "A full template to generate gtk code"
     self.extension = ".c"
     self.command = "g++ -o $dir_name$$filename$ $dir_name$$filename$$extension$ `pkg-config --cflags --libs gtk+-3.0`\n"
     self.command += "$dir_name$./$filename$"
     self.code_parts = [
         "destroy", "windows", "function", "declaration", "configuration",
         "show", "struct", "callback"
     ]
     self.code = r"""
コード例 #7
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "opencv"
        self.language = "c"
        self.description = "A full template to generate OpenCV code"
        self.extension = '.c'
        self.command = "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/;\n"
        self.command += "export PKG_CONFIG_PATH=/lib/pkgconfig/;\n"
        self.command += "g++ $filename$$extension$  -o $filename$ `pkg-config --cflags --libs opencv`\n"
        self.command += "LD_LIBRARY_PATH=/lib/ $dir_name$./$filename$"
        self.code_parts = [
            "include", "function", "declaration", "execution", "deallocation"
        ]

        self.code = r"""
コード例 #8
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "opencv"
        self.language = "c"
        self.description = "c / opencv code template"
        self.command = "make run\n"
        self.code_parts = [
            "include", "function", "declaration", "execution", "deallocation"
        ]

        self.files["main.c"] = r"""
        
/*
* Generated by Mosaicode
*	$name$
*	$description$
*	Developed by: $author$
*	Using $license$
*/

#ifdef _CH_
#pragma package <opencv>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"

using namespace cv;
using namespace std;
$single_code[include]$

$single_code[function]$

#define FRAMERATE 1000.0 / 25.0

int main(int argc, char ** argv){
    char key = ' ';
    $code[declaration]$
    while((key = (char)waitKey(FRAMERATE)) != 27){
        $code[execution, connection]$
        $code[deallocation]$
    }

    destroyAllWindows();
    return 0;
}
"""

        self.files["function.c"] = r"""
#include "opencv2/core.hpp"
using namespace cv;
"""

        self.files["Makefile"] = r"""
コード例 #9
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "Mosaicode-Sound"
        self.language = "c"
        self.command = "make && ./main\n"
        self.description = "mosaicode-c-sound"
        self.code_parts = ["declaration", "execution", "setup"]
        self.properties = [{
            "name": "title",
            "label": "Title",
            "value": "Title",
            "type": MOSAICODE_STRING
        }]

        self.files["main.c"] = \
r"""
#include <mosaic-sound.h>
#include <portaudio.h>
#include <alsa/asoundlib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <math.h>

#define NUM_SECONDS 12
#define SAMPLE_RATE 44100
#define FRAMES_PER_BUFFER 256

$code[declaration]$

static int mscsound_callback(const void *inputBuffer, void *outputBuffer,
                             unsigned long framesPerBuffer,
                             const PaStreamCallbackTimeInfo *timeInfo,
                             PaStreamCallbackFlags statusFlags,
                             void *userData) {
  float *in = (float *)inputBuffer;
  float *out = (float *)outputBuffer;

  (void)timeInfo; /* Prevent unused variable warnings. */
  (void)statusFlags;
  (void)userData;
  (void)in;
  (void)out;

  $code[execution]$

  return paContinue;
}

/*
 * This routine is called by mscsound when mscsound_callback is done.
 */
static void mscsound_finished(void *data) { printf("Stream Completed!\n"); }

/*******************************************************************/
int main(int argc, char *argv[]) {
  time_t t;

  /* Intializes random number generator */
  srand((unsigned) time(&t));

  $code[setup]$

  $connections$

  void *stream = mscsound_initialize(SAMPLE_RATE, FRAMES_PER_BUFFER);

  printf("Playing until the Enter key is pressed.\n");
  getchar();

  mscsound_terminate(stream);

  return 0;
}
"""

        self.files["Makefile"] = \
r"""CC := gcc
コード例 #10
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "gtk"
        self.language = "c"
        self.description = "A full template to generate gtk code"
        self.command = "make && $dir_name$./main\n"
        self.code_parts = ["declaration", "setup"]
        self.properties = [{"name": "title",
                            "label": "Title",
                            "value": "Title",
                            "type": MOSAICODE_STRING
                            },
                            {"name": "border",
                            "label": "Border",
                            "value": 50,
                            "type": MOSAICODE_INT
                            },
                            {"name": "width",
                            "label": "Width",
                            "value": 800,
                            "type": MOSAICODE_INT
                            },
                            {"name": "height",
                            "label": "Height",
                            "value": 600,
                            "type": MOSAICODE_INT
                            }
                           ]

        self.files["callback.h"] = r"""
typedef void (*string_callback)(const char * value);
typedef void (*float_callback)(float value);
typedef void (*int_callback)(int value);
typedef void (*char_callback)(char value);
"""

        self.files["main.c"] = r"""
#include <gtk/gtk.h>
#include <limits.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "callback.h"

GtkWidget * window;
GtkWidget * fixed_layout;
$code[declaration]$

void destroy(void){
    gtk_main_quit ();
}

int main(int argc, char *argv[]){
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "$prop[title]$");
    g_signal_connect(window, "destroy",G_CALLBACK(destroy), NULL);
    gtk_window_resize(GTK_WINDOW(window), $prop[width]$, $prop[height]$);
    gtk_container_set_border_width(GTK_CONTAINER(window), $prop[border]$);

    fixed_layout = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed_layout);


    $code[setup]$
    $connections$

    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}
"""

        self.files["Makefile"] = \
r"""CC := gcc
コード例 #11
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "webaudio"
        self.language = "javascript"
        self.command = "python -m webbrowser -t $dir_name$index.html\n"
        self.description = "Javascript / webaudio code template"

        self.code_parts = [
            "onload", "function", "declaration", "execution", "html"
        ]
        self.properties = [{
            "name": "title",
            "label": "Title",
            "value": "Title",
            "type": MOSAICODE_STRING
        }]

        self.files["index.html"] = r"""
<html>
    <head>
        <meta http-equiv="Cache-Control" content="no-store" />
        <!-- $author$ $license$ -->
        <title>$prop[title]$</title>
        <link rel="stylesheet" type="text/css" href="theme.css">
        <script src="functions.js"></script>
        <script>
        $single_code[function]$
        function loadme(){
        $single_code[onload]$
        return;
        }
        var context = new (window.AudioContext || window.webkitAudioContext)();
        //declaration block
        $code[declaration]$

        //execution
        $code[execution]$

        //connections
        $connections$
        </script>
    </head>

    <body onload='loadme();'>
        $code[html]$
    </body>
</html>
"""

        self.files["theme.css"] = r"""
/*
Developed by: $author$
*/
html, body {
  background: #ffeead;
  color: #ff6f69;
}
h1, p {
  color: #ff6f69;
}
#navbar a {
  color: #ff6f69;
}
.item {
  background: #ffcc5c;
}
button {
  background: #ff6f69;
  color: #ffcc5c;
}
"""

        self.files["functions.js"] = r"""
コード例 #12
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "Mosaicode-Sound-Gtk"
        self.language = "c"
        self.command = "make && ./main\n"
        self.description = "mosaicode-c-sound-gtk"
        self.code_parts = ["declaration", "execution", "setup", "function"]
        self.properties = [{
            "name": "sample_rate",
            "label": "Sample Rate",
            "value": "44100",
            "type": MOSAICODE_INT
        }, {
            "name": "frame_per_buffer",
            "label": "Frames Per Buffer",
            "value": "256",
            "type": MOSAICODE_INT
        }, {
            "name": "title",
            "label": "Title",
            "value": "Title",
            "type": MOSAICODE_STRING
        }, {
            "name": "width",
            "label": "Width",
            "value": 800,
            "type": MOSAICODE_INT
        }, {
            "name": "height",
            "label": "Height",
            "value": 600,
            "type": MOSAICODE_INT
        }]

        self.files["main.c"] = \
r"""
#include <mosaic-sound.h>
#include <portaudio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>

#define NUM_SECONDS 12
#define SAMPLE_RATE 44100
#define FRAMES_PER_BUFFER 256

GtkWidget *window;
GtkWidget *vbox;
$code[declaration]$

void destroy(void){
   gtk_main_quit ();
}

static int mscsound_callback(const void *inputBuffer, void *outputBuffer,
                             unsigned long framesPerBuffer,
                             const PaStreamCallbackTimeInfo *timeInfo,
                             PaStreamCallbackFlags statusFlags,
                             void *userData) {
  float *in = (float *)inputBuffer;
  float *out = (float *)outputBuffer;

  (void)timeInfo; /* Prevent unused variable warnings. */
  (void)statusFlags;
  (void)userData;
  (void)in;

  $code[execution]$

  return paContinue;
}

/*
 * This routine is called by mscsound when mscsound_callback is done.
 */
static void mscsound_finished(void *data) { printf("Stream Completed!\n"); }

/*******************************************************************/
int main(int argc, char *argv[]) {
   gtk_init(&argc, &argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title(GTK_WINDOW(window), "$prop[title]$");
   g_signal_connect(window, "destroy",G_CALLBACK(destroy), NULL);
   gtk_window_resize(GTK_WINDOW(window), $prop[width]$, $prop[height]$);

   vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL,3);
   gtk_container_add(GTK_CONTAINER(window), vbox);

   $code[setup]$
   $connections$

  void *stream = mscsound_inicialize(SAMPLE_RATE, FRAMES_PER_BUFFER);

   gtk_widget_show_all(window);
   gtk_main();

  mscsound_terminate(stream);

  return 0;
}
"""

        self.files["Makefile"] = \
r"""CC := gcc