Exemplo n.º 1
0
void DimensionManager::onColumnClicked() {
    printf("DimensionManager::onColumnClicked()\n");

    //FIXME: BUG: this method is currently very unreliably called, it should actually be called when the user selects another column, it is ATM however also called when the table content changed programmatically causing the dialog below to popup at undesired times !

    //HACK: Prevents that onColumnClicked() gets called multiple times or at times where it is not desired
    if (ignoreColumnClicked) {
        ignoreColumnClicked = false;
        return;
    }
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 18) || GTKMM_MAJOR_VERSION > 2
    // prevents app to crash if this dialog is closed
    if (!get_visible())
        return;
#else
# warning Your GTKMM version is too old; dimension manager dialog might crash when changing a dimension type !
#endif

#if (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 3
    if (!is_visible()) return;
#endif

    Gtk::TreeModel::Path path;
    Gtk::TreeViewColumn* focus_column;
    treeView.get_cursor(path, focus_column);
    //const int row = path[0];
    if (focus_column == treeView.get_column(0)) {
        Gtk::TreeModel::iterator it = treeView.get_model()->get_iter(path);
        if (!it) return;
        Gtk::TreeModel::Row row = *it;
        gig::dimension_t oldType = row[tableModel.m_type];

        Gtk::Dialog dialog(_("Change Dimension"), true /*modal*/);
        int oldTypeIndex = -1;
        Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(comboModel);
        for (int i = 0x01, count = 0; i < 0xff; i++) {
            Glib::ustring sType =
                dimTypeAsString(static_cast<gig::dimension_t>(i));
            if (i == oldType) oldTypeIndex = count;
            if (sType.find("Unknown") != 0) {
                Gtk::TreeModel::Row row = *(refComboModel->append());
                row[comboModel.m_type_id]   = i;
                row[comboModel.m_type_name] = sType;
                count++;
            }
        }
        Gtk::Table table(1, 2);
        Gtk::Label labelDimType(_("Dimension:"), Gtk::ALIGN_START);
        Gtk::ComboBox comboDimType;
        comboDimType.set_model(refComboModel);
        comboDimType.pack_start(comboModel.m_type_id);
        comboDimType.pack_start(comboModel.m_type_name);
        table.attach(labelDimType, 0, 1, 0, 1);
        table.attach(comboDimType, 1, 2, 0, 1);
        dialog.get_vbox()->pack_start(table);

        dialog.add_button(_("_OK"), 0);
        dialog.add_button(_("_Cancel"), 1);
        dialog.show_all_children();
        
        comboDimType.set_active(oldTypeIndex);

        if (!dialog.run()) { // OK selected ...
            ignoreColumnClicked = true;
            Gtk::TreeModel::iterator iterType = comboDimType.get_active();
            if (!iterType) return;
            Gtk::TreeModel::Row rowType = *iterType;
            if (!rowType) return;
            int iTypeID = rowType[comboModel.m_type_id];
            gig::dimension_t newType = static_cast<gig::dimension_t>(iTypeID);
            if (newType == oldType) return;
            //printf("change 0x%x -> 0x%x\n", oldType, newType);

            // assemble the list of regions where the selected dimension type
            // shall be changed
            std::vector<gig::Region*> vRegions;
            if (allRegions()) {
                gig::Instrument* instr = (gig::Instrument*)region->GetParent();
                for (gig::Region* rgn = instr->GetFirstRegion(); rgn; rgn = instr->GetNextRegion()) {
                    if (rgn->GetDimensionDefinition(oldType)) vRegions.push_back(rgn);
                }
            } else vRegions.push_back(region);

            std::set<Glib::ustring> errors;

            for (uint iRgn = 0; iRgn < vRegions.size(); ++iRgn) {
                gig::Region* region = vRegions[iRgn];
                try {
                    // notify everybody that we're going to update the region
                    region_to_be_changed_signal.emit(region);
                    // change the dimension type on that region
                    region->SetDimensionType(oldType, newType);
                    // let everybody know there was a change
                    region_changed_signal.emit(region);
                } catch (RIFF::Exception e) {
                    // notify that the changes are over (i.e. to avoid dead locks)
                    region_changed_signal.emit(region);
                    Glib::ustring txt = _("Could not alter dimension: ") + e.Message;
                    if (vRegions.size() == 1) {
                        // show error message directly
                        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
                        msg.run();
                    } else {
                        // remember error, they are shown after all regions have been processed
                        errors.insert(txt);
                    }
                }
            }
            // update all GUI elements
            refreshManager();

            if (!errors.empty()) {
                Glib::ustring txt = _(
                    "The following errors occurred while trying to change the dimension type on all regions:"
                );
                txt += "\n\n";
                for (std::set<Glib::ustring>::const_iterator it = errors.begin();
                    it != errors.end(); ++it)
                {
                    txt += "-> " + *it + "\n";
                }
                txt += "\n";
                txt += _(
                    "You might also want to check the console for further warnings and "
                    "error messages."
                );
                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
                msg.run();
            }
        }
    }
}
Exemplo n.º 2
0
void uv_container::mouse_move_rel(int rel_x, int rel_y)
{
    if(get_visible()) mouse_move_rel_childs(rel_x, rel_y);
}
Exemplo n.º 3
0
	void print_rbm(rbm* r) {

	  std::cout << "Rbm with " << r->nv << " visible and "
				<< r->nh << " hidden units." << std::endl;

	  // visible units
	  std::cout << "visible units:" << std::endl;
	  for (unsigned int i=0; i<r->nv; i++) {

		std::cout << get_visible(r, i);
		if (i != 0 && i % 8 == 0) {
		  std::cout << std::endl;
		}
		else {
		  std::cout << " ";
		}
	  }
	  std::cout << std::endl;

	  // hidden units
	  std::cout << "Hidden units:" << std::endl;
	  for (unsigned int j=0; j<r->nh; j++) {

		std::cout << get_hidden(r, j);
		if (j != 0 && j % 8 == 0) {
		  std::cout << std::endl;
		}
		else {
		  std::cout << " ";
		}
	  }
	  std::cout << std::endl;

	  // weights
	  std::cout << "Weights:" << std::endl;
	  for (unsigned int i=0; i<r->nv; i++) {

		for(unsigned int j=0; j<r->nh; j++) {
			std::cout << get_weight(r, i, j);
			if ((i + j) != 0 && (i + j) % 8 == 0) {
			  std::cout << std::endl;
			}
			else {
			  std::cout << " ";
			}
		 }
	  }
	  std::cout << std::endl;

	  //biases
	  std::cout << "Bias weights visible:" << std::endl;
	  for (unsigned int i=0; i<r->nv; i++) {

		std::cout << get_weight_visible_bias(r, i);
		if (i != 0 && i % 8 == 0) {
		  std::cout << std::endl;
		}
		else {
		  std::cout << " ";
		}
	  }
	  std::cout << std::endl;
	  std::cout << "Bias weights hidden:" << std::endl;
	  for (unsigned int j=0; j<r->nh; j++) {

		std::cout << get_weight_hidden_bias(r, j);
		if (j != 0 && j % 8 == 0) {
		  std::cout << std::endl;
		}
		else {
		  std::cout << " ";
		}
	  }
	  std::cout << std::endl;
	}
Exemplo n.º 4
0
//---------------------------------------------------------------------------
void uv_container::draw(vector<GLuint> * clist)
{
   if(get_visible()) draw_childs(clist);
}
Exemplo n.º 5
0
bool uv_container::key_action(int key, int sym, int mod, int what)
{
   if(get_visible()) key_action_childs(key, sym, mod, what);
}
Exemplo n.º 6
0
		TITANIUM_PROPERTY_GETTER(Animation, visible)
		{
			return get_context().CreateBoolean(get_visible());
		}
Exemplo n.º 7
0
bool tcontrol::disable_click_dismiss() const
{
	return get_visible() == twidget::tvisible::visible && get_active();
}
Exemplo n.º 8
0
bool styled_widget::disable_click_dismiss() const
{
	return get_visible() == widget::visibility::visible && get_active();
}
Exemplo n.º 9
0
void RenderPreview::initialisePreview()
{
#if 0
#ifdef WIN32
    // greebo: Unfortunate hack to fix the grey GL renderviews in the EntityChooser
    // and other windows that are hidden instead of destroyed when closed.
    Gtk::Container* container = get_parent();
    bool wasShown = get_visible();

    if (container != NULL)
    {
        if (wasShown)
        {
            hide();
        }

        container->remove(*this);
        container->add(*this);

        if (wasShown)
        {
            show();
        }
    }

#endif
#endif
	// Grab the GL widget with sentry object
	wxPaintDC dc(_glWidget);
	_glWidget->SetCurrent(GlobalOpenGL().getwxGLContext());
	
    // Set up the camera
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(PREVIEW_FOV, 1, 0.1, 10000);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Set up the lights
    glEnable(GL_LIGHTING);

    glEnable(GL_LIGHT0);
    GLfloat l0Amb[] = { 0.3f, 0.3f, 0.3f, 1.0f };
    GLfloat l0Dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    GLfloat l0Pos[] = { 1.0f, 1.0f, 1.0f, 0.0f };
    glLightfv(GL_LIGHT0, GL_AMBIENT, l0Amb);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, l0Dif);
    glLightfv(GL_LIGHT0, GL_POSITION, l0Pos);

    glEnable(GL_LIGHT1);
    GLfloat l1Dif[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat l1Pos[] = { 0.0, 0.0, 1.0, 0.0 };
    glLightfv(GL_LIGHT1, GL_DIFFUSE, l1Dif);
    glLightfv(GL_LIGHT1, GL_POSITION, l1Pos);

    if (_renderSystem->shaderProgramsAvailable())
    {
        _renderSystem->setShaderProgram(
            RenderSystem::SHADER_PROGRAM_INTERACTION
        );
    }
}
Exemplo n.º 10
0
void train_crbm(dataset_blas *train_set, int nvisible, int nhidden, int nlabel,
               int epoch, double lr,
               int minibatch, double momentum, char *model_file){
    crbm m;
    int i, j, k;
    int nepoch;
    double *v1, *y1;
    uint8_t *l;
    int batch_size, niter;
    int wc;
    int err;
    double lik;
    double delta;
    int *idx;
    time_t start_t, end_t;

    init_crbm(&m, nvisible, nhidden, nlabel);

    //wc = (int)cblas_dasum(train_set->N * train_set->n_feature, train_set->input, 1);
    niter = (train_set->N-1)/minibatch + 1;
    delta = lr / (1.0*minibatch);
    /*
     * shuffle training data
    v1 = (double*)malloc(minibatch * m.nvisible * sizeof(double));
    y1 = (double*)malloc(minibatch * m.ncat * sizeof(double));
    l = (uint8_t*)malloc(minibatch * sizeof(uint8_t));
    idx = (int*)malloc(train_set->N * sizeof(int));
    for(i = 0; i < train_set->N; i++)
        idx[i] = i;*/
    bzero(w_u, sizeof(w_u));
    bzero(u_u, sizeof(u_u));
    bzero(bh_u, sizeof(bh_u));
    bzero(bv_u, sizeof(bv_u));
    bzero(by_u, sizeof(by_u));

    //shuffle(idx, train_set->N);
    
    for(nepoch = 0; nepoch < epoch; nepoch++){
        
        lik = 0;
        err = 0;
        start_t = time(NULL);

        for(k = 0; k < niter; k++){
#ifdef DEBUG
            if((k+1) % 200 == 0){
                printf("batch %d\n", k+1);
            }
#endif
            if(k == niter - 1){
                batch_size = train_set->N - minibatch * (niter-1);
            }else{
                batch_size = minibatch;
            }

            v1 = train_set->input + train_set->n_feature * minibatch * k;
            y1 = train_set->label + train_set->nlabel * minibatch * k;
            l = train_set->output + minibatch * k;
            /*
             * shuffle training data
            for(i = 0; i < batch_size; i++){
                cblas_dcopy(m.nvisible, train_set->input + m.nvisible * idx[k*minibatch+i],
                            1, v1 + m.nvisible * i, 1);
                cblas_dcopy(m.ncat, train_set->label + m.ncat * idx[k*minibatch+i],
                            1, y1 + m.ncat * i, 1);
                l[i] = train_set->output[idx[k*minibatch+i]];
            }*/
            get_hidden(&m, v1, y1, ph1, batch_size);            
            sample_hidden(&m, ph1, h1, batch_size);

            get_visible(&m, h1, pv, batch_size);
            sample_visible(&m, pv, v2, batch_size);

            get_class(&m, h1, py, batch_size);
            sample_class(&m, py, y2, batch_size);

            get_hidden(&m, v2, y2, ph2, batch_size);
            sample_hidden(&m, ph2, h2, batch_size);
            
            //lik += get_likelihood(&m, v1, pv, batch_size);
            err += get_error(&m, y2, l, batch_size);
            
            //update w_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.nvisible, batch_size,
                        1.0, ph2, m.nhidden, v2, m.nvisible,
                        0, a, m.nvisible);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.nvisible, batch_size,
                        1.0, ph1, m.nhidden, v1, m.nvisible,
                        -1, a, m.nvisible);
            cblas_daxpy(m.nvisible * m.nhidden, momentum, w_u, 1,
                        a, 1);
            cblas_dcopy(m.nvisible * m.nhidden, a, 1, w_u, 1);

            //update u_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.ncat, batch_size,
                        1.0, ph2, m.nhidden, y2, m.ncat,
                        0, a, m.ncat);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, m.ncat, batch_size,
                        1.0, ph1, m.nhidden, y1, m.ncat,
                        -1, a, m.ncat);
            cblas_daxpy(m.ncat * m.nhidden, momentum, u_u, 1,
                        a, 1);
            cblas_dcopy(m.ncat * m.nhidden, a, 1, u_u, 1);

            //update bv_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nvisible, 1, batch_size,
                        1.0, v2, m.nvisible, I, 1,
                        0, a, 1);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nvisible, 1, batch_size,
                        1.0, v1, m.nvisible, I, 1,
                        -1, a, 1);
            cblas_daxpy(m.nvisible, momentum, bv_u, 1,
                        a, 1);
            cblas_dcopy(m.nvisible, a, 1, bv_u, 1);

            //update by_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.ncat, 1, batch_size,
                        1.0, y2, m.ncat, I, 1,
                        0, a, 1);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.ncat, 1, batch_size,
                        1.0, y1, m.ncat, I, 1,
                        -1, a, 1);
            cblas_daxpy(m.ncat, momentum, by_u, 1,
                        a, 1);
            cblas_dcopy(m.ncat, a, 1, by_u, 1);

            //update bh_u
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, 1, batch_size,
                        1.0, ph2, m.nhidden, I, 1,
                        0, a, 1);
            cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
                        m.nhidden, 1, batch_size,
                        1.0, ph1, m.nhidden, I, 1,
                        -1, a, 1);
            cblas_daxpy(m.nhidden, momentum, bh_u, 1,
                        a, 1);
            cblas_dcopy(m.nhidden, a, 1, bh_u, 1);

            //change parameter
            cblas_daxpy(m.nvisible * m.nhidden, delta, w_u, 1,
                        m.w, 1);
            cblas_daxpy(m.ncat * m.nhidden, delta, u_u, 1,
                        m.u, 1);
            cblas_daxpy(m.nvisible, delta, bv_u, 1,
                        m.bv, 1);
            cblas_daxpy(m.ncat, delta, by_u, 1,
                        m.by, 1);
            cblas_daxpy(m.nhidden, delta, bh_u, 1,
                        m.bh, 1);
        }
        end_t = time(NULL);

        printf("[epoch %d] error:%.5lf%%\ttime:%.2fmin\n", nepoch + 1, 
               err * 100.0 / train_set->N, (end_t - start_t) / 60.0);
    }
    dump_model(&m, model_file);
    //print_prob(&m, train_set, "../data/rsm/test.prob");

    /*
     * shuffle training data
    free(v1);
    free(y1);
    free(l);*/
    free_crbm(&m);
}
Exemplo n.º 11
0
			inline bool get_is_visible() const
			{
				return get_visible() && get_parent_is_visible();
			}
Exemplo n.º 12
0
void ComboBox::draw()
{
    combo_box->SetHidden(!get_visible());
    combo_box->SetPos(x - frame->off_x, y - frame->off_y);
    combo_box->SetWidth(width);
}