mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
12 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/clifford/mixmagic/pitch.patch
  9. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. This patch adds pitch shifting to mixmagic. (by Clifford)
  23. --- ./src/block.c.orig Sat Mar 9 11:06:32 2002
  24. +++ ./src/block.c Mon May 13 20:16:56 2002
  25. @@ -834,6 +834,7 @@
  26. b->start = block->start + MIN (block->selection_start, block->selection_end);
  27. b->length = ABS (block->selection_start - block->selection_end);
  28. + block->length_unpitched = block->length * block->pitch;
  29. b->sample = sample_ref (block->sample);
  30. b->position = block->position + MIN (block->selection_start, block->selection_end);
  31. @@ -1143,6 +1144,8 @@
  32. newBlock->sample = sample_ref (block->sample);
  33. newBlock->start = block->start;
  34. newBlock->length = block->length;
  35. + newBlock->length_unpitched = block->length_unpitched;
  36. + newBlock->pitch = block->pitch;
  37. /* Position it on the same place as the popup menu */
  38. newBlock->position = block->position;
  39. @@ -1183,8 +1186,8 @@
  40. block_draw (Block *block)
  41. {
  42. gint i, width, height;
  43. - gint offset, value;
  44. - GString * start_gs , * len_gs ;
  45. + gint offset, offset_start, value;
  46. + GString * start_gs , * len_gs , * pitch_gs;
  47. g_assert (IS_BLOCK(block));
  48. @@ -1210,11 +1213,13 @@
  49. width,
  50. height);
  51. - offset = block->start / INDEX_RATIO;
  52. + offset_start = block->start / INDEX_RATIO;
  53. + offset = 0;
  54. for (i = 0; i < width;i++) {
  55. value = index_get_average (block->sample->index,
  56. - offset, block->start / INDEX_RATIO,
  57. + offset_start + offset * block->pitch,
  58. + block->start / INDEX_RATIO,
  59. block->track->song->x_scale / INDEX_RATIO,
  60. block->sample->length / INDEX_RATIO / 2) / ((float)0x7f / height);
  61. gdk_draw_line (block->pixmap,
  62. @@ -1254,13 +1259,42 @@
  63. /* Draw title */
  64. + gdk_draw_text (block->pixmap,
  65. + GTK_WIDGET(block)->style->font,
  66. + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  67. + 10, 15,
  68. + "F:",
  69. + 2);
  70. +
  71. gdk_draw_text (block->pixmap,
  72. GTK_WIDGET(block)->style->font,
  73. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  74. - 0, 10,
  75. + 25, 15,
  76. block->sample->id,
  77. strlen (block->sample->id));
  78. + /* Draw Pitch Value */
  79. +
  80. + pitch_gs = g_string_sized_new(20);
  81. +
  82. + pitch_gs->len = g_snprintf(pitch_gs->str, 20, "%c%02d.%02d %%",
  83. + block->pitch == 0 ? '0' : (block->pitch > 0 ? '+' : '-'),
  84. + abs(block->pitch*10000 - 10000) / 100,
  85. + abs(block->pitch*10000 - 10000) % 100);
  86. +
  87. + gdk_draw_text (block->pixmap,
  88. + GTK_WIDGET(block)->style->font,
  89. + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  90. + 10, 30,
  91. + "P:",
  92. + 2);
  93. +
  94. + gdk_draw_text (block->pixmap,
  95. + GTK_WIDGET(block)->style->font,
  96. + GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  97. + 25, 30,
  98. + pitch_gs->str,
  99. + pitch_gs->len);
  100. /* Draw start time */
  101. @@ -1281,14 +1315,14 @@
  102. gdk_draw_text (block->pixmap,
  103. GTK_WIDGET(block)->style->font,
  104. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  105. - 0, height - 20,
  106. + 10, height - 20,
  107. "S:",
  108. 2);
  109. gdk_draw_text (block->pixmap,
  110. GTK_WIDGET(block)->style->font,
  111. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  112. - 15, height - 20,
  113. + 25, height - 20,
  114. start_gs->str,
  115. start_gs->len);
  116. @@ -1313,14 +1347,14 @@
  117. gdk_draw_text (block->pixmap,
  118. GTK_WIDGET(block)->style->font,
  119. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  120. - 0, height - 5,
  121. + 10, height - 5,
  122. "L:",
  123. 2);
  124. gdk_draw_text (block->pixmap,
  125. GTK_WIDGET(block)->style->font,
  126. GTK_WIDGET(block)->style->fg_gc[GTK_WIDGET(block)->state],
  127. - 15, height - 5,
  128. + 25, height - 5,
  129. len_gs->str,
  130. len_gs->len);
  131. @@ -1481,6 +1515,73 @@
  132. gtk_widget_draw (GTK_WIDGET (block), NULL);
  133. }
  134. +static void block_set_pitch (GtkWidget *widget, Block *block, gfloat newpitch) {
  135. + block->pitch = newpitch;
  136. + block->length = block->length_unpitched / newpitch;
  137. + block_update (block);
  138. + song_set_dirty (block->track->song, TRUE);
  139. +}
  140. +
  141. +static void block_dec_pitch_1 (GtkWidget *widget, Block *block)
  142. + { block_set_pitch (widget, block, block->pitch - 0.0001); }
  143. +
  144. +static void block_dec_pitch_3 (GtkWidget *widget, Block *block)
  145. + { block_set_pitch (widget, block, block->pitch - 0.0003); }
  146. +
  147. +static void block_dec_pitch_5 (GtkWidget *widget, Block *block)
  148. + { block_set_pitch (widget, block, block->pitch - 0.0005); }
  149. +
  150. +static void block_dec_pitch_10 (GtkWidget *widget, Block *block)
  151. + { block_set_pitch (widget, block, block->pitch - 0.0010); }
  152. +
  153. +static void block_dec_pitch_30 (GtkWidget *widget, Block *block)
  154. + { block_set_pitch (widget, block, block->pitch - 0.0030); }
  155. +
  156. +static void block_dec_pitch_50 (GtkWidget *widget, Block *block)
  157. + { block_set_pitch (widget, block, block->pitch - 0.0050); }
  158. +
  159. +static void block_dec_pitch_100 (GtkWidget *widget, Block *block)
  160. + { block_set_pitch (widget, block, block->pitch - 0.0100); }
  161. +
  162. +static void block_dec_pitch_300 (GtkWidget *widget, Block *block)
  163. + { block_set_pitch (widget, block, block->pitch - 0.0300); }
  164. +
  165. +static void block_dec_pitch_500 (GtkWidget *widget, Block *block)
  166. + { block_set_pitch (widget, block, block->pitch - 0.0500); }
  167. +
  168. +
  169. +static void block_pitch_reset (GtkWidget *widget, Block *block)
  170. + { block_set_pitch (widget, block, 1); }
  171. +
  172. +
  173. +static void block_inc_pitch_1 (GtkWidget *widget, Block *block)
  174. + { block_set_pitch (widget, block, block->pitch + 0.0001); }
  175. +
  176. +static void block_inc_pitch_3 (GtkWidget *widget, Block *block)
  177. + { block_set_pitch (widget, block, block->pitch + 0.0003); }
  178. +
  179. +static void block_inc_pitch_5 (GtkWidget *widget, Block *block)
  180. + { block_set_pitch (widget, block, block->pitch + 0.0005); }
  181. +
  182. +static void block_inc_pitch_10 (GtkWidget *widget, Block *block)
  183. + { block_set_pitch (widget, block, block->pitch + 0.0010); }
  184. +
  185. +static void block_inc_pitch_30 (GtkWidget *widget, Block *block)
  186. + { block_set_pitch (widget, block, block->pitch + 0.0030); }
  187. +
  188. +static void block_inc_pitch_50 (GtkWidget *widget, Block *block)
  189. + { block_set_pitch (widget, block, block->pitch + 0.0050); }
  190. +
  191. +static void block_inc_pitch_100 (GtkWidget *widget, Block *block)
  192. + { block_set_pitch (widget, block, block->pitch + 0.0100); }
  193. +
  194. +static void block_inc_pitch_300 (GtkWidget *widget, Block *block)
  195. + { block_set_pitch (widget, block, block->pitch + 0.0300); }
  196. +
  197. +static void block_inc_pitch_500 (GtkWidget *widget, Block *block)
  198. + { block_set_pitch (widget, block, block->pitch + 0.0500); }
  199. +
  200. +
  201. static void
  202. block_select_all (GtkWidget *widget, Block *block)
  203. {
  204. @@ -1534,6 +1635,26 @@
  205. GNOMEUIINFO_SEPARATOR,
  206. GNOMEUIINFO_ITEM_NONE (N_("Convert to loopblock"), N_("Convert to loopblock"), block_convert_to_loopblock),
  207. GNOMEUIINFO_SEPARATOR,
  208. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -5.00"), N_(""), block_dec_pitch_500),
  209. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -3.00"), N_(""), block_dec_pitch_300),
  210. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -1.00"), N_(""), block_dec_pitch_100),
  211. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.50"), N_(""), block_dec_pitch_50),
  212. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.30"), N_(""), block_dec_pitch_30),
  213. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.10"), N_(""), block_dec_pitch_10),
  214. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.05"), N_(""), block_dec_pitch_5),
  215. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.03"), N_(""), block_dec_pitch_3),
  216. + GNOMEUIINFO_ITEM_NONE (N_("Pitch -0.01"), N_(""), block_dec_pitch_1),
  217. + GNOMEUIINFO_ITEM_NONE (N_("Reset Pitch"), N_(""), block_pitch_reset),
  218. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.01"), N_(""), block_inc_pitch_1),
  219. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.03"), N_(""), block_inc_pitch_3),
  220. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.05"), N_(""), block_inc_pitch_5),
  221. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.10"), N_(""), block_inc_pitch_10),
  222. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.30"), N_(""), block_inc_pitch_30),
  223. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +0.50"), N_(""), block_inc_pitch_50),
  224. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +1.00"), N_(""), block_inc_pitch_100),
  225. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +3.00"), N_(""), block_inc_pitch_300),
  226. + GNOMEUIINFO_ITEM_NONE (N_("Pitch +5.00"), N_(""), block_inc_pitch_500),
  227. + GNOMEUIINFO_SEPARATOR,
  228. GNOMEUIINFO_ITEM_NONE (N_("Select all"), N_("Make the selection cover the whole block"), block_select_all),
  229. GNOMEUIINFO_END
  230. };
  231. @@ -1640,24 +1761,30 @@
  232. mix_into_buffer (Block *block, gint16 *buffer, gint position, gint length)
  233. {
  234. gint16 *data;
  235. - gint i;
  236. + gint i, data_offset, data_xoffset;
  237. - data = (gint16 *)(block->sample->data +
  238. - (block->start + position - block->position) * block->sample->byte_p_spl);
  239. -
  240. - for (i = 0;i < length / (sizeof (guint16) * 2);i++) {
  241. + data = (gint16 *)(block->sample->data +
  242. + (block->start - block->position) *
  243. + block->sample->byte_p_spl);
  244. + data_offset = position;
  245. +
  246. + for (i = 0; i < length / (sizeof (guint16) * 2); i++) {
  247. +
  248. + data_xoffset = data_offset * block->pitch;
  249. + data_xoffset *= block->sample->num_channels;
  250. mixer_mix_sample_into_buffer (buffer,
  251. - data,
  252. + data + data_xoffset,
  253. block->amp_env,
  254. block->pan_env,
  255. block->track->amp,
  256. block->track->pan,
  257. - position - block->position + i, block->sample->num_channels);
  258. + position - block->position + i,
  259. + block->sample->num_channels);
  260. - data += block->sample->num_channels;
  261. + data_offset++;
  262. buffer += 2;
  263. }
  264. }
  265. /*
  266. @@ -1675,8 +1813,11 @@
  267. block->start = atoi ((ptr = xmlGetProp (node, "start")));
  268. g_free (ptr);
  269. - block->length = atoi ((ptr = xmlGetProp (node, "length")));
  270. + block->length_unpitched = atoi ((ptr = xmlGetProp (node, "length")));
  271. g_free (ptr);
  272. + block->pitch = (float)atoi ((ptr = xmlGetProp (node, "pitch"))) / 10000;
  273. + g_free (ptr);
  274. + block->length = (float)block->length_unpitched * block->pitch;
  275. block->position = atoi ((ptr = xmlGetProp (node, "position")));
  276. g_free (ptr);
  277. ptr = xmlGetProp (node, "sample");
  278. --- ./src/track.c.orig Tue Mar 12 06:39:42 2002
  279. +++ ./src/track.c Mon Mar 11 20:53:32 2002
  280. @@ -328,6 +328,8 @@
  281. block->start = 0;
  282. block->length = sample_get_length(block->sample);
  283. + block->length_unpitched = sample_get_length(block->sample);
  284. + block->pitch=1;
  285. /* Position it on the same place as the popup menu */
  286. block->position = (x + (gint)(GTK_LAYOUT (track->layout)->hadjustment->value)) * track->song->x_scale;
  287. --- ./src/block.h.orig Mon Mar 11 20:47:57 2002
  288. +++ ./src/block.h Mon Mar 11 20:37:16 2002
  289. @@ -89,6 +89,9 @@
  290. gint length; /* The length of this block */
  291. gint position; /* Position in time */
  292. + gfloat pitch; /* Pitch shifting (in %) */
  293. + gint length_unpitched; /* The length before pitch is applied */
  294. +
  295. Sample *sample; /* The sample assosiated with this block */
  296. GList *amp_env; /* Pointer to this blocks amplitude envelope or NULL */