diff src/amidi-plug/amidi-plug.c @ 461:cfd1b8a88e2d trunk

[svn] - updated amidi-plug to the new plugin API
author giacomo
date Fri, 19 Jan 2007 04:46:00 -0800
parents 59d793da5395
children 8f1785471613
line wrap: on
line diff
--- a/src/amidi-plug/amidi-plug.c	Thu Jan 18 18:52:45 2007 -0800
+++ b/src/amidi-plug/amidi-plug.c	Fri Jan 19 04:46:00 2007 -0800
@@ -28,52 +28,67 @@
 }
 
 
-static gint amidiplug_is_our_file( gchar * filename )
+static gboolean amidiplug_detect_by_content( VFSFile * fp )
 {
-#if defined(MIDIFILE_PROBE_MAGICBYTES)
-    VFSFile * fp;
-    gchar magic_bytes[4];
+  gchar magic_bytes[4];
+  gint res = 0;
+
+  if ( fp == NULL )
+    return FALSE;
+
+  if ( VFS_FREAD( magic_bytes , 1 , 4 , fp ) != 4 )
+    return FALSE;
 
-    fp = VFS_FOPEN( filename , "rb" );
+  if ( !strncmp( magic_bytes , "MThd" , 4 ) )
+  {
+    DEBUGMSG( "MIDI found, %s is a standard midi file\n" , filename );
+    return TRUE;
+  }
 
-    if ( fp == NULL )
+  if ( !strncmp( magic_bytes , "RIFF" , 4 ) )
+  {
+    /* skip the four bytes after RIFF,
+       then read the next four */
+    if ( VFS_FSEEK( fp , 4 , SEEK_CUR ) != 0 )
       return FALSE;
 
-    VFS_FREAD( magic_bytes , 1 , 4 , fp );
+    if ( VFS_FREAD( magic_bytes , 1 , 4 , fp ) != 4 )
+      return FALSE;
 
-    if ( !strncmp( magic_bytes , "MThd" , 4 ) )
+    if ( !strncmp( magic_bytes , "RMID" , 4 ) )
     {
-      VFS_FCLOSE( fp );
-      DEBUGMSG( "MIDI found, %s is a standard midi file\n" , filename );
+      DEBUGMSG( "MIDI found, %s is a riff midi file\n" , filename );
       return TRUE;
     }
+  }
 
-    if ( !strncmp( magic_bytes , "RIFF" , 4 ) )
-    {
-      /* skip the four bytes after RIFF,
-         then read the next four */
-      VFS_FSEEK( fp , 4 , SEEK_CUR );
-      VFS_FREAD( magic_bytes , 1 , 4 , fp );
-      if ( !strncmp( magic_bytes , "RMID" , 4 ) )
-      {
-        VFS_FCLOSE( fp );
-        DEBUGMSG( "MIDI found, %s is a riff midi file\n" , filename );
-        return TRUE;
-      }
-    }
-    VFS_FCLOSE( fp );
-#else
-    gchar * ext = strrchr( filename, '.' );
-    /* check the filename extension */
-    if ( ( ext ) &&
-         (( !strcasecmp(ext,".mid") ) || ( !strcasecmp(ext,".midi") ) ||
-          ( !strcasecmp(ext,".rmi") ) || ( !strcasecmp(ext,".rmid") )) )
-      return TRUE;
-#endif
   return FALSE;
 }
 
 
+static gint amidiplug_is_our_file( gchar * filename )
+{
+  VFSFile * fp;
+  gboolean result = FALSE;
+
+  fp = VFS_FOPEN( filename , "rb" );
+
+  if ( fp == NULL )
+    return FALSE;
+
+  result = amidiplug_detect_by_content( fp );
+  VFS_FCLOSE( fp );
+
+  return result;
+}
+
+
+static gint amidiplug_is_our_file_from_vfs( gchar *filename , VFSFile *fp )
+{
+  return amidiplug_detect_by_content( fp );
+}
+
+
 static void amidiplug_init( void )
 {
   g_log_set_handler(NULL , G_LOG_LEVEL_WARNING , g_log_default_handler , NULL);