1 /*
2  * libInstPatch
3  * Copyright (C) 1999-2014 Element Green <element@elementsofsound.org>
4  *
5  * Author of this file: (C) 2012 BALATON Zoltan <balaton@eik.bme.hu>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; version 2.1
10  * of the License only.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA or on the web at http://www.gnu.org.
21  */
22 /**
23  * SECTION: IpatchSLIFile
24  * @short_description: Spectralis file object
25  * @see_also:
26  *
27  * A #IpatchFile object type for Spectralis instrument and instrument collection
28  * files.
29  */
30 #include <string.h>
31 #include <glib.h>
32 #include <glib-object.h>
33 #include "IpatchSLIFile.h"
34 #include "IpatchSLIFile_priv.h"
35 #include "ipatch_priv.h"
36 
37 static gboolean ipatch_sli_file_identify(IpatchFile *file,
38         IpatchFileHandle *handle, GError **err);
39 
G_DEFINE_TYPE(IpatchSLIFile,ipatch_sli_file,IPATCH_TYPE_FILE)40 G_DEFINE_TYPE(IpatchSLIFile, ipatch_sli_file, IPATCH_TYPE_FILE)
41 
42 
43 /* Spectralis file class init function */
44 static void
45 ipatch_sli_file_class_init(IpatchSLIFileClass *klass)
46 {
47     IpatchFileClass *file_class = IPATCH_FILE_CLASS(klass);
48 
49     file_class->identify = ipatch_sli_file_identify;
50 }
51 
52 static void
ipatch_sli_file_init(IpatchSLIFile * file)53 ipatch_sli_file_init(IpatchSLIFile *file)
54 {
55 }
56 
57 /* Spectralis file identification method */
58 static gboolean
ipatch_sli_file_identify(IpatchFile * file,IpatchFileHandle * handle,GError ** err)59 ipatch_sli_file_identify(IpatchFile *file, IpatchFileHandle *handle, GError **err)
60 {
61     guint32 buf[3];
62     char *filename;
63     int len;
64 
65     if(handle)    /* Test content */
66     {
67         if(!ipatch_file_read(handle, buf, 12, err))
68         {
69             return (FALSE);
70         }
71 
72         if(buf[0] == IPATCH_SLI_FOURCC_SIFI && buf[2] == 0x100)
73         {
74             return (TRUE);
75         }
76     }  /* Test file name extension */
77     else if((filename = ipatch_file_get_name(file)))      /* ++ alloc file name */
78     {
79         len = strlen(filename);
80 
81         if(len >= 4 &&
82                 (g_ascii_strcasecmp(filename + len - 4, ".slc") == 0 ||
83                  g_ascii_strcasecmp(filename + len - 4, ".sli") == 0))
84         {
85             g_free(filename);         /* -- free file name */
86             return (TRUE);
87         }
88 
89         g_free(filename);         /* -- free file name */
90     }
91 
92     return (FALSE);
93 }
94 
95 /**
96  * ipatch_sli_file_new:
97  *
98  * Create a new Spectralis file object.
99  *
100  * Returns: New Spectralis file object (derived from IpatchFile) with a
101  * reference count of 1. Caller owns the reference and removing it will
102  * destroy the item.
103  */
104 IpatchSLIFile *
ipatch_sli_file_new(void)105 ipatch_sli_file_new(void)
106 {
107     return (IPATCH_SLI_FILE(g_object_new(IPATCH_TYPE_SLI_FILE, NULL)));
108 }
109