root/sweep/trunk/src/notes.c

Revision 688, 4.0 kB (checked in by erikd, 2 years ago)

Clean up large number of '#if 0' and '#if 1' code blocks.

Remove code chunks surrounded by '#if 0' .. '#endif'.
Remove '#if 1' and '#endif' around code chunks that are actually being used.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Sweep, a sound wave editor.
3  *
4  * Copyright (C) 2000 Conrad Parker
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #  include <config.h>
23 #endif
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31
32 #include "callbacks.h"
33
34 #include <sweep/sweep_i18n.h>
35
36 #include <sweep/sweep_types.h>
37 #include <sweep/sweep_undo.h>
38 #include <sweep/sweep_sample.h>
39
40 #include "head.h"
41 #include "interface.h"
42 #include "edit.h"
43 #include "sample-display.h"
44 #include "play.h"
45
46 #include "notes.h"
47
48 typedef struct _sw_noteplay sw_noteplay;
49
50 struct _sw_noteplay {
51   char name [5];
52   float pitch;
53   guint  accel_key;
54   char accel_basename [4];
55 };
56
57 static void play_view_note_cb (GtkWidget * widget, gpointer data);
58
59 static sw_noteplay notes [] =
60 {
61   { N_("C3") , 0.500000, GDK_z, "C3" },
62   { N_("C#3"), 0.529732, GDK_s, "C#3"},
63   { N_("D3") , 0.561231, GDK_x, "D3" },
64   { N_("Eb3"), 0.594604, GDK_d, "Eb3"},
65   { N_("E3") , 0.629961, GDK_c, "E3" },
66   { N_("F3") , 0.667420, GDK_v, "F3" },
67   { N_("F#3"), 0.707107, GDK_g, "F#3"},
68   { N_("G3") , 0.749154, GDK_b, "G3" },
69   { N_("G#3"), 0.793701, GDK_h, "G#3"},
70   { N_("A3") , 0.840896, GDK_n, "A3" },
71   { N_("Bb3"), 0.890899, GDK_j, "Bb3"},
72   { N_("B3") , 0.943874, GDK_m, "B3" },
73
74   { N_("C4") , 1.000000, GDK_q, "C4" },
75
76   { N_("C#4"), 1.059463, GDK_2, "C#4"},
77   { N_("D4") , 1.122462, GDK_w, "D4" },
78   { N_("Eb4"), 1.189207, GDK_3, "Eb4"},
79   { N_("E4") , 1.259921, GDK_e, "E4" },
80   { N_("F4") , 1.334840, GDK_r, "F4" },
81   { N_("F#4"), 1.414214, GDK_5, "F#4"},
82   { N_("G4") , 1.498307, GDK_t, "G4" },
83   { N_("G#4"), 1.587401, GDK_6, "G#4"},
84   { N_("A4") , 1.681793, GDK_y, "A4" },
85   { N_("Bb4"), 1.781797, GDK_7, "Bb4"},
86   { N_("B4") , 1.887749, GDK_u, "B4" },
87
88   { N_("C5") , 2.000000, GDK_i, "C5" },
89   { N_("C#5"), 2.118926, GDK_9, "C#5"},
90   { N_("D5") , 2.244924, GDK_o, "D5" },
91   { N_("D#5"), 2.378414, GDK_0, "D#5"},
92   { N_("E5") , 2.519842, GDK_p, "E5" },
93 } ;
94
95
96 void
97 noteplay_setup (GtkWidget *subsubmenu, sw_view * view,
98                 GtkAccelGroup *accel_group)
99 {
100   GtkWidget *menuitem;
101   int k;
102   gchar * tmpchar;
103
104   for (k = 0 ; k < sizeof (notes) / sizeof (notes [0]) ; k++) {
105     menuitem = gtk_menu_item_new_with_label (_(notes [k].name));
106     gtk_menu_append (GTK_MENU(subsubmenu), menuitem);
107         gtk_menu_set_accel_group(GTK_MENU(subsubmenu), accel_group);
108     g_signal_connect (G_OBJECT(menuitem), "activate",
109                         G_CALLBACK(play_view_note_cb), view);
110     tmpchar = g_strdup_printf("<Sweep-View>/Playback/Play Note/%s",
111                                notes[k].accel_basename);
112          
113     gtk_menu_item_set_accel_path (GTK_MENU_ITEM(menuitem), tmpchar);
114         gtk_accel_map_add_entry  ( tmpchar, notes[k].accel_key, 0);
115
116     g_object_set_data (G_OBJECT(menuitem), "default",
117                               GINT_TO_POINTER(k));
118         gtk_widget_show (menuitem);
119   }
120
121   return;
122 }
123
124 static void
125 play_view_note_cb (GtkWidget * widget, gpointer data)
126 {
127   sw_view * view = (sw_view*) data;
128   sw_head * head = view->sample->play_head;
129   sw_framecount_t mouse_offset;
130   int k;
131   float pitch;
132  
133   /* Retrieve the pitch. */
134   k = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(widget), "default"));
135   pitch = notes[k].pitch;
136
137   if (head->going) {
138     head_set_rate (head, pitch);
139     mouse_offset =
140       sample_display_get_mouse_offset (SAMPLE_DISPLAY(view->display));
141     head_set_offset (head, mouse_offset);
142   } else {
143     play_view_all_pitch (view, pitch);
144   }
145
146 }
Note: See TracBrowser for help on using the browser.