[gnome-devel-docs: 18/19] Ran through Guitar Tuner demos



commit d6d64deca45654a7f9e8392db6523c1876414c5f
Author: P. F. Chimento <philip chimento gmail com>
Date:   Mon Mar 21 22:52:52 2011 +0100

    Ran through Guitar Tuner demos
    
    I ran through all the Guitar Tuner demos (except Python so far) and
    followed all the instructions to create them in Anjuta. Changed the
    names of GUI elements where necessary so that they corresponded to the
    buttons you see in Anjuta. Some code tweaks were necessary too.

 platform-demos/C/guitar-tuner.c.page            |    6 +++---
 platform-demos/C/guitar-tuner.cpp.page          |    8 ++++----
 platform-demos/C/guitar-tuner.py.page           |    8 ++++----
 platform-demos/C/guitar-tuner.vala.page         |    7 ++++---
 platform-demos/C/guitar-tuner/guitar-tuner.cc   |   21 +++++++++------------
 platform-demos/C/guitar-tuner/guitar-tuner.vala |    3 +--
 6 files changed, 25 insertions(+), 28 deletions(-)
---
diff --git a/platform-demos/C/guitar-tuner.c.page b/platform-demos/C/guitar-tuner.c.page
index c74a0e6..f0444bb 100644
--- a/platform-demos/C/guitar-tuner.c.page
+++ b/platform-demos/C/guitar-tuner.c.page
@@ -51,7 +51,7 @@
        <em>gstreamer-0.10</em> from the list to include the GStreamer library in your project.</p>
     </item>
     <item>
-    <p>Click <gui>Finished</gui> and the project will be created for you. Open <file>src/main.c</file> from the <gui>Project</gui> or <gui>File</gui> tabs. You should see some code which starts with the lines:</p>
+    <p>Click <gui>Apply</gui> and the project will be created for you. Open <file>src/main.c</file> from the <gui>Project</gui> or <gui>File</gui> tabs. You should see some code which starts with the lines:</p>
     <code mime="text/x-csrc"><![CDATA[
 #include <config.h>
 #include <gtk/gtk.h>]]></code>
@@ -80,7 +80,7 @@
   </list>
 
   <p>This code is ready to be used, so you can compile it by clicking <guiseq><gui>Build</gui><gui>Build Project</gui></guiseq> (or press <keyseq><key>Shift</key><key>F7</key></keyseq>).</p>
-  <p>Press <gui>Configure</gui> on the next window that appears to configure a debug build. You only need to do this once, for the first build.</p>
+  <p>Press <gui>Execute</gui> on the next window that appears to configure a debug build. You only need to do this once, for the first build.</p>
 </section>
 
 <section>
@@ -247,7 +247,7 @@ void on_button_clicked (GtkButton* button,
 
 <section>
   <title>Build and run the application</title>
-  <p>All of the code should now be ready to go. Click <guiseq><gui>Build</gui><gui>Build Project</gui></guiseq> to build everything again, and then <guiseq><gui>Run</gui><gui>Run</gui></guiseq> to start the application.</p>
+  <p>All of the code should now be ready to go. Click <guiseq><gui>Build</gui><gui>Build Project</gui></guiseq> to build everything again, and then <guiseq><gui>Run</gui><gui>Execute</gui></guiseq> to start the application.</p>
   <p>If you haven't already done so, choose the <file>Debug/src/guitar-tuner</file> application in the dialog that appears. Finally, hit <gui>Run</gui> and enjoy!</p>
 </section>
 
diff --git a/platform-demos/C/guitar-tuner.cpp.page b/platform-demos/C/guitar-tuner.cpp.page
index ba450e4..dbba18f 100644
--- a/platform-demos/C/guitar-tuner.cpp.page
+++ b/platform-demos/C/guitar-tuner.cpp.page
@@ -44,7 +44,7 @@
     <p>Start Anjuta and click <guiseq><gui>File</gui><gui>New</gui><gui>Project</gui></guiseq> to open the project wizard.</p>
     </item>
     <item>
-    <p>Choose <gui>Gtkmm (Simple)</gui> from the <gui>C++</gui> tab, click <gui>Forward</gui>, and fill out your details on the next few pages. Use <file>guitar-tuner</file> as project name and directory.</p>
+    <p>Choose <gui>GTKmm (Simple)</gui> from the <gui>C++</gui> tab, click <gui>Forward</gui>, and fill out your details on the next few pages. Use <file>guitar-tuner</file> as project name and directory.</p>
    	</item>
     <item>
     <p>Make sure that <gui>Configure external packages</gui> is selected. On the next page, select
@@ -76,7 +76,7 @@
   </list>
 
   <p>This code is ready to be used, so you can compile it by clicking <guiseq><gui>Build</gui><gui>Build Project</gui></guiseq> (or press <keyseq><key>Shift</key><key>F7</key></keyseq>).</p>
-  <p>Press <gui>Configure</gui> on the next window that appears to configure a debug build. You only need to do this once, for the first build.</p>
+  <p>Press <gui>Execute</gui> on the next window that appears to configure a debug build. You only need to do this once, for the first build.</p>
 </section>
 
 <section>
@@ -173,7 +173,7 @@ bool Sound::stop_playing()
 	m_pipeline->set_state(Gst::STATE_NULL);
 	return false;
 }
-  ]]></code>
+]]></code>
  
   <p>The code has the following purpose:</p>  
   <steps>
@@ -208,7 +208,7 @@ on_button_clicked(double frequency, Sound* sound)
 {
 	sound->start_playing (frequency);
 }
-  ]]></code>
+]]></code>
   <p>It only calls the helper class we defined before to play the correct frequencies. With some more
   clever code we would also have been able to directly connect to the class without using the function
   but we will leave that to use as an exercise.</p>
diff --git a/platform-demos/C/guitar-tuner.py.page b/platform-demos/C/guitar-tuner.py.page
index c96e178..64d8884 100644
--- a/platform-demos/C/guitar-tuner.py.page
+++ b/platform-demos/C/guitar-tuner.py.page
@@ -44,10 +44,10 @@
     <p>Start Anjuta and click <guiseq><gui>File</gui><gui>New</gui><gui>Project</gui></guiseq> to open the project wizard.</p>
     </item>
     <item>
-    <p>Choose <gui>Gtk+ (Simple)</gui> from the <gui>Python</gui> tab, click <gui>Forward</gui>, and fill out your details on the next few pages. Use <file>guitar-tuner</file> as project name and directory.</p>
+    <p>Choose <gui>PyGTK (automake)</gui> from the <gui>Python</gui> tab, click <gui>Forward</gui>, and fill out your details on the next few pages. Use <file>guitar-tuner</file> as project name and directory.</p>
    	</item>
     <item>
-    <p>Click <gui>Finished</gui> and the project will be created for you. Open <file>src/guitar_tuner.py</file> from the <gui>Project</gui> or <gui>File</gui> tabs. You should see some code which starts with the lines:</p>
+    <p>Click <gui>Apply</gui> and the project will be created for you. Open <file>src/guitar_tuner.py</file> from the <gui>Project</gui> or <gui>File</gui> tabs. You should see some code which starts with the lines:</p>
     <code mime="test/x-python"><![CDATA[
 from gi.repository import Gtk, GdkPixbuf, Gdk
 import os, sys]]></code>
@@ -65,7 +65,7 @@ import os, sys]]></code>
 libraries needed.</p>
    </item>
    <item>
-    <p>A class is declared that will be the main class for our application. In the <code>__init()</code> method
+    <p>A class is declared that will be the main class for our application. In the <code>__init__</code> method
 	the main window is loaded from the GtkBuilder file (<file>src/guitar-tuner.ui</file>) and the
 	signals are connected.</p>
     <p>Connecting signals is how you define what happens when you push a button, or when some other event happens. Here, the <code>destroy</code> method is called (and quits the app) when you close the window.</p>
@@ -76,7 +76,7 @@ libraries needed.</p>
    </item>
   </list>
 
-  <p>This code is ready to be used, so you can run it by clicking <guiseq><gui>Run</gui><gui>Run</gui></guiseq>.</p>
+  <p>This code is ready to be used, so you can run it by clicking <guiseq><gui>Run</gui><gui>Execute</gui></guiseq>.</p>
 </section>
 
 <section>
diff --git a/platform-demos/C/guitar-tuner.vala.page b/platform-demos/C/guitar-tuner.vala.page
index b0d96ba..0498e1b 100644
--- a/platform-demos/C/guitar-tuner.vala.page
+++ b/platform-demos/C/guitar-tuner.vala.page
@@ -77,7 +77,7 @@ using Gtk;]]></code>
   </list>
 
   <p>This code is ready to be used, so you can compile it by clicking <guiseq><gui>Build</gui><gui>Build Project</gui></guiseq> (or press <keyseq><key>Shift</key><key>F7</key></keyseq>).</p>
-  <p>Change the <gui>Configuration</gui> to <gui>Default</gui> and then press <gui>Configure</gui> configure the build directory. You only need to do this once, for the first build.</p>
+  <p>Change the <gui>Configuration</gui> to <gui>Default</gui> and then press <gui>Execute</gui> to configure the build directory. You only need to do this once, for the first build.</p>
 </section>
 
 <section>
@@ -140,7 +140,9 @@ that needs special treating while linking in order to be found at runtime.</p>
   <title>Set up the pipeline</title>
   <p>In this simple example we will use a tone generator source called <code>audiotestsrc</code> and send the output to the default system sound device, <code>autoaudiosink</code>. We only need to configure the frequency of the tone generator; this is accessible through the <code>freq</code> property of <code>audiotestsrc</code>.</p>
   
-  <p>Insert the following line into <file>guitar_tuner.vala</file> inside our <code>Main</code> class:</p>
+  <p>We need to add a line to initialize GStreamer; put the following code on the line above the <code>Gtk.init</code> call in the <code>main</code> function:</p>
+  <code mime="text/x-valasrc"><![CDATA[Gst.init (ref argv);]]></code>
+  <p>Then, copy the following function into <file>guitar_tuner.vala</file> inside our <code>Main</code> class:</p>
   <code mime="text/x-valasrc"><![CDATA[
 Gst.Element sink;
 Gst.Element source;
@@ -168,7 +170,6 @@ private void play_sound(double frequency)
 
 	time.set_callback(() => {
 		pipeline.set_state (Gst.State.PAUSED);
-		pipeline.unref();
 		return false;
 	});
 	time.attach(null);
diff --git a/platform-demos/C/guitar-tuner/guitar-tuner.cc b/platform-demos/C/guitar-tuner/guitar-tuner.cc
index feaca71..42b07c9 100644
--- a/platform-demos/C/guitar-tuner/guitar-tuner.cc
+++ b/platform-demos/C/guitar-tuner/guitar-tuner.cc
@@ -1,19 +1,16 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 
 #include <gtkmm.h>
 #include <iostream>
 #include <gstreamermm.h>
 
-
 #ifdef ENABLE_NLS
 #  include <libintl.h>
 #endif
 
-
-
-/* For testing propose use the local (not installed) ui file */
+/* For testing purposes, use the local (not installed) ui file */
 /* #define UI_FILE PACKAGE_DATA_DIR"/guitar_tuner_cpp/ui/guitar_tuner_cpp.ui" */
-#define UI_FILE "src/guitar_tuner_cpp.ui"
+#define UI_FILE "src/guitar_tuner.ui"
 
 class Sound
 {
@@ -69,7 +66,7 @@ main(int argc, char *argv[])
 	Gtk::Main kit(argc, argv);
 	Gst::init (argc, argv);
 	
-	//Load the Glade file and instiate its widgets:
+	// Load the Glade file and instantiate its widgets:
 	Glib::RefPtr<Gtk::Builder> builder;
 	try
 	{
@@ -90,19 +87,19 @@ main(int argc, char *argv[])
 	button->signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&on_button_clicked),
 	                                              369.23, &sound));
 	builder->get_widget("button_A", button);
-	button->signal_clicked().connect (sigc::bind<double>(sigc::ptr_fun(&on_button_clicked),
+	button->signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&on_button_clicked),
 	                                              440, &sound));
 	builder->get_widget("button_D", button);
-	button->signal_clicked().connect (sigc::bind<double>(sigc::ptr_fun(&on_button_clicked),
+	button->signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&on_button_clicked),
 	                                              587.33, &sound));
 	builder->get_widget("button_G", button);
-	button->signal_clicked().connect (sigc::bind<double>(sigc::ptr_fun(&on_button_clicked),
+	button->signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&on_button_clicked),
 	                                              783.99, &sound));
 	builder->get_widget("button_B", button);
-	button->signal_clicked().connect (sigc::bind<double>(sigc::ptr_fun(&on_button_clicked),
+	button->signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&on_button_clicked),
 	                                              987.77, &sound));
 	builder->get_widget("button_e", button);
-	button->signal_clicked().connect (sigc::bind<double>(sigc::ptr_fun(&on_button_clicked),
+	button->signal_clicked().connect (sigc::bind<double, Sound*>(sigc::ptr_fun(&on_button_clicked),
 	                                              1318.5, &sound));
 	
 	if (main_win)
diff --git a/platform-demos/C/guitar-tuner/guitar-tuner.vala b/platform-demos/C/guitar-tuner/guitar-tuner.vala
index 2924701..6c8f6b3 100644
--- a/platform-demos/C/guitar-tuner/guitar-tuner.vala
+++ b/platform-demos/C/guitar-tuner/guitar-tuner.vala
@@ -84,7 +84,6 @@ public class Main : Object
 
 		time.set_callback(() => {
 			pipeline.set_state (Gst.State.PAUSED);
-			pipeline.unref();
 		    return false;
 		});
 
@@ -92,8 +91,8 @@ public class Main : Object
 	}
 		
 	static int main (string[] args) {
-		Gtk.init (ref args);
 		Gst.init (ref args);
+		Gtk.init (ref args);
 		var app = new Main ();
 
 		Gtk.main ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]