annotate Plugins/Input/amidi-plug/amidi-plug.c @ 805:b8b9d7f5d371 trunk

[svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
author giacomo
date Tue, 07 Mar 2006 11:47:20 -0800
parents 8efa4b799c19
children ee25017cb472
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
1 /*
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
2 *
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
3 * Author: Giacomo Lozito <james@develia.org>, (C) 2005-2006
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
4 *
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify it
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
6 * under the terms of the GNU General Public License as published by the
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
7 * Free Software Foundation; either version 2 of the License, or (at your
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
8 * option) any later version.
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
9 *
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful, but
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
13 * General Public License for more details.
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
14 *
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License along
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
16 * with this program; if not, write to the Free Software Foundation, Inc.,
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
18 *
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
19 */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
20
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
21 #include "amidi-plug.h"
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
22
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
23
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
24 InputPlugin *get_iplugin_info(void)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
25 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
26 amidiplug_ip.description = g_strdup_printf(_("AMIDI-Plug %s (MIDI Player)"), AMIDIPLUG_VERSION);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
27 return &amidiplug_ip;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
28 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
29
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
30
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
31 static gint amidiplug_is_our_file( gchar * filename )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
32 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
33 #ifdef MIDIFILE_PROBE_MAGICBYTES
544
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
34 VFSFile * fp;
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
35 gchar magic_bytes[4];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
36
544
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
37 fp = vfs_fopen( filename , "rb" );
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
38
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
39 if (fp == NULL)
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
40 return FALSE;
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
41
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
42 vfs_fread( magic_bytes , 1 , 4 , fp );
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
43
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
44 if ( !strncmp( magic_bytes , "MThd" , 4 ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
45 {
544
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
46 vfs_fclose( fp );
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
47 DEBUGMSG( "MIDI found, %s is a standard midi file\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
48 return TRUE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
49 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
50
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
51 if ( !strncmp( magic_bytes , "RIFF" , 4 ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
52 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
53 /* skip the four bytes after RIFF,
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
54 then read the next four */
544
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
55 vfs_fseek( fp , 4 , SEEK_CUR );
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
56 vfs_fread( magic_bytes , 1 , 4 , fp );
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
57 if ( !strncmp( magic_bytes , "RMID" , 4 ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
58 {
544
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
59 vfs_fclose( fp );
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
60 DEBUGMSG( "MIDI found, %s is a riff midi file\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
61 return TRUE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
62 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
63 }
544
3f45ec88fcd3 [svn] fix giacomo's bug I think
nenolod
parents: 525
diff changeset
64 vfs_fclose( fp );
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
65 #else
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
66 gchar * ext = strrchr( filename, '.' );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
67 /* check the filename extension */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
68 if ( ( ext ) &&
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
69 (( !strcasecmp(ext,".mid") ) || ( !strcasecmp(ext,".midi") ) ||
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
70 ( !strcasecmp(ext,".rmi") ) || ( !strcasecmp(ext,".rmid") )) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
71 return TRUE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
72 #endif
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
73 return FALSE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
74 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
75
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
76
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
77 static void amidiplug_init( void )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
78 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
79 g_log_set_handler(NULL , G_LOG_LEVEL_WARNING , g_log_default_handler , NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
80 DEBUGMSG( "init, read configuration\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
81 /* read configuration */
525
6e332a32d2f5 [svn] amidi-plug: do not try to guess the correct alsa port from alsa-lib version if there's not a wavetable hw synth available
giacomo
parents: 522
diff changeset
82 i_configure_cfg_read();
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
83 amidiplug_playing_status = AMIDIPLUG_STOP;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
84 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
85
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
86
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
87 static void amidiplug_cleanup( void )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
88 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
89 g_free( amidiplug_ip.description );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
90 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
91
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
92
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
93 static void amidiplug_configure( void )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
94 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
95 if ( amidiplug_gui_prefs.config_win )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
96 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
97 return;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
98 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
99 else
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
100 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
101 GSList * wports = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
102 GSList * scards = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
103 /* get an updated list of writable ALSA MIDI ports and ALSA-enabled sound cards*/
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
104 DEBUGMSG( "get an updated list of writable ALSA MIDI ports\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
105 wports = i_seq_port_get_list();
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
106 DEBUGMSG( "get an updated list of ALSA-enabled sound cards\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
107 scards = i_seq_card_get_list();
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
108 /* display them in our nice config dialog */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
109 DEBUGMSG( "opening config window\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
110 i_configure_gui( wports , scards );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
111 /* free the cards list and the ports list */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
112 i_seq_card_free_list( scards );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
113 i_seq_port_free_list( wports );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
114 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
115 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
116
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
117
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
118 static void amidiplug_aboutbox( void )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
119 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
120 i_about_gui();
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
121 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
122
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
123
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
124 static void amidiplug_file_info_box( gchar * filename )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
125 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
126 i_fileinfo_gui( filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
127 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
128
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
129
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
130 static void amidiplug_stop( void )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
131 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
132 DEBUGMSG( "STOP request at tick: %i\n" , midifile.playing_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
133 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
134 if (( amidiplug_playing_status == AMIDIPLUG_PLAY ) ||
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
135 ( amidiplug_playing_status == AMIDIPLUG_STOP ))
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
136 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
137 amidiplug_playing_status = AMIDIPLUG_STOP;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
138 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
139 pthread_join( amidiplug_play_thread , NULL );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
140 DEBUGMSG( "STOP activated (play thread joined)\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
141 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
142 else if ( amidiplug_playing_status == AMIDIPLUG_PAUSE )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
143 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
144 amidiplug_playing_status = AMIDIPLUG_STOP;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
145 DEBUGMSG( "STOP activated (from PAUSE to STOP)\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
146 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
147 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
148 else /* AMIDIPLUG_ERR */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
149 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
150 DEBUGMSG( "STOP activated (in error handling, ok)\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
151 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
152 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
153 /* kill the sequencer (while it has been already killed if we come from
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
154 pause, it's safe to do anyway since it checks for multiple calls */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
155 i_seq_off();
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
156 /* free midi data (same as above) */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
157 i_midi_free( &midifile );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
158 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
159
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
160
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
161 static void amidiplug_pause( gshort paused )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
162 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
163 if ( paused )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
164 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
165 DEBUGMSG( "PAUSE request at tick: %i\n" , midifile.playing_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
166 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
167 /* this cond is used to avoid race conditions */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
168 while ( amidiplug_playing_status != AMIDIPLUG_PLAY )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
169 pthread_cond_wait( &amidiplug_playing_cond , &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
170 amidiplug_playing_status = AMIDIPLUG_PAUSE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
171 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
172
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
173 pthread_join( amidiplug_play_thread , NULL );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
174 DEBUGMSG( "PAUSE activated (play thread joined)\n" , midifile.playing_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
175
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
176 /* kill the sequencer */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
177 i_seq_off();
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
178 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
179 else
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
180 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
181 DEBUGMSG( "PAUSE deactivated, returning to tick %i\n" , midifile.playing_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
182 /* revive the sequencer */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
183 i_seq_on( 0 , NULL );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
184 /* re-set initial tempo */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
185 i_midi_setget_tempo( &midifile );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
186 i_seq_queue_set_tempo( midifile.current_tempo , midifile.ppq );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
187 /* get back to the previous state */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
188 amidiplug_skipto( midifile.playing_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
189
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
190 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
191 /* play play play! */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
192 DEBUGMSG( "PAUSE deactivated, starting play thread again\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
193 pthread_create(&amidiplug_play_thread, NULL, amidiplug_play_loop, NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
194 /* this cond is used to avoid race conditions */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
195 while ( amidiplug_playing_status != AMIDIPLUG_PLAY )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
196 pthread_cond_wait( &amidiplug_playing_cond , &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
197 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
198 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
199 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
200
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
201
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
202 static void amidiplug_seek( gint time )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
203 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
204 DEBUGMSG( "SEEK requested (time %i), pausing song...\n" , time );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
205 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
206 /* this cond is used to avoid race conditions */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
207 while ( amidiplug_playing_status != AMIDIPLUG_PLAY )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
208 pthread_cond_wait( &amidiplug_playing_cond , &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
209 amidiplug_playing_status = AMIDIPLUG_PAUSE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
210 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
211
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
212 pthread_join( amidiplug_play_thread , NULL );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
213 DEBUGMSG( "SEEK requested (time %i), song paused\n" , time );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
214 /* kill the sequencer */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
215 i_seq_off();
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
216 /* revive the sequencer */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
217 i_seq_on( 0 , NULL );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
218 /* re-set initial tempo */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
219 i_midi_setget_tempo( &midifile );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
220 i_seq_queue_set_tempo( midifile.current_tempo , midifile.ppq );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
221 /* get back to the previous state */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
222 DEBUGMSG( "SEEK requested (time %i), moving to tick %i of %i\n" ,
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
223 time , (gint)((time * 1000000) / midifile.avg_microsec_per_tick) , midifile.max_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
224 midifile.playing_tick = (gint)((time * 1000000) / midifile.avg_microsec_per_tick);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
225 amidiplug_skipto( midifile.playing_tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
226 /* play play play! */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
227 DEBUGMSG( "SEEK done, starting play thread again\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
228 pthread_create(&amidiplug_play_thread, NULL, amidiplug_play_loop, NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
229 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
230
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
231
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
232 static gint amidiplug_get_time( void )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
233 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
234 gint pt;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
235 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
236 if (( amidiplug_playing_status == AMIDIPLUG_PLAY ) ||
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
237 ( amidiplug_playing_status == AMIDIPLUG_PAUSE ))
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
238 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
239 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
240 pthread_mutex_lock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
241 pt = midifile.playing_tick;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
242 pthread_mutex_unlock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
243 return (gint)((pt * midifile.avg_microsec_per_tick) / 1000);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
244 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
245 else if ( amidiplug_playing_status == AMIDIPLUG_STOP )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
246 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
247 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
248 DEBUGMSG( "GETTIME on stopped song, returning -1\n" , time );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
249 return -1;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
250 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
251 else /* AMIDIPLUG_ERR */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
252 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
253 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
254 DEBUGMSG( "GETTIME on halted song (an error occurred?), returning -1 and stopping the player\n" , time );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
255 xmms_remote_stop(0);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
256 return -1;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
257 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
258 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
259
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
260
737
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
261 static void amidiplug_get_volume( gint * l , gint * r )
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
262 {
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
263 gchar mixer_card[10];
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
264 snprintf( mixer_card , 8 , "hw:%i" , amidiplug_cfg.mixer_card_id );
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
265 mixer_card[9] = '\0';
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
266 /* get volume */
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
267 i_seq_mixer_get_volume( l , r , mixer_card , amidiplug_cfg.mixer_control_name ,
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
268 amidiplug_cfg.mixer_control_id );
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
269 }
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
270
8efa4b799c19 [svn] Added a get_volume plugin function, to ensure that the player volume is properly updated when the player is remotely controlled
giacomo
parents: 548
diff changeset
271
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
272 static void amidiplug_set_volume( gint l , gint r )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
273 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
274 gchar mixer_card[10];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
275 snprintf( mixer_card , 8 , "hw:%i" , amidiplug_cfg.mixer_card_id );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
276 mixer_card[9] = '\0';
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
277 /* set volume */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
278 i_seq_mixer_set_volume( l , r , mixer_card , amidiplug_cfg.mixer_control_name ,
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
279 amidiplug_cfg.mixer_control_id );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
280 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
281
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
282
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
283 static void amidiplug_get_song_info( gchar * filename , gchar ** title , gint * length )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
284 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
285 /* song title, get it from the filename */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
286 *title = G_PATH_GET_BASENAME(filename);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
287
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
288 /* sure, it's possible to calculate the length of a MIDI file anytime,
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
289 but the file must be entirely parsed to calculate it; this could lead
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
290 to performance loss, for now it's safer to calculate the length only
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
291 right before playing the file */
805
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
292
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
293 if ( amidiplug_cfg.length_precalc_enable )
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
294 {
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
295 /* let's calculate the midi length, using this nice helper function that
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
296 will return 0 if a problem occurs and the length can't be calculated */
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
297 midifile_t mf;
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
298
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
299 if ( i_midi_parse_from_filename( filename , &mf ) )
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
300 *length = (gint)(mf.length / 1000);
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
301 else
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
302 *length = -1;
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
303
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
304 i_midi_free( &mf );
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
305 }
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
306 else
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
307 *length = -1;
b8b9d7f5d371 [svn] update amidi-plug towards 0.2; bug fixes and a new option (midi length pre-calculation)
giacomo
parents: 737
diff changeset
308
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
309 return;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
310 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
311
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
312
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
313 static void amidiplug_play( gchar * filename )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
314 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
315 gint port_count = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
316 DEBUGMSG( "PLAY requested, midifile init\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
317 /* midifile init */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
318 i_midi_init( &midifile );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
319
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
320 /* get the number of selected alsa ports */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
321 port_count = i_util_str_count( amidiplug_cfg.seq_writable_ports , ':' );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
322 if ( port_count < 1 )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
323 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
324 g_warning( "No ALSA ports selected\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
325 amidiplug_playing_status = AMIDIPLUG_ERR;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
326 return;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
327 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
328
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
329 DEBUGMSG( "PLAY requested, opening file: %s\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
330 midifile.file_pointer = fopen( filename , "rb" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
331 if (!midifile.file_pointer)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
332 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
333 g_warning( "Cannot open %s\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
334 amidiplug_playing_status = AMIDIPLUG_ERR;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
335 return;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
336 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
337 midifile.file_name = filename;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
338
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
339 switch( i_midi_file_read_id( &midifile ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
340 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
341 case MAKE_ID('R', 'I', 'F', 'F'):
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
342 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
343 DEBUGMSG( "PLAY requested, RIFF chunk found, processing...\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
344 /* read riff chunk */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
345 if ( !i_midi_file_parse_riff( &midifile ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
346 WARNANDBREAKANDPLAYERR( "%s: invalid file format (riff parser)\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
347
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
348 /* if that was read correctly, go ahead and read smf data */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
349 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
350
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
351 case MAKE_ID('M', 'T', 'h', 'd'):
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
352 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
353 DEBUGMSG( "PLAY requested, MThd chunk found, processing...\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
354 if ( !i_midi_file_parse_smf( &midifile , port_count ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
355 WARNANDBREAKANDPLAYERR( "%s: invalid file format (smf parser)\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
356
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
357 if ( midifile.time_division < 1 )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
358 WARNANDBREAKANDPLAYERR( "%s: invalid time division (%i)\n" , filename , midifile.time_division );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
359
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
360 DEBUGMSG( "PLAY requested, setting ppq and tempo...\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
361 /* fill midifile.ppq and midifile.tempo using time_division */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
362 if ( !i_midi_setget_tempo( &midifile ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
363 WARNANDBREAKANDPLAYERR( "%s: invalid values while setting ppq and tempo\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
364
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
365 DEBUGMSG( "PLAY requested, sequencer init\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
366 /* sequencer on */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
367 if ( !i_seq_on( 1 , amidiplug_cfg.seq_writable_ports ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
368 WARNANDBREAKANDPLAYERR( "%s: ALSA problem, play aborted\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
369
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
370 DEBUGMSG( "PLAY requested, setting sequencer queue tempo...\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
371 /* set sequencer queue tempo using ppq and tempo (call only after i_midi_setget_tempo) */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
372 if ( !i_seq_queue_set_tempo( midifile.current_tempo , midifile.ppq ) )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
373 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
374 i_seq_off(); /* kill the sequencer */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
375 WARNANDBREAKANDPLAYERR( "%s: ALSA queue problem, play aborted\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
376 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
377
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
378 /* fill midifile.length, keeping in count tempo-changes */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
379 i_midi_setget_length( &midifile );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
380 DEBUGMSG( "PLAY requested, song length calculated: %i msec\n" , (gint)(midifile.length / 1000) );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
381
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
382 /* our length is in microseconds, but the player wants milliseconds */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
383 amidiplug_ip.set_info( G_PATH_GET_BASENAME(filename) , (gint)(midifile.length / 1000) , -1 , -1 , -1 );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
384
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
385 /* play play play! */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
386 DEBUGMSG( "PLAY requested, starting play thread\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
387 amidiplug_playing_status = AMIDIPLUG_PLAY;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
388 pthread_create(&amidiplug_play_thread, NULL, amidiplug_play_loop, NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
389 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
390 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
391
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
392 default:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
393 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
394 amidiplug_playing_status = AMIDIPLUG_ERR;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
395 g_warning( "%s is not a Standard MIDI File\n" , filename );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
396 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
397 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
398 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
399
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
400 fclose( midifile.file_pointer );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
401 return;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
402 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
403
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
404
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
405
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
406 void * amidiplug_play_loop( void * arg )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
407 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
408 snd_seq_event_t ev;
548
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
409 gint i, p, c;
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
410 gboolean rewind = FALSE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
411
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
412 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
413 if ( amidiplug_playing_status != AMIDIPLUG_PAUSE )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
414 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
415 DEBUGMSG( "PLAY thread, rewind tracks to their first event\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
416 rewind = TRUE;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
417 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
418 else
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
419 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
420 DEBUGMSG( "PLAY thread, do not rewind tracks to their first event (coming from a PAUSE status)\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
421 amidiplug_playing_status = AMIDIPLUG_PLAY;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
422 pthread_cond_signal( &amidiplug_playing_cond );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
423 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
424 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
425
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
426 if ( rewind )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
427 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
428 /* initialize current position in each track */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
429 for (i = 0; i < midifile.num_tracks; ++i)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
430 midifile.tracks[i].current_event = midifile.tracks[i].first_event;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
431 snd_seq_start_queue(sc.seq, sc.queue, NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
432 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
433
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
434 /* common settings for all our events */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
435 snd_seq_ev_clear(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
436 ev.queue = sc.queue;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
437 ev.source.port = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
438 ev.flags = SND_SEQ_TIME_STAMP_TICK;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
439
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
440 DEBUGMSG( "PLAY thread, start the play loop\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
441 for (;;)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
442 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
443 midievent_t * event = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
444 midifile_track_t * event_track = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
445 gint i, min_tick = midifile.max_tick + 1;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
446
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
447 /* search next event */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
448 for (i = 0; i < midifile.num_tracks; ++i)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
449 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
450 midifile_track_t * track = &midifile.tracks[i];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
451 midievent_t * e2 = track->current_event;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
452 if (( e2 ) && ( e2->tick < min_tick ))
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
453 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
454 min_tick = e2->tick;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
455 event = e2;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
456 event_track = track;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
457 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
458 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
459
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
460 /* check if the song has been stopped */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
461 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
462 if ( amidiplug_playing_status != AMIDIPLUG_PLAY )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
463 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
464 DEBUGMSG( "PLAY thread, PAUSE or STOP requested, exiting from play loop\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
465 event = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
466 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
467 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
468
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
469 if (!event)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
470 break; /* end of song reached */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
471
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
472 /* advance pointer to next event */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
473 event_track->current_event = event->next;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
474
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
475 /* output the event */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
476 ev.type = event->type;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
477 ev.time.tick = event->tick - midifile.skip_offset;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
478 ev.dest = sc.dest_port[event->port];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
479
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
480 switch (ev.type)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
481 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
482 case SND_SEQ_EVENT_NOTEON:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
483 case SND_SEQ_EVENT_NOTEOFF:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
484 case SND_SEQ_EVENT_KEYPRESS:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
485 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
486 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
487 ev.data.note.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
488 ev.data.note.note = event->data.d[1];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
489 ev.data.note.velocity = event->data.d[2];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
490 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
491 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
492 case SND_SEQ_EVENT_CONTROLLER:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
493 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
494 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
495 ev.data.control.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
496 ev.data.control.param = event->data.d[1];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
497 ev.data.control.value = event->data.d[2];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
498 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
499 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
500 case SND_SEQ_EVENT_PGMCHANGE:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
501 case SND_SEQ_EVENT_CHANPRESS:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
502 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
503 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
504 ev.data.control.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
505 ev.data.control.value = event->data.d[1];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
506 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
507 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
508 case SND_SEQ_EVENT_PITCHBEND:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
509 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
510 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
511 ev.data.control.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
512 ev.data.control.value = ((event->data.d[1]) | ((event->data.d[2]) << 7)) - 0x2000;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
513 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
514 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
515 case SND_SEQ_EVENT_SYSEX:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
516 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
517 snd_seq_ev_set_variable(&ev, event->data.length, event->sysex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
518 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
519 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
520 case SND_SEQ_EVENT_TEMPO:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
521 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
522 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
523 ev.dest.client = SND_SEQ_CLIENT_SYSTEM;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
524 ev.dest.port = SND_SEQ_PORT_SYSTEM_TIMER;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
525 ev.data.queue.queue = sc.queue;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
526 ev.data.queue.param.value = event->data.tempo;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
527 DEBUGMSG( "PLAY thread, processing tempo event with value %i on tick %i\n" ,
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
528 event->data.tempo , event->tick );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
529 pthread_mutex_lock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
530 midifile.current_tempo = event->data.tempo;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
531 pthread_mutex_unlock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
532 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
533 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
534 default:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
535 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
536 DEBUGMSG( "PLAY thread, encountered invalid event type %i\n" , ev.type );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
537 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
538 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
539 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
540
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
541 pthread_mutex_lock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
542 midifile.playing_tick = event->tick;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
543 pthread_mutex_unlock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
544
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
545 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
546 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
547 snd_seq_sync_output_queue(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
548 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
549
548
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
550 /* time to shutdown playback! */
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
551 /* send "ALL SOUNDS OFF" to all channels on all ports */
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
552 ev.type = SND_SEQ_EVENT_CONTROLLER;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
553 ev.time.tick = 0;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
554 snd_seq_ev_set_fixed(&ev);
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
555 ev.data.control.param = MIDI_CTL_ALL_SOUNDS_OFF;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
556 ev.data.control.value = 0;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
557 for ( p = 0 ; p < sc.dest_port_num ; p++)
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
558 {
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
559 ev.queue = sc.queue;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
560 ev.dest = sc.dest_port[p];
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
561
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
562 for ( c = 0 ; c < 16 ; c++ )
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
563 {
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
564 ev.data.control.channel = c;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
565 snd_seq_event_output(sc.seq, &ev);
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
566 snd_seq_drain_output(sc.seq);
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
567 }
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
568 }
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
569
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
570 /* schedule queue stop at end of song */
548
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
571 snd_seq_ev_clear(&ev);
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
572 ev.queue = sc.queue;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
573 ev.source.port = 0;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
574 ev.flags = SND_SEQ_TIME_STAMP_TICK;
1954be7d4889 [svn] added support for the FluidSynth ALSA backend, by sending a MIDI_CTL_ALL_SOUNDS_OFF controller event when playback is halted
giacomo
parents: 544
diff changeset
575
522
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
576 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
577 ev.type = SND_SEQ_EVENT_STOP;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
578 ev.time.tick = midifile.max_tick - midifile.skip_offset;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
579 ev.dest.client = SND_SEQ_CLIENT_SYSTEM;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
580 ev.dest.port = SND_SEQ_PORT_SYSTEM_TIMER;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
581 ev.data.queue.queue = sc.queue;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
582 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
583 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
584 /* snd_seq_sync_output_queue(sc.seq); */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
585
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
586 pthread_mutex_lock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
587 if ( amidiplug_playing_status != AMIDIPLUG_PAUSE )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
588 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
589 amidiplug_playing_status = AMIDIPLUG_STOP;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
590 DEBUGMSG( "PLAY thread, song stopped/ended\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
591
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
592 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
593 pthread_mutex_unlock( &amidiplug_playing_mutex );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
594
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
595 pthread_exit(NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
596 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
597
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
598
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
599 /* amidigplug_skipto: re-do all events that influence the playing of our
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
600 midi file; re-do them using a time-tick of 0, so they are processed
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
601 istantaneously and proceed this way until the playing_tick is reached;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
602 also obtain the correct skip_offset from the playing_tick */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
603 void amidiplug_skipto( gint playing_tick )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
604 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
605 snd_seq_event_t ev;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
606 gint i;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
607
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
608 /* this check is always made, for safety*/
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
609 if ( playing_tick >= midifile.max_tick )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
610 playing_tick = midifile.max_tick - 1;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
611
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
612 /* initialize current position in each track */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
613 for (i = 0; i < midifile.num_tracks; ++i)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
614 midifile.tracks[i].current_event = midifile.tracks[i].first_event;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
615
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
616 /* common settings for all our events */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
617 snd_seq_ev_clear(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
618 ev.queue = sc.queue;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
619 ev.source.port = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
620 ev.flags = SND_SEQ_TIME_STAMP_TICK;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
621
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
622 snd_seq_start_queue(sc.seq, sc.queue, NULL);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
623
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
624 DEBUGMSG( "SKIPTO request, starting skipto loop\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
625 for (;;)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
626 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
627 midievent_t * event = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
628 midifile_track_t * event_track = NULL;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
629 gint i, min_tick = midifile.max_tick + 1;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
630
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
631 /* search next event */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
632 for (i = 0; i < midifile.num_tracks; ++i)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
633 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
634 midifile_track_t * track = &midifile.tracks[i];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
635 midievent_t * e2 = track->current_event;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
636 if (( e2 ) && ( e2->tick < min_tick ))
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
637 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
638 min_tick = e2->tick;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
639 event = e2;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
640 event_track = track;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
641 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
642 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
643
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
644 /* unlikely here... unless very strange MIDI files are played :) */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
645 if (!event)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
646 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
647 DEBUGMSG( "SKIPTO request, reached the last event but not the requested tick (!)\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
648 break; /* end of song reached */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
649 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
650
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
651 /* reached the requested tick, job done */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
652 if ( event->tick >= playing_tick )
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
653 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
654 DEBUGMSG( "SKIPTO request, reached the requested tick, exiting from skipto loop\n" );
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
655 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
656 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
657
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
658 /* advance pointer to next event */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
659 event_track->current_event = event->next;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
660
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
661 /* output the event */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
662 ev.type = event->type;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
663 ev.time.tick = event->tick;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
664 ev.dest = sc.dest_port[event->port];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
665
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
666 switch (ev.type)
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
667 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
668 /* do nothing for these
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
669 case SND_SEQ_EVENT_NOTEON:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
670 case SND_SEQ_EVENT_NOTEOFF:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
671 case SND_SEQ_EVENT_KEYPRESS:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
672 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
673 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
674 } */
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
675 case SND_SEQ_EVENT_CONTROLLER:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
676 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
677 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
678 ev.data.control.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
679 ev.data.control.param = event->data.d[1];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
680 ev.data.control.value = event->data.d[2];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
681 ev.time.tick = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
682 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
683 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
684 snd_seq_sync_output_queue(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
685 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
686 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
687 case SND_SEQ_EVENT_PGMCHANGE:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
688 case SND_SEQ_EVENT_CHANPRESS:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
689 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
690 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
691 ev.data.control.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
692 ev.data.control.value = event->data.d[1];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
693 ev.time.tick = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
694 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
695 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
696 snd_seq_sync_output_queue(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
697 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
698 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
699 case SND_SEQ_EVENT_PITCHBEND:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
700 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
701 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
702 ev.data.control.channel = event->data.d[0];
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
703 ev.data.control.value = ((event->data.d[1]) | ((event->data.d[2]) << 7)) - 0x2000;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
704 ev.time.tick = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
705 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
706 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
707 snd_seq_sync_output_queue(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
708 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
709 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
710 case SND_SEQ_EVENT_SYSEX:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
711 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
712 snd_seq_ev_set_variable(&ev, event->data.length, event->sysex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
713 ev.time.tick = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
714 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
715 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
716 snd_seq_sync_output_queue(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
717 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
718 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
719 case SND_SEQ_EVENT_TEMPO:
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
720 {
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
721 snd_seq_ev_set_fixed(&ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
722 ev.dest.client = SND_SEQ_CLIENT_SYSTEM;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
723 ev.dest.port = SND_SEQ_PORT_SYSTEM_TIMER;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
724 ev.data.queue.queue = sc.queue;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
725 ev.data.queue.param.value = event->data.tempo;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
726 pthread_mutex_lock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
727 midifile.current_tempo = event->data.tempo;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
728 pthread_mutex_unlock(&amidiplug_gettime_mutex);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
729 ev.time.tick = 0;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
730 snd_seq_event_output(sc.seq, &ev);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
731 snd_seq_drain_output(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
732 snd_seq_sync_output_queue(sc.seq);
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
733 break;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
734 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
735 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
736 }
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
737
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
738 midifile.skip_offset = playing_tick;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
739
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
740 return;
60c744f652f4 [svn] amidi-plug (MIDI through ALSA seq) input plugin added, brand new and completely written from scratch :)
giacomo
parents:
diff changeset
741 }