Migrating from C to C++ (5)

IC-7410try

The colored boxes are the areas for waveform (mono) and waterfall of IC7410, and waveform (I and Q) and waterfall of Soft66LC4.

NewSound *mynewsound[2];
vector<NewSound*> newusblist;

int main(int argc, char *argv[])
{
	mynewsound[0] = new SoundIC7410{argv[1]};	/* IC-7410 */
	mynewsound[1] = new SoundSoft66{argv[2]};	/* Soft66LC4 */
	for(int i=0;i<2;i++) {
		newusblist.push_back(mynewsound[i]);
	}

	argc = 1;			/* just for the next line */
	Glib::RefPtr < Gtk::Application > app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

	Gtk::Window mywindow;
	Gtk::VBox   mybox;
	MyDrawingArea *aaa;

	mywindow.set_title("IC-7410 Rig Control Program (C++ version)");
	for(auto x : newusblist) {
		aaa = new MyDrawingArea(x);
		mybox.pack_start(*aaa, FALSE, FALSE, 0);
	}
	mywindow.add(mybox);
	mywindow.show_all();
	return app->run(mywindow);
}
class NewSound : public Gtk::Box {
public:
	virtual int waveform_nsamples () const = 0;
	virtual int waveform_nchannels() const = 0;
	virtual int waterfall_nfft    () const = 0;
	virtual int waterfall_ntime   () const = 0;
	virtual ~NewSound();
};

struct AlsaParams { // Advanced Linux Sound Architecture
	// ...
};

class SoundIC7410 : public NewSound, protected AlsaParams {
public:
	SoundIC7410();
	SoundIC7410(char *s);
	virtual ~SoundIC7410();
	int waveform_nsamples () const override {return  800;};
	int waveform_nchannels() const override {return    1;};
	int waterfall_nfft    () const override {return  512;};
	int waterfall_ntime   () const override {return  256;};
	// ...
public:
	char* sound_device = nullptr;
	// ...
};

class SoundSoft66 : public NewSound, protected AlsaParams {
public:
	SoundSoft66();
	SoundSoft66(char *s);
	virtual ~SoundSoft66();
	int waveform_nsamples () const override {return  600;};
	int waveform_nchannels() const override {return    2;};
	int waterfall_nfft    () const override {return  400;};
	int waterfall_ntime   () const override {return  300;};
	// ...
private:
	char* sound_device = nullptr;
	// ...
};
class MyDrawingArea : public Gtk::DrawingArea {
public:
	MyDrawingArea();
	MyDrawingArea(NewSound*);
	virtual ~MyDrawingArea();
	bool on_draw(const Cairo::RefPtr < Cairo::Context > &cr) override;
private:
	int count     {0};
	int nchannels {0};
	int nsamples  {0};
	int nfft      {0};
	int ntime     {0};
};
MyDrawingArea::MyDrawingArea(NewSound *x) : count {0} {
	nsamples  = x->waveform_nsamples ();
	nchannels = x->waveform_nchannels();
	nfft      = x->waterfall_nfft    ();
	ntime     = x->waterfall_ntime   ();

	set_size_request(max(nsamples, nfft), 100*nchannels + ntime + 30);
}

MyDrawingArea::~MyDrawingArea() {
	// TODO Auto-generated destructor stub
}

bool MyDrawingArea::on_draw(const Cairo::RefPtr<Cairo::Context> &cr) {
	cr->save();
		for(int iy=0;iy<nchannels;iy++) {
			cr->set_source_rgba(0.1*nchannels, 0.5*iy, 0.5, 1.0);
			cr->rectangle( 10, 10+100*iy,  nsamples - 20,  80);
			cr->fill();
			cr->stroke();
		}
	cr->restore();

	cr->save();
			cr->set_source_rgba(0.4, 0.1*(n%10), 0.5, 1.0);
			cr->rectangle(10, 10+100*nchannels, nfft, ntime);
			cr->fill();
			cr->stroke();
	cr->restore();

	return true;
}

I am not sure if I am going to the right direction or not.

Leave a Reply

Your email address will not be published. Required fields are marked *