From bb02d97272068a051a5af12dee75aaa00fea0920 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Wed, 23 Mar 2022 22:57:26 +0100 Subject: [PATCH] - Add Layer support, - Add inital sample load, - Improve XML parsing functions, - No GFX and no Sound! --- drummer.c | 1400 ++++++++++++++++++++++++++++++++--------------------- drummer.h | 278 +++++++++-- go.sh | 2 +- 3 files changed, 1099 insertions(+), 581 deletions(-) diff --git a/drummer.c b/drummer.c index 17dbf1e..bfb7300 100644 --- a/drummer.c +++ b/drummer.c @@ -12,6 +12,308 @@ +/*---------------------------------------------------------------------------------*/ +/* */ +/*---------------------------------------------------------------------------------*/ + +NDT_Status DR_Layer_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node *Node_Ptr, NDT_Command Command, va_list *Args_Ptr) +{ + NDT_Command_Name Command_Name; + + + switch( Command) + { + case NDD_CMD_MANAGER_VERSION: + { + ND_VA_ARG_GET( Version_Name_Ptr, *Args_Ptr, NDT_Version_Name *); + + + Command_Name = "NDD_CMD_MANAGER_VERSION"; + + *Version_Name_Ptr = "$Revision: 1.0 $ $Name: Layer_Manager $ $Date: 2021/12/12 21:27:12 $ $Author: agibert $"; + + return( NDS_OK); + } + + case NDD_CMD_INDEX_GET: + { + ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); + ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); + ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); + ND_VA_ARG_GET( Layer_Ptr, *Args_Ptr, DRT_Layer *); + + + Command_Name = "NDD_CMD_INDEX_GET"; + + switch(Cmd) + { + case NDD_CMD_INDEX0_PRINT: + { + *Reply_Index_Id_Ptr = 0; + *Reply_Command_Ptr = Cmd; + break; + } + + case NDD_CMD_INDEX1_PRINT: + { + *Reply_Index_Id_Ptr = 1; + *Reply_Command_Ptr = Cmd; + break; + } + + default: + { + *Reply_Index_Id_Ptr = Index_Id; + *Reply_Command_Ptr = Cmd; + break; + } + } + + return( NDS_OK); + } + + case NDD_CMD_VALUE_ALLOC: + { + ND_VA_ARG_GET( Layer_Ptr_Ptr, *Args_Ptr, DRT_Layer **); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + ND_VA_ARG_GET( Layer_Template_Ptr, user_args, DRT_Layer *); + + ND_VA_LIST_CLOSE( user_args); + + + Command_Name = "NDD_CMD_VALUE_ALLOC"; + + if( ( *Layer_Ptr_Ptr = (DRT_Layer *)malloc( sizeof( DRT_Layer))) != NULL) + { + ( *Layer_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; + + strncpy( ( *Layer_Ptr_Ptr)->FileName, Layer_Template_Ptr->FileName, FILENAME_SIZE); + + ( *Layer_Ptr_Ptr)->Sample_Ptr = Layer_Template_Ptr->Sample_Ptr; + ( *Layer_Ptr_Ptr)->Sample_Size = Layer_Template_Ptr->Sample_Size; + ( *Layer_Ptr_Ptr)->Min = Layer_Template_Ptr->Min; + ( *Layer_Ptr_Ptr)->Max = Layer_Template_Ptr->Max; + ( *Layer_Ptr_Ptr)->Gain = Layer_Template_Ptr->Gain; + ( *Layer_Ptr_Ptr)->Pitch = Layer_Template_Ptr->Pitch; + + return( NDS_OK); + } + else + { + return( NDS_KO); + } + } + + case NDD_CMD_VALUE_FREE: + { + ND_VA_ARG_GET( Layer_Ptr, *Args_Ptr, DRT_Layer *); + + + Command_Name = "NDD_CMD_VALUE_FREE"; + + + free( Layer_Ptr); + + return( NDS_OK); + } + + case NDD_CMD_VALUE_COMP: + { + ND_VA_ARG_GET( Layer1_Ptr, *Args_Ptr, DRT_Layer *); + ND_VA_ARG_GET( Layer2_Ptr, *Args_Ptr, DRT_Layer *); + + long rc; + + + Command_Name = "NDD_CMD_VALUE_COMP"; + + switch( Index_Id) + { + case 0: + { + rc = Layer1_Ptr->Id - Layer2_Ptr->Id; + break; + } + + case 1: + { + rc = strcmp( Layer1_Ptr->FileName, Layer2_Ptr->FileName); + break; + } + + default: + { + printf( "Unknown COMP idx (%d) !\n", Index_Id); + return( NDS_KO); + } + } + + if( rc < 0) + { + return( NDS_LOWER); + } + else + { + if( rc > 0) + { + return( NDS_GREATER); + } + else + { + return( NDS_EQUAL); + } + } + } + + case NDD_CMD_VALUE_ADD: + { + /* + ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( user_data, user_args, user_type); + ND_VA_ARG_GET( ..., user_args, ...); + + ND_VA_LIST_CLOSE( user_args); + */ + + + Command_Name = "NDD_CMD_VALUE_ADD"; + + return( NDS_OK); + } + + case NDD_CMD_VALUE_REMOVE: + { + /* + ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( user_data, user_args, user_type); + ND_VA_ARG_GET( ..., user_args, ...); + + ND_VA_LIST_CLOSE( user_args); + */ + + + Command_Name = "NDD_CMD_VALUE_REMOVE"; + + return( NDS_OK); + } + + case NDD_CMD_VALUE_PRINT: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( lib_args, *Args_Ptr); + + ND_VA_ARG_GET( Out, lib_args, FILE *); + ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); + ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); + ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); + + ND_VA_LIST_OPEN( user_args, lib_args); + + ND_VA_ARG_GET( Count_Ptr, user_args, long *); + + ND_VA_LIST_CLOSE( user_args); + ND_VA_LIST_CLOSE( lib_args); + + DRT_Layer *Layer_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_VALUE_PRINT"; + + if( DR_Layer_Dump( Layer_Ptr, ++(*Count_Ptr)) != DRS_OK) + { + return( NDS_KO); + } + else + { + return( NDS_OK); + } + } + + case NDD_CMD_INFO_PRINT: + { + Command_Name = "NDD_CMD_INFO_PRINT"; + + return( NDS_OK); + + } + + case NDD_CMD_INDEX0_PRINT: + case NDD_CMD_INDEX1_PRINT: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( Out, user_args, FILE *); + ND_VA_ARG_GET( Count_Ptr, user_args, long *); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Layer *Layer_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_INDEX_PRINT"; + + if( DR_Layer_Dump( Layer_Ptr, ++(*Count_Ptr)) != DRS_OK) + { + return( NDS_KO); + } + else + { + return( NDS_OK); + } + } + + case NDD_CMD_SAMPLE_LOAD: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( Kit_Ptr, user_args, DRT_Kit *); + ND_VA_ARG_GET( SampleRate, user_args, double); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Layer *Layer_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_SAMPLE_LOAD"; + + if( DR_Layer_Sample_Load( Layer_Ptr, Kit_Ptr, SampleRate) != DRS_OK) + { + return( NDS_KO); + } + else + { + return( NDS_OK); + } + } + + default: + { + printf( "Layer_Manager() called with an undefined command %d\n", Command); + return( NDS_ERRAPI); + + } + } + + printf( "Layer_Manager() called with command %d (%s)\n", Command, Command_Name); + return( NDS_OK); +} + + + + + /*---------------------------------------------------------------------------------*/ /* */ /*---------------------------------------------------------------------------------*/ @@ -37,13 +339,6 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, case NDD_CMD_INDEX_GET: { - /* - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); - ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); - ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - */ - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); @@ -54,16 +349,6 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, switch(Cmd) { - /* - case NDT_CMD_SOME_USER_CMD: - { - *Reply_Index_Id_Ptr = 0; - *Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD; - break; - } - ... - */ - case NDD_CMD_INDEX0_PRINT: { *Reply_Index_Id_Ptr = 0; @@ -91,46 +376,38 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, case NDD_CMD_VALUE_ALLOC: { - /* - ND_VA_ARG_GET( Value_Ptr_Ptr, *Args_Ptr, void **); + ND_VA_ARG_GET( Instrument_Ptr_Ptr, *Args_Ptr, DRT_Instrument **); - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - ND_VA_ARG_GET( Instrument_Ptr_Ptr, *Args_Ptr, DRT_Instrument **); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - ND_VA_ARG_GET( Name, user_args, char *); - ND_VA_ARG_GET( FileName, user_args, char *); - ND_VA_ARG_GET( Gain, user_args, double); - ND_VA_ARG_GET( Sample_Ptr, user_args, char *); - ND_VA_ARG_GET( Sample_Size, user_args, long); + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + ND_VA_ARG_GET( Instrument_Template_Ptr, user_args, DRT_Instrument *); ND_VA_LIST_CLOSE( user_args); + NDT_Status nd_status; + Command_Name = "NDD_CMD_VALUE_ALLOC"; if( ( *Instrument_Ptr_Ptr = (DRT_Instrument *)malloc( sizeof( DRT_Instrument))) != NULL) { ( *Instrument_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - - strncpy( ( *Instrument_Ptr_Ptr)->Name, Name, NAME_LEN); - strncpy( ( *Instrument_Ptr_Ptr)->FileName, FileName, FILENAME_LEN); + + strncpy( ( *Instrument_Ptr_Ptr)->Name, Instrument_Template_Ptr->Name, NAME_SIZE); - (*Instrument_Ptr_Ptr)->Name[ NAME_LEN] = '\0'; - (*Instrument_Ptr_Ptr)->FileName[FILENAME_LEN] = '\0'; + ( *Instrument_Ptr_Ptr)->Gain = Instrument_Template_Ptr->Gain; + ( *Instrument_Ptr_Ptr)->Pan_Left = Instrument_Template_Ptr->Pan_Left; + ( *Instrument_Ptr_Ptr)->Pan_Right = Instrument_Template_Ptr->Pan_Right; - ( *Instrument_Ptr_Ptr)->Gain = Gain; - ( *Instrument_Ptr_Ptr)->Sample_Ptr = Sample_Ptr; - ( *Instrument_Ptr_Ptr)->Sample_Size = Sample_Size; - return( NDS_OK); + if( ( nd_status = ND_DataStruct_Open( &((*Instrument_Ptr_Ptr)->Layer_DS_Ptr), DRD_LAYER_DS_INDEX_NB, DRG_Layer_DS_Index_Tab_Initial, "Layer_Manager", DR_Layer_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) + { + printf( "DR_Instrument_Manager: ND_DataStruct_Open() failed (%d) !\n", nd_status); + return( NDS_KO); + } + else + { + return( NDS_OK); + } } else { @@ -140,22 +417,18 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, case NDD_CMD_VALUE_FREE: { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - ND_VA_ARG_GET( Instrument_Ptr, *Args_Ptr, DRT_Instrument *); + NDT_Status nd_status; + Command_Name = "NDD_CMD_VALUE_FREE"; + if( ( nd_status = ND_DataStruct_Close( Instrument_Ptr->Layer_DS_Ptr)) != NDS_OK) + { + printf( "DR_Instrument_Manager: Can't close Kit_DS (%d)!\n", nd_status); + return( DRS_KO); + } free( Instrument_Ptr); @@ -164,18 +437,6 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, case NDD_CMD_VALUE_COMP: { - /* - ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, void *); - ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - ND_VA_ARG_GET( Instrument1_Ptr, *Args_Ptr, DRT_Instrument *); ND_VA_ARG_GET( Instrument2_Ptr, *Args_Ptr, DRT_Instrument *); @@ -262,26 +523,6 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, case NDD_CMD_VALUE_PRINT: { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_OPEN( user_args, lib_args); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - - void *Value_Ptr = Node_Ptr->Value; - */ ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); ND_VA_LIST_OPEN( lib_args, *Args_Ptr); @@ -315,46 +556,35 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, case NDD_CMD_INFO_PRINT: { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); + ND_VA_ARG_GET( Out, lib_args, FILE *); + ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); + ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); + ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); + ND_VA_LIST_CLOSE( lib_args); - ND_VA_LIST_OPEN( user_args, lib_args); + NDT_Status nd_status; + DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); + + Command_Name = "NDD_CMD_INFO_PRINT"; - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - */ - - - Command_Name = "NDD_CMD_INFO_PRINT"; - - return( NDS_OK); + if( ( nd_status = ND_DataStruct_Info_Print( Out, Instrument_Ptr->Layer_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) + { + printf( "DR_Instrument_Manager: ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); + return( DRS_KO); + } + return( NDS_OK); } case NDD_CMD_INDEX0_PRINT: case NDD_CMD_INDEX1_PRINT: { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); ND_VA_LIST_OPEN( user_args, *Args_Ptr); @@ -378,40 +608,47 @@ NDT_Status DR_Instrument_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, return( NDS_OK); } } -/* - case NDD_CMD_PHONEBOOK_SAVE: - { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - ND_VA_LIST_OPEN( user_args, *Args_Ptr); + case NDD_CMD_STATS_GET: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); + ND_VA_LIST_OPEN( user_args, *Args_Ptr); - ND_VA_LIST_CLOSE( user_args); - */ -/* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, user_args, FILE *); - ND_VA_ARG_GET( Count_Ptr, user_args, long *); + ND_VA_ARG_GET( Instruments_Count_Ptr, user_args, long *); + ND_VA_ARG_GET( Layers_Count_Ptr, user_args, long *); ND_VA_LIST_CLOSE( user_args); DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; + + Command_Name = "NDD_CMD_STATS_GET"; - Command_Name = "NDD_CMD_PHONEBOOK_SAVE"; - - fprintf( Out, "%s:%s:%s:%s\n", Instrument_Ptr->Number, Instrument_Ptr->Name, Instrument_Ptr->Address, Instrument_Ptr->Email); - (*Count_Ptr)++; + (*Instruments_Count_Ptr)++; + (*Layers_Count_Ptr) += Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; return( NDS_OK); - } -*/ + } + + case NDD_CMD_SAMPLE_LOAD: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( Kit_Ptr, user_args, DRT_Kit *); + ND_VA_ARG_GET( SampleRate, user_args, double); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Instrument *Instrument_Ptr = Node_Ptr->Value; + + Command_Name = "NDD_CMD_SAMPLE_LOAD"; + + return( ND_DataStruct_Traverse( Instrument_Ptr->Layer_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)); + } + default: { printf( "Instrument_Manager() called with an undefined command %d\n", Command); @@ -453,13 +690,6 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod case NDD_CMD_INDEX_GET: { - /* - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); - ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); - ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - */ - ND_VA_ARG_GET( Reply_Index_Id_Ptr, *Args_Ptr, NDT_Index_Id *); ND_VA_ARG_GET( Reply_Command_Ptr, *Args_Ptr, NDT_Command *); ND_VA_ARG_GET( Cmd, *Args_Ptr, NDT_Command); @@ -508,25 +738,9 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod case NDD_CMD_VALUE_ALLOC: { - /* - ND_VA_ARG_GET( Value_Ptr_Ptr, *Args_Ptr, void **); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - - ND_VA_ARG_GET( Kit_Ptr_Ptr, *Args_Ptr, DRT_Kit **); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( Name, user_args, char *); - ND_VA_ARG_GET( Desc, user_args, char *); - ND_VA_ARG_GET( FileName, user_args, char *); - + ND_VA_ARG_GET( Kit_Ptr_Ptr, *Args_Ptr, DRT_Kit **); + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + ND_VA_ARG_GET( Kit_Template_Ptr, user_args, DRT_Kit *); ND_VA_LIST_CLOSE( user_args); NDT_Status nd_status; @@ -537,18 +751,14 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod if( ( *Kit_Ptr_Ptr = (DRT_Kit *)malloc( sizeof( DRT_Kit))) != NULL) { ( *Kit_Ptr_Ptr)->Id = Root_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; - - strncpy( ( *Kit_Ptr_Ptr)->Name, Name, NAME_LEN); - strncpy( ( *Kit_Ptr_Ptr)->Desc, Desc, DESC_LEN); - strncpy( ( *Kit_Ptr_Ptr)->FileName, FileName, FILENAME_LEN); - - (*Kit_Ptr_Ptr)->Name[ NAME_LEN] = '\0'; - (*Kit_Ptr_Ptr)->Desc[ DESC_LEN] = '\0'; - (*Kit_Ptr_Ptr)->FileName[FILENAME_LEN] = '\0'; + + strncpy( ( *Kit_Ptr_Ptr)->Name, Kit_Template_Ptr->Name, NAME_SIZE); + strncpy( ( *Kit_Ptr_Ptr)->Desc, Kit_Template_Ptr->Desc, DESC_SIZE); + strncpy( ( *Kit_Ptr_Ptr)->DirName, Kit_Template_Ptr->DirName, DIRNAME_SIZE); if( ( nd_status = ND_DataStruct_Open( &((*Kit_Ptr_Ptr)->Instrument_DS_Ptr), DRD_INSTRUMENT_DS_INDEX_NB, DRG_Instrument_DS_Index_Tab_Initial, "Instrument_Manager", DR_Instrument_Manager, NULL, NULL, NULL, NULL, NDD_TRUE, NULL)) != NDS_OK) { - printf( "DR_Instrument_Manager: ND_DataStruct_Open() failed (%d) !\n", nd_status); + printf( "DR_Kit_Manager: ND_DataStruct_Open() failed (%d) !\n", nd_status); return( NDS_KO); } @@ -562,17 +772,6 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod case NDD_CMD_VALUE_FREE: { - /* - ND_VA_ARG_GET( Value_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - ND_VA_ARG_GET( Kit_Ptr, *Args_Ptr, DRT_Kit *); NDT_Status nd_status; @@ -582,7 +781,7 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod if( ( nd_status = ND_DataStruct_Close( Kit_Ptr->Instrument_DS_Ptr)) != NDS_OK) { - printf( "Can't close Kit_DS (%d)!\n", nd_status); + printf( "DR_Kit_Manager: Can't close Kit_DS (%d)!\n", nd_status); return( DRS_KO); } @@ -593,18 +792,6 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod case NDD_CMD_VALUE_COMP: { - /* - ND_VA_ARG_GET( Value1_Ptr, *Args_Ptr, void *); - ND_VA_ARG_GET( Value2_Ptr, *Args_Ptr, void *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - ND_VA_ARG_GET( Kit1_Ptr, *Args_Ptr, DRT_Kit *); ND_VA_ARG_GET( Kit2_Ptr, *Args_Ptr, DRT_Kit *); @@ -691,27 +878,6 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod case NDD_CMD_VALUE_PRINT: { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_OPEN( user_args, lib_args); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - - void *Value_Ptr = Node_Ptr->Value; - */ - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); ND_VA_LIST_OPEN( lib_args, *Args_Ptr); @@ -745,25 +911,6 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod case NDD_CMD_INFO_PRINT: { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( lib_args, *Args_Ptr); - - ND_VA_ARG_GET( Out, lib_args, FILE *); - ND_VA_ARG_GET( Recursive_Mode, lib_args, NDT_Recursive_Mode); - ND_VA_ARG_GET( Recursive_Depth, lib_args, NDT_Recursive_Depth); - ND_VA_ARG_GET( Recursive_Offset, lib_args, NDT_Recursive_Offset); - - ND_VA_LIST_OPEN( user_args, lib_args); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - ND_VA_LIST_CLOSE( lib_args); - */ - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); ND_VA_LIST_OPEN( lib_args, *Args_Ptr); @@ -783,28 +930,16 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod if( ( nd_status = ND_DataStruct_Info_Print( Out, Kit_Ptr->Instrument_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) { - printf( "ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); + printf( "DR_Kit_Manager: ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); return( DRS_KO); } return( NDS_OK); - } case NDD_CMD_INDEX0_PRINT: case NDD_CMD_INDEX1_PRINT: { - /* - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); - - ND_VA_LIST_OPEN( user_args, *Args_Ptr); - - ND_VA_ARG_GET( user_data, user_args, user_type); - ND_VA_ARG_GET( ..., user_args, ...); - - ND_VA_LIST_CLOSE( user_args); - */ - ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); ND_VA_LIST_OPEN( user_args, *Args_Ptr); @@ -828,6 +963,47 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod return( NDS_OK); } } + + case NDD_CMD_STATS_GET: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( Kits_Count_Ptr, user_args, long *); + ND_VA_ARG_GET( Instruments_Count_Ptr, user_args, long *); + ND_VA_ARG_GET( Layers_Count_Ptr, user_args, long *); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Kit *Kit_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_STATS_GET"; + + (*Kits_Count_Ptr)++; + + return( ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_STATS_GET, Instruments_Count_Ptr, Layers_Count_Ptr)); + } + + case NDD_CMD_SAMPLE_LOAD: + { + ND_VA_ARG_GET( Next_Node_Ptr, *Args_Ptr, NDT_Node *); + + ND_VA_LIST_OPEN( user_args, *Args_Ptr); + + ND_VA_ARG_GET( SampleRate, user_args, double); + + ND_VA_LIST_CLOSE( user_args); + + DRT_Kit *Kit_Ptr = Node_Ptr->Value; + + + Command_Name = "NDD_CMD_SAMPLE_LOAD"; + + return( ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)); + } + /* case NDD_CMD_PHONEBOOK_SAVE: { @@ -877,15 +1053,188 @@ NDT_Status DR_Kit_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Nod /*---------------------------------------------------------------------------------*/ -/* DR_Instrument_Add */ +/* DR_Layer_Add */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_Instrument_Add( DRT_Instrument **Instrument_Ptr_Ptr, NDT_Root *DS_Ptr, char *Name, char *FileName, double Gain, char *Sample_Ptr, long Sample_Size) +DRT_Status DR_Layer_Add( DRT_Layer **Layer_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Layer *Layer_Template_Ptr) { NDT_Status nd_status; - if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Instrument_Ptr_Ptr, Name, FileName, Gain, Sample_Ptr, Sample_Size)) != NDS_OK) + if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Layer_Ptr_Ptr, Layer_Template_Ptr)) != NDS_OK) + { + printf( "Can't allocate new layer: ND_Value_Alloc() failed (%d) !\n", nd_status); + return( DRS_KO); + } + else + { + if( ( nd_status = ND_DataStruct_Value_Add( DS_Ptr, (void *)*Layer_Ptr_Ptr)) != NDS_OK) + { + printf( "Can't add new layer: ND_Value_Add() failed (%d) !\n", nd_status); + return( DRS_KO); + } + } + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Sample_Load( DRT_Layer *Layer_Ptr, DRT_Kit *Kit_Ptr, double SampleRate) +{ + DRT_Status status; + SNDFILE *sndf_ptr; + +// int load_sample(char* path, drmr_layer* layer, double target_rate) { +// long size; + + + fprintf( stderr, "Loading: [%s]\n", Layer_Ptr->FileName); + + if( ( Layer_Ptr->SF_Info_Ptr = malloc( sizeof(SF_INFO))) == NULL) + { + fprintf( stderr, "Can't allocate SF_Info buffer !\n"); + return( DRS_KO); + } + + if( ( sndf_ptr = sf_open( Layer_Ptr->FileName, SFM_READ, Layer_Ptr->SF_Info_Ptr)) == NULL) + { + fprintf( stderr, "Can't open sample file [%s] (%d)!\n", Layer_Ptr->FileName, sf_strerror( (SNDFILE *)( Layer_Ptr->Sample_Ptr))); + status = DRS_KO; + } + else + { + if( Layer_Ptr->SF_Info_Ptr->channels > 2) + { + fprintf(stderr, "Too many channels: Can only handle mono / stereo samples!\n"); + status = DRS_KO; + } + else + { + Layer_Ptr->Sample_Size = Layer_Ptr->SF_Info_Ptr->frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); + + if( ( Layer_Ptr->Sample_Ptr = malloc( Layer_Ptr->Sample_Size)) == NULL) + { + fprintf(stderr,"Can't allocate sample memory: (%d) for [%s]!\n", Layer_Ptr->Sample_Size, Layer_Ptr->FileName); + status = DRS_KO; + } + else + { + sf_read_float( sndf_ptr, Layer_Ptr->Sample_Ptr, ( Layer_Ptr->Sample_Size / sizeof( float))); + + status = DRS_OK; + + // convert rate if needed + if( Layer_Ptr->SF_Info_Ptr->samplerate != SampleRate) + { + int src_status; + SRC_DATA src_data; + long out_size; + float *data_out; + + + src_data.data_in = Layer_Ptr->Sample_Ptr; + src_data.input_frames = Layer_Ptr->SF_Info_Ptr->frames; + src_data.src_ratio = SampleRate / Layer_Ptr->SF_Info_Ptr->samplerate; + src_data.output_frames = (long)ceil( Layer_Ptr->SF_Info_Ptr->frames * src_data.src_ratio); + + out_size = src_data.output_frames * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); + + if( ( src_data.data_out = malloc( out_size)) == NULL) + { + fprintf(stderr,"Can't allocate resample memory: (%d) for [%s]!\n", out_size, Layer_Ptr->FileName); + status = DRS_KO; + } + else + { + + if( ( src_status = src_simple( &src_data, RATE_CONV_QUALITY, Layer_Ptr->SF_Info_Ptr->channels)) != 0) + { + fprintf( stderr,"Can't convert rate for [%s]: [%s]\n", Layer_Ptr->FileName, src_strerror( src_status)); + } + else + { + if( src_data.input_frames_used != Layer_Ptr->SF_Info_Ptr->frames) + { + fprintf(stderr,"Didn't consume all input frames. used: %li had: %li gened: %li\n", + src_data.input_frames_used, Layer_Ptr->SF_Info_Ptr->frames, src_data.output_frames_gen); + } + + free( Layer_Ptr->Sample_Ptr); + + Layer_Ptr->Sample_Ptr = data_out; + Layer_Ptr->Sample_Size = src_data.output_frames_gen * Layer_Ptr->SF_Info_Ptr->channels * sizeof( float); + Layer_Ptr->SF_Info_Ptr->samplerate = SampleRate; + Layer_Ptr->SF_Info_Ptr->frames = src_data.output_frames_gen; + } + + free( data_out); + } + } + } + } + + sf_close( sndf_ptr); + } + + free( Layer_Ptr->SF_Info_Ptr); + + return( status); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Sample_UnLoad */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Sample_UnLoad( DRT_Layer *Layer_Ptr) +{ +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Dump */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Dump( DRT_Layer *Layer_Ptr, long count) +{ + NDT_Status nd_status; + + + fprintf( stderr, " %03d) Layer: ", count); + fprintf( stderr, " Id: (% 3d) File Name: [%s] Sample: [%lx] Sample Size: (%d) Min: (%f) Max: (%f) Gain: (%f) Pitch: (%f)\n", + Layer_Ptr->Id, Layer_Ptr->FileName, Layer_Ptr->Sample_Ptr, Layer_Ptr->Sample_Size, Layer_Ptr->Min, Layer_Ptr->Max, Layer_Ptr->Gain, Layer_Ptr->Pitch); +// fprintf( stderr, "\n"); + + return( DRS_OK); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Instrument_Add */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Instrument_Add( DRT_Instrument **Instrument_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Instrument *Instrument_Template_Ptr) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Instrument_Ptr_Ptr, Instrument_Template_Ptr)) != NDS_OK) { printf( "Can't allocate new instrument: ND_Value_Alloc() failed (%d) !\n", nd_status); return( DRS_KO); @@ -894,7 +1243,7 @@ DRT_Status DR_Instrument_Add( DRT_Instrument **Instrument_Ptr_Ptr, NDT_Root * { if( ( nd_status = ND_DataStruct_Value_Add( DS_Ptr, (void *)*Instrument_Ptr_Ptr)) != NDS_OK) { - printf( "Can't add new kit: ND_Value_Add() failed (%d) !\n", nd_status); + printf( "Can't add new instrument: ND_Value_Add() failed (%d) !\n", nd_status); return( DRS_KO); } } @@ -910,15 +1259,34 @@ DRT_Status DR_Instrument_Add( DRT_Instrument **Instrument_Ptr_Ptr, NDT_Root * /* DR_Instrument_Dump */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_Instrument_Dump( DRT_Instrument *Instrument_Ptr, long count) +DRT_Status DR_Instrument_Dump( DRT_Instrument *Instrument_Ptr, long Count) { - NDT_Status nd_status; + NDT_Status nd_status; + long count2; - fprintf( stderr, " %03d) Instrument: ", count); - fprintf( stderr, " Id: (% 3d) Name: [%s] File Name: [%s] Gain: (%f) Sample: [%lx] Sample Size: (%d)\n", - Instrument_Ptr->Id, Instrument_Ptr->Name, Instrument_Ptr->FileName, Instrument_Ptr->Gain, Instrument_Ptr->Sample_Ptr, Instrument_Ptr->Sample_Size); + fprintf( stderr, " %03d) Instrument: ", Count); + fprintf( stderr, " Id: (% 3d) Name: [%s] Gain: (%f) Pan Left: (%f) Pan Right: (%f)\n", + Instrument_Ptr->Id, Instrument_Ptr->Name, Instrument_Ptr->Gain, Instrument_Ptr->Pan_Left, Instrument_Ptr->Pan_Right); // fprintf( stderr, "\n"); + fprintf( stderr, " Layer List:\n"); + + if( Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) + { + fprintf( stderr, " Empty list!\n"); + } + else + { + count2 = 0; + + if( ( nd_status = ND_DataStruct_Value_Print( stderr, Instrument_Ptr->Layer_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0, &count2)) != NDS_OK) + { + printf( "Cant't dump layers: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + } + + fprintf( stderr, "\n"); return( DRS_OK); } @@ -931,12 +1299,12 @@ DRT_Status DR_Instrument_Dump( DRT_Instrument *Instrument_Ptr, long count) /* DR_Kit_Add */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_Kit_Add( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, char *Name, char *Desc, char *FileName) +DRT_Status DR_Kit_Add( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, DRT_Kit *Kit_Template_Ptr) { NDT_Status nd_status; - if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Kit_Ptr_Ptr, Name, Desc, FileName)) != NDS_OK) + if( ( nd_status = ND_Value_Alloc( DS_Ptr, (void **)Kit_Ptr_Ptr, Kit_Template_Ptr)) != NDS_OK) { printf( "Can't allocate new kit: ND_Value_Alloc() failed (%d) !\n", nd_status); return( DRS_KO); @@ -957,19 +1325,41 @@ DRT_Status DR_Kit_Add( DRT_Kit **Kit_Ptr_Ptr, NDT_Root *DS_Ptr, char *Name, +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Sample_Load( DRT_Kit *Kit_Ptr, double SampleRate) +{ + NDT_Status nd_status; + + + if( ( nd_status = ND_DataStruct_Traverse( Kit_Ptr->Instrument_DS_Ptr, NDD_CMD_SAMPLE_LOAD, Kit_Ptr, SampleRate)) != NDS_OK) + { + printf( "Cant't load kit samples: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + return( DRS_OK); +} + + + + + /*---------------------------------------------------------------------------------*/ /* DR_Kit_Dump */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_Kit_Dump( DRT_Kit *Kit_Ptr, long count) +DRT_Status DR_Kit_Dump( DRT_Kit *Kit_Ptr, long Count) { NDT_Status nd_status; long count2; - fprintf( stderr, " %03d) DrumKit:", count); - fprintf( stderr, " Id: (% 3d) Name: [%s] Descrition: [%.32s] File Name: [%s]\n", Kit_Ptr->Id, Kit_Ptr->Name, Kit_Ptr->Desc, Kit_Ptr->FileName); + fprintf( stderr, " %03d) DrumKit:", Count); + fprintf( stderr, " Id: (% 3d) Name: [%s] Descrition: [%.32s] Dir Name: [%s]\n", Kit_Ptr->Id, Kit_Ptr->Name, Kit_Ptr->Desc, Kit_Ptr->DirName); fprintf( stderr, " Instruments List:\n"); if( Kit_Ptr->Instrument_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) @@ -997,34 +1387,10 @@ DRT_Status DR_Kit_Dump( DRT_Kit *Kit_Ptr, long count) /*---------------------------------------------------------------------------------*/ -/* DR_Kits_Load */ +/* DR_XML_Node_Exist */ /*---------------------------------------------------------------------------------*/ -void element_names_print( xmlNode *xml_node, int depth) -{ - xmlNode *xml_cur_node; - - - for( xml_cur_node = xml_node; xml_cur_node; xml_cur_node = xml_cur_node->next) - { - if( xml_cur_node->type == XML_ELEMENT_NODE) - { - printf( "% *cnode type: Element, name: %s\n", depth*2, ' ', xml_cur_node->name); - } - - element_names_print( xml_cur_node->children, depth + 1); - } -} - - - - - -/*---------------------------------------------------------------------------------*/ -/* DR_XML_Value_Get */ -/*---------------------------------------------------------------------------------*/ - -DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_XpathCtx, char *Xpath_Request) +DRT_Status DR_XML_Node_Exist( xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_XpathCtx, char *Xpath_Request) { DRT_Status status; xmlXPathObjectPtr xml_xpathobj; @@ -1035,7 +1401,7 @@ DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Do if( ( xml_xpathobj = xmlXPathEvalExpression( Xpath_Request, Xml_XpathCtx)) == NULL) { - fprintf( stderr, "xmlXPathEvalExpression failed!\n"); + fprintf( stderr, "DR_XML_Node_Exist: xmlXPathEvalExpression failed [%s]!\n", Xpath_Request); status = DRS_KO; } else @@ -1044,19 +1410,64 @@ DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Do if( xmlXPathNodeSetIsEmpty( nodeset)) { - fprintf( stderr, "[%s] not found!\n", Xpath_Request); +// fprintf( stderr, "[%s] not found!\n", Xpath_Request); + status = DRS_KO; + } + else + { +// fprintf( stderr, "[%s] found!\n", Xpath_Request); + status = DRS_OK; + } + } + + return( status); +} + + + + + +/*---------------------------------------------------------------------------------*/ +/* DR_XML_Value_Get */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_XpathCtx, char *Xpath_HeadRequest, char *Xpath_TailRequest) +{ + DRT_Status status; + xmlXPathObjectPtr xml_xpathobj; + xmlNodeSetPtr nodeset; + char *tmpval_ptr; + long tmpval_len; + char xpath_request[1024]; + + + strcpy( xpath_request, Xpath_HeadRequest); + strcat( xpath_request, Xpath_TailRequest); + + if( ( xml_xpathobj = xmlXPathEvalExpression( xpath_request, Xml_XpathCtx)) == NULL) + { + fprintf( stderr, "DR_XML_Value_Get: xmlXPathEvalExpression failed! [%s]\n", xpath_request); + status = DRS_KO; + } + else + { + nodeset = xml_xpathobj->nodesetval; + + if( xmlXPathNodeSetIsEmpty( nodeset)) + { + fprintf( stderr, "[%s] not found!\n", xpath_request); status = DRS_KO; } else { if( ( tmpval_ptr = xmlNodeListGetString( Xml_Doc, nodeset->nodeTab[0]->xmlChildrenNode, 1)) == NULL) { - fprintf( stderr, "[%s] value not found!\n", Xpath_Request); + fprintf( stderr, "[%s] value not found!\n", xpath_request); status = DRS_KO; } else { - fprintf( stderr, "[%s] = [%s] found!\n", nodeset->nodeTab[0]->name, tmpval_ptr); +// fprintf( stderr, "[%s] = [%s] found!\n", nodeset->nodeTab[0]->name, tmpval_ptr); if( ( tmpval_len = strlen( tmpval_ptr)) > Max_Len) { @@ -1082,67 +1493,111 @@ DRT_Status DR_XML_Value_Get( char *Value_Ptr, long Max_Len, xmlDocPtr Xml_Do /*---------------------------------------------------------------------------------*/ -/* DR_XML_Node_Exist */ +/* DR_XML_Query_Tab_Exec */ /*---------------------------------------------------------------------------------*/ -DRT_Status DR_XML_Node_Exist( xmlDocPtr Xml_Doc, xmlXPathContextPtr Xml_XpathCtx, char *Xpath_Request) +DRT_Status DR_XML_Query_Tab_Exec( void *Value_Ptr, xmlDocPtr XML_Doc, xmlXPathContextPtr XML_XpathCtx, char *Xpath_Head, DRT_XML_Query *XML_Query_Tab) { - DRT_Status status; - xmlXPathObjectPtr xml_xpathobj; - xmlNodeSetPtr nodeset; - char *tmpval_ptr; - long tmpval_len; - - - if( ( xml_xpathobj = xmlXPathEvalExpression( Xpath_Request, Xml_XpathCtx)) == NULL) - { - fprintf( stderr, "xmlXPathEvalExpression failed!\n"); - status = DRS_KO; - } - else - { - nodeset = xml_xpathobj->nodesetval; + DRT_Status status; + char reply_str[DESC_SIZE]; + int i; - if( xmlXPathNodeSetIsEmpty( nodeset)) + + i=0; + + while( XML_Query_Tab[i].XPath_Query != NULL) + { + if( ( status = DR_XML_Value_Get( reply_str, DESC_LEN, XML_Doc, XML_XpathCtx, Xpath_Head, XML_Query_Tab[i].XPath_Query)) != DRS_OK) { - fprintf( stderr, "[%s] not found!\n", Xpath_Request); - status = DRS_KO; + strcpy( reply_str, ""); } - else + + switch( XML_Query_Tab[i].Value_Type) { - fprintf( stderr, "[%s] found!\n", Xpath_Request); - status = DRS_OK; + case XML_QUERY_VALUE_STRING: + { + strncpy( ( Value_Ptr + XML_Query_Tab[i].Value_Offset), reply_str, XML_Query_Tab[i].Value_Len); + break; + } + + case XML_QUERY_VALUE_INT: + { + *( (int *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = atoi( reply_str); + break; + } + + case XML_QUERY_VALUE_LONG: + { + *( (long *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtol( reply_str, NULL, 10); + break; + } + + case XML_QUERY_VALUE_LONGLONG: + { + *( (long long *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtoll( reply_str, NULL, 10); + break; + } + + case XML_QUERY_VALUE_FLOAT: + { + *( (float *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtof( reply_str, NULL); + break; + } + + case XML_QUERY_VALUE_DOUBLE: + { + *( (double *)( Value_Ptr + XML_Query_Tab[i].Value_Offset)) = strtod( reply_str, NULL); + break; + } + + default: + { + fprintf( stderr, "Unknown valute type: (%d)\n", XML_Query_Tab[i].Value_Type); + break; + } } + + i++; } - return( status); + return( DRS_OK); } - /*---------------------------------------------------------------------------------*/ /* DR_Kit_Load */ /*---------------------------------------------------------------------------------*/ DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) { - DRT_Status status; - NDT_Status nd_status; - DRT_Kit kit_template; - DRT_Kit *kit_ptr; - DRT_Instrument instrument_template; - DRT_Instrument *instrument_ptr; - char tmp_str[256]; - char xpath_instrument[256]; - char xpath_value[256]; - xmlDocPtr xml_doc; - xmlXPathContextPtr xml_xpathCtx; - xmlXPathObjectPtr xml_xpathObj; - int i; + DRT_Status status; + NDT_Status nd_status; + + DRT_Kit kit_template; + DRT_Kit *kit_ptr; + DRT_Instrument instrument_template; + DRT_Instrument *instrument_ptr; + DRT_Layer layer_template; + DRT_Layer *layer_ptr; + + xmlDocPtr xml_doc; + xmlXPathContextPtr xml_xpathCtx; + xmlXPathObjectPtr xml_xpathObj; + + char tmp_filename[FILENAME_SIZE]; + char xpath_head[1024]; + char reply_str[256]; + + int instrument, layer; + short i; + layer_template.Sample_Ptr = NULL; + layer_template.Sample_Size = 0; + + fprintf( stderr, "Loading: [%s]...\n", FileName); if( strlen( FileName) > FILENAME_LEN) @@ -1152,9 +1607,10 @@ DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) } else { - strcpy( kit_template.FileName, FileName); + strcpy( tmp_filename, FileName); + strcpy( kit_template.DirName, dirname(tmp_filename)); - if( ( xml_doc = xmlParseFile( kit_template.FileName)) == NULL) + if( ( xml_doc = xmlParseFile( FileName)) == NULL) { fprintf( stderr, "xml_doc failed!\n"); status = DRS_KO; @@ -1180,73 +1636,66 @@ DRT_Status DR_Kit_Load( DRT_Base *Base_Ptr, char *FileName) } else { - if( ( status = DR_XML_Value_Get( kit_template.Name, NAME_LEN, xml_doc, xml_xpathCtx, XML_XPATH_DRUMKIT_KIT_NAME_FULL)) != DRS_OK) - { - fprintf( stderr, "Name not found!\n"); - } - else if( DR_XML_Value_Get( kit_template.Desc, DESC_LEN, xml_doc, xml_xpathCtx, XML_XPATH_DRUMKIT_KIT_INFO_FULL) != DRS_OK) - { - fprintf( stderr, "Info not found!\n"); - strcpy( kit_template.Desc, ""); - } - - if( ( status = DR_Kit_Add( &kit_ptr, Base_Ptr->Kit_DS_Ptr, kit_template.Name, kit_template.Desc, kit_template.FileName)) != DRS_OK) + DR_XML_Query_Tab_Exec( &kit_template, xml_doc, xml_xpathCtx, XML_XPATH_DRUMKIT_BASE_STR, DRG_XML_Query_Tab_Kit); + + if( ( status = DR_Kit_Add( &kit_ptr, Base_Ptr->Kit_DS_Ptr, &kit_template)) != DRS_OK) { fprintf( stderr, "Can't create a new kit!\n"); } else { - fprintf( stderr, "New kit!\n"); +// fprintf( stderr, "New kit!\n"); status = DRS_OK; - i = 1; + instrument = 1; while( ( status == DRS_OK) - && ( sprintf( xpath_instrument, XML_XPATH_DRUMKIT_INSTRUMENT_FULL, i) > 0) - && ( DR_XML_Node_Exist( xml_doc, xml_xpathCtx, xpath_instrument) == DRS_OK)) + && ( sprintf( xpath_head, XML_XPATH_DRUMKIT_INSTRUMENT_FULL, instrument) > 0) + && ( DR_XML_Node_Exist( xml_doc, xml_xpathCtx, xpath_head) == DRS_OK)) { - strcpy( xpath_value, xpath_instrument); -// strcat( xpath_value, "/drumkit:id"); - strcat( xpath_value, XML_XPATH_DRUMKIT_ID_STR); - - if( ( status = DR_XML_Value_Get( tmp_str, 256, xml_doc, xml_xpathCtx, xpath_value)) != DRS_OK) + instrument_template.Id = -1; + + DR_XML_Query_Tab_Exec( &instrument_template, xml_doc, xml_xpathCtx, xpath_head, DRG_XML_Query_Tab_Instrument); + + if( instrument_template.Id == -1) { fprintf( stderr, "Instrument id not found!\n"); } else { - instrument_template.Id = atoi( tmp_str); - - strcpy( xpath_value, xpath_instrument); -// strcat( xpath_value, "/drumkit:name"); - strcat( xpath_value, XML_XPATH_DRUMKIT_NAME_STR); - - if( ( status = DR_XML_Value_Get( instrument_template.Name, NAME_LEN, xml_doc, xml_xpathCtx, xpath_value)) != DRS_OK) - { - fprintf( stderr, "Instrument name not found!\n"); - strcpy( instrument_template.Name, ""); - status = DRS_OK; - } - - strcpy( xpath_value, xpath_instrument); - strcat( xpath_value, XML_XPATH_DRUMKIT_LAYER_FILENAME_STR); - - if( ( status = DR_XML_Value_Get( instrument_template.FileName, FILENAME_LEN, xml_doc, xml_xpathCtx, xpath_value)) != DRS_OK) - { - fprintf( stderr, "Instrument file name not found!\n"); - strcpy( instrument_template.FileName, ""); - status = DRS_OK; - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, instrument_template.Name, instrument_template.FileName, 1.01, NULL, 0)) != DRS_OK) + if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, &instrument_template)) != DRS_OK) { fprintf( stderr, "Can't create a new instrument!\n"); } else { - fprintf( stderr, "New Instrument!\n"); - i++; +// fprintf( stderr, "New Instrument!\n"); + } + + layer = 1; + while( ( status == DRS_OK) + && ( sprintf( xpath_head, XML_XPATH_DRUMKIT_LAYER_FULL, instrument, layer) > 0) + && ( DR_XML_Node_Exist( xml_doc, xml_xpathCtx, xpath_head) == DRS_OK)) + { + DR_XML_Query_Tab_Exec( &layer_template, xml_doc, xml_xpathCtx, xpath_head, DRG_XML_Query_Tab_Layer); + + strcpy( tmp_filename, kit_template.DirName); + strcat( tmp_filename, "/"); + strcat( tmp_filename, layer_template.FileName); + strcpy( layer_template.FileName, tmp_filename); + + if( ( status = DR_Layer_Add( &layer_ptr, instrument_ptr->Layer_DS_Ptr, &layer_template)) != DRS_OK) + { + fprintf( stderr, "Can't create a new layer!\n"); + } + else + { +// fprintf( stderr, "New layer!\n"); + layer++; + } } } + + instrument++; } } } @@ -1313,170 +1762,25 @@ DRT_Status DR_Kits_Load( DRT_Base *Base_Ptr) } globfree( &glob_struct); - + + Base_Ptr->SampleRate=44100; + +/* + status = DR_Layer_Sample_Load( (DRT_Layer *)( + ((DRT_Instrument *)( + ((DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value)) + ->Instrument_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value)) + ->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), + (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), Base_Ptr->SampleRate); +*/ + status = DR_Kit_Sample_Load( (DRT_Kit *)(Base_Ptr->Kit_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Head->Value), + Base_Ptr->SampleRate); + return( status); } - -/* - if( ( xml_xpathObj = xmlXPathEvalExpression( "/drumkit:drumkit_info/drumkit:name", xml_xpathCtx)) == NULL) - { - fprintf( stderr, "xmlXPathEvalExpression failed!\n"); - status = DRS_KO; - } - else - { - xmlNodeSetPtr nodeset = xml_xpathObj->nodesetval; - - if( !xmlXPathNodeSetIsEmpty( xml_xpathObj->nodesetval)) - { - fprintf( stderr, "Name [%s] found!\n", nodeset->nodeTab[0]->name); - - int i; - char *keyword; - - for( i=0; i < nodeset->nodeNr; i++) - { - keyword = xmlNodeListGetString( xml_doc, nodeset->nodeTab[i]->xmlChildrenNode, 1); - printf( "keyword: %s\n", keyword); - xmlFree( keyword); - } - } - - DRT_Status DR_XML_Value_Get( char **Value_Ptr_Ptr, xmlDocPtr Xml_Doc, xmlXPathContextPtr xml_xpathCtx, char *Xpath_Request) - { - xmlXPathObjectPtr xml_xpathobj; - xmlNodeSetPtr nodeset; - - - if( ( xml_xpathobj = xmlXPathEvalExpression( "/drumkit:drumkit_info/drumkit:name", xml_xpathCtx)) == NULL) - { - fprintf( stderr, "xmlXPathEvalExpression failed!\n"); - status = DRS_KO; - } - else - { - nodeset = xml_xpathobj->nodesetval; - - if( !xmlXPathNodeSetIsEmpty( nodeset)) - { - (*Value_Ptr_Ptr) = xmlNodeListGetString( Xml_Doc, nodeset->nodeTab[0]->xmlChildrenNode, 1); - - fprintf( stderr, "[%s] = [%s] found!\n", nodeset->nodeTab[0]->name, *Value_Ptr_Ptr); - } - } - - xmlXPathFreeObject(xml_xpathObj); - status = DRS_OK; - } - -/* - xmlNodeSetPtr nodes = xml_xpathObj->nodesetval; - xmlNodePtr cur; - int size; - int i; - size = (nodes) ? nodes->nodeNr : 0; - - fprintf( stderr, "Result (%d nodes):\n", size); - - for( i = 0; i < size; ++i) - { - assert( nodes->nodeTab[i]); - - if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) - { - xmlNsPtr ns; - - ns = (xmlNsPtr)nodes->nodeTab[i]; - cur = (xmlNodePtr)ns->next; - - if(cur->ns) - { - fprintf( stderr, "= namespace \"%s\"=\"%s\" for node %s:%s\n", ns->prefix, ns->href, cur->ns->href, cur->name); - } - else - { - fprintf( stderr, "= namespace \"%s\"=\"%s\" for node %s\n", ns->prefix, ns->href, cur->name); - } - } - else - { - if( nodes->nodeTab[i]->type == XML_ELEMENT_NODE) - { - cur = nodes->nodeTab[i]; - - if(cur->ns) - { - fprintf( stderr, "= element node \"%s:%s\"\n", cur->ns->href, cur->name); - } - else - { - fprintf( stderr, "= element node \"%s\"\n", cur->name); - } - } - else - { - cur = nodes->nodeTab[i]; - fprintf( stderr, "= node \"%s\": type %d\n", cur->name, cur->type); - } - } - } -*/ -/* - - if( ( status = DR_Kit_Add( &kit_ptr, Base_Ptr->Kit_DS_Ptr, "Kit number one", "This is the best drumkit!", "/tmp/toto.xml")) != DRS_OK) - { - return( status); - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, "Instrument 1.1", "/tmp/instrument-1.1.wav", 1.01, NULL, 0)) != DRS_OK) - { - return( status); - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, "Instrument 1.2", "/tmp/instrument-1.2.wav", 2.01, NULL, 0)) != DRS_OK) - { - return( status); - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, "Instrument 1.3", "/tmp/instrument-1.3.wav", 0.02, NULL, 0)) != DRS_OK) - { - return( status); - } - - - if( ( status = DR_Kit_Add( &kit_ptr, Base_Ptr->Kit_DS_Ptr, "Kit number two", "This is a good drumkit.", "/tmp/titi.xml")) != DRS_OK) - { - return( status); - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, "Instrument 2.1", "/tmp/instrument-2.1.wav", 1.01, NULL, 0)) != DRS_OK) - { - return( status); - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, "Instrument 2.2", "/tmp/instrument-2.2.wav", 2.01, NULL, 0)) != DRS_OK) - { - return( status); - } - - if( ( status = DR_Instrument_Add( &instrument_ptr, kit_ptr->Instrument_DS_Ptr, "Instrument 2.3", "/tmp/instrument-2.3.wav", 0.02, NULL, 0)) != DRS_OK) - { - return( status); - } - - - if( ( status = DR_Kit_Add( &kit_ptr, Base_Ptr->Kit_DS_Ptr, "Kit number three", "This is not the the best drum kit...", "/tmp/tata.xml")) != DRS_OK) - { - return( status); - } -*/ - - - - /*---------------------------------------------------------------------------------*/ @@ -1488,17 +1792,20 @@ DRT_Status DR_Kits_Dump( DRT_Base *Base_Ptr) NDT_Status nd_status; short index; long count = 0; + long kits_count = 0; + long instruments_count = 0; + long layers_count = 0; + fprintf( stderr, "\n"); fprintf( stderr, "DrumKit List:\n"); - +/* if( ( nd_status = ND_DataStruct_Info_Print( stderr, Base_Ptr->Kit_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)) != NDS_OK) { printf( "ND_DataStruct_Info_Print() failed (%d) !\n", nd_status); return( DRS_KO); } -/* for( index = 0; index < Base_Ptr->Kit_DS_Ptr->Index_Nb; index++) { count = 0; @@ -1520,12 +1827,21 @@ DRT_Status DR_Kits_Dump( DRT_Base *Base_Ptr) fprintf( stderr, "\n"); } */ + if( ( nd_status = ND_DataStruct_Value_Print( stderr, Base_Ptr->Kit_DS_Ptr, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0, &count)) != NDS_OK) { printf( "Can't dump kits: ND_DataStruct_Value_Print() failed (%d) !\n", nd_status); return( DRS_KO); } + if( ( nd_status = ND_DataStruct_Traverse( Base_Ptr->Kit_DS_Ptr, NDD_CMD_STATS_GET, &kits_count, &instruments_count, &layers_count)) != NDS_OK) + { + printf( "Can't compute stats: ND_DataStruct_Traverse() failed (%d) !\n", nd_status); + return( DRS_KO); + } + + fprintf( stderr, "Number of Kits: (%ld) Number of Instruments: (%ld) Number of Layers: (%ld)\n", kits_count, instruments_count, layers_count); + return( DRS_OK); } diff --git a/drummer.h b/drummer.h index 577c8d2..f9d009f 100644 --- a/drummer.h +++ b/drummer.h @@ -12,16 +12,22 @@ #include #include #include +#include +#include #include +#include + #include #include #include #include -#include -#include +#include +#include + + @@ -42,11 +48,16 @@ typedef short DRT_Boolean; #define DRD_MAX(A,B) (((A) < (B)) ? (B) : (A)) #define DRD_MIN(A,B) (((A) > (B)) ? (B) : (A)) -#define NDD_CMD_INDEX0_PRINT ( NDT_Command) 65 -#define NDD_CMD_INDEX1_PRINT ( NDT_Command) 66 +#define NDD_CMD_STATS_GET ( NDT_Command) 65 +#define NDD_CMD_SAMPLE_LOAD ( NDT_Command) 66 +#define NDD_CMD_SAMPLE_UNLOAD ( NDT_Command) 67 +#define NDD_CMD_INDEX0_PRINT ( NDT_Command) 68 +#define NDD_CMD_INDEX1_PRINT ( NDT_Command) 69 #define NAME_LEN (short) 256 #define NAME_SIZE (NAME_LEN + 1) +#define DIRNAME_LEN (short) 1024 +#define DIRNAME_SIZE (DIRNAME_LEN) #define FILENAME_LEN (short) 1024 #define FILENAME_SIZE (FILENAME_LEN) #define DESC_LEN (short) 2048 @@ -60,7 +71,7 @@ typedef short DRT_Boolean; /* Status definition */ /*----------------------------------------------------------------------------*/ -typedef short DRT_Status; +typedef short DRT_Status; #define DRS_OK ( DRT_Status) 0 @@ -77,7 +88,27 @@ typedef short DRT_Status; /*----------------------------------------------------------------------------*/ -/* Kit_DS Indexes */ +/* Layer_DS Indexes */ +/*----------------------------------------------------------------------------*/ + +#define DRD_LAYER_DS_INDEX_NB (short)2 + +static NDT_Index_Type DRG_Layer_DS_Index_Tab_Initial[DRD_LAYER_DS_INDEX_NB] = +{ + (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED), + (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_SORTED) +}; + +static NDT_Index_Type DRG_Layer_DS_Index_Tab_Final[DRD_LAYER_DS_INDEX_NB] = +{ + (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED), + (NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED) +}; + + + +/*----------------------------------------------------------------------------*/ +/* Instrument_DS Indexes */ /*----------------------------------------------------------------------------*/ #define DRD_INSTRUMENT_DS_INDEX_NB (short)2 @@ -122,46 +153,89 @@ static NDT_Index_Type DRG_Kit_DS_Index_Tab_Final[DRD_KIT_DS_INDEX_NB] = /* XML XPATH Tags */ /*---------------------------------------------------------------------------------*/ -#define STR(A) #A -#define TAG(A) STR(A) +#define STR(A) #A +#define TAG(A) STR(A) -#define XML_XPATH_ELEMENT(A) *[local-name()=(A)] +#define XML_XPATH_ELEMENT(A) *[local-name()=(A)] +#define XML_SLASH / -#define XML_XPATH_DRUMKIT_BASE_TAG XML_XPATH_ELEMENT('drumkit_info') -#define XML_XPATH_DRUMKIT_NAME_TAG XML_XPATH_ELEMENT('name') -#define XML_XPATH_DRUMKIT_INFO_TAG XML_XPATH_ELEMENT('info') -#define XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG XML_XPATH_ELEMENT('instrumentList') -#define XML_XPATH_DRUMKIT_INSTRUMENT_TAG XML_XPATH_ELEMENT('instrument') -#define XML_XPATH_DRUMKIT_ID_TAG XML_XPATH_ELEMENT('id') -#define XML_XPATH_DRUMKIT_INSTRUMENTCOMPONENT_TAG XML_XPATH_ELEMENT('instrumentComponent') -#define XML_XPATH_DRUMKIT_LAYER_TAG XML_XPATH_ELEMENT('layer') -#define XML_XPATH_DRUMKIT_FILENAME_TAG XML_XPATH_ELEMENT('filename') +#define XML_XPATH_DRUMKIT_BASE_TAG XML_XPATH_ELEMENT('drumkit_info') +#define XML_XPATH_DRUMKIT_NAME_TAG XML_XPATH_ELEMENT('name') +#define XML_XPATH_DRUMKIT_INFO_TAG XML_XPATH_ELEMENT('info') +#define XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG XML_XPATH_ELEMENT('instrumentList') +#define XML_XPATH_DRUMKIT_INSTRUMENT_TAG XML_XPATH_ELEMENT('instrument') +#define XML_XPATH_DRUMKIT_ID_TAG XML_XPATH_ELEMENT('id') +#define XML_XPATH_DRUMKIT_GAIN_TAG XML_XPATH_ELEMENT('gain') +#define XML_XPATH_DRUMKIT_PAN_LEFT_TAG XML_XPATH_ELEMENT('pan_L') +#define XML_XPATH_DRUMKIT_PAN_RIGHT_TAG XML_XPATH_ELEMENT('pan_R') +#define XML_XPATH_DRUMKIT_INSTRUMENTCOMPONENT_TAG XML_XPATH_ELEMENT('instrumentComponent') +#define XML_XPATH_DRUMKIT_LAYER_TAG XML_XPATH_ELEMENT('layer') +#define XML_XPATH_DRUMKIT_FILENAME_TAG XML_XPATH_ELEMENT('filename') +#define XML_XPATH_DRUMKIT_MIN_TAG XML_XPATH_ELEMENT('min') +#define XML_XPATH_DRUMKIT_MAX_TAG XML_XPATH_ELEMENT('max') +#define XML_XPATH_DRUMKIT_PITCH_TAG XML_XPATH_ELEMENT('pitch') -#define XML_XPATH_DRUMKIT_BASE_STR TAG(/XML_XPATH_DRUMKIT_BASE_TAG) -#define XML_XPATH_DRUMKIT_ID_STR TAG(/XML_XPATH_DRUMKIT_ID_TAG) -#define XML_XPATH_DRUMKIT_NAME_STR TAG(/XML_XPATH_DRUMKIT_NAME_TAG) -#define XML_XPATH_DRUMKIT_LAYER_FILENAME_STR TAG(/XML_XPATH_DRUMKIT_INSTRUMENTCOMPONENT_TAG/XML_XPATH_DRUMKIT_LAYER_TAG[1]/XML_XPATH_DRUMKIT_FILENAME_TAG) +#define XML_XPATH_DRUMKIT_BASE_STR TAG(/XML_XPATH_DRUMKIT_BASE_TAG) +#define XML_XPATH_DRUMKIT_NAME_STR TAG(/XML_XPATH_DRUMKIT_NAME_TAG) +#define XML_XPATH_DRUMKIT_INFO_STR TAG(/XML_XPATH_DRUMKIT_INFO_TAG) +#define XML_XPATH_DRUMKIT_ID_STR TAG(/XML_XPATH_DRUMKIT_ID_TAG) +#define XML_XPATH_DRUMKIT_GAIN_STR TAG(/XML_XPATH_DRUMKIT_GAIN_TAG) +#define XML_XPATH_DRUMKIT_PAN_LEFT_STR TAG(/XML_XPATH_DRUMKIT_PAN_LEFT_TAG) +#define XML_XPATH_DRUMKIT_PAN_RIGHT_STR TAG(/XML_XPATH_DRUMKIT_PAN_RIGHT_TAG) +#define XML_XPATH_DRUMKIT_FILENAME_STR TAG(/XML_XPATH_DRUMKIT_FILENAME_TAG) +#define XML_XPATH_DRUMKIT_MIN_STR TAG(/XML_XPATH_DRUMKIT_MIN_TAG) +#define XML_XPATH_DRUMKIT_MAX_STR TAG(/XML_XPATH_DRUMKIT_MAX_TAG) +#define XML_XPATH_DRUMKIT_PITCH_STR TAG(/XML_XPATH_DRUMKIT_PITCH_TAG) -#define XML_XPATH_DRUMKIT_KIT_NAME_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_NAME_TAG) -#define XML_XPATH_DRUMKIT_KIT_INFO_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INFO_TAG) -#define XML_XPATH_DRUMKIT_INSTRUMENT_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]) +#define XML_XPATH_DRUMKIT_KIT_NAME_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_NAME_TAG) +#define XML_XPATH_DRUMKIT_KIT_INFO_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INFO_TAG) +#define XML_XPATH_DRUMKIT_INSTRUMENT_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]) +#define XML_XPATH_DRUMKIT_LAYER_FULL2 TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]/XML_XPATH_DRUMKIT_INSTRUMENTCOMPONENT_TAG/XML_XPATH_DRUMKIT_LAYER_TAG[%i]) +#define XML_XPATH_DRUMKIT_LAYER_FULL TAG(/XML_XPATH_DRUMKIT_BASE_TAG/XML_XPATH_DRUMKIT_INSTRUMENTLIST_TAG/XML_XPATH_DRUMKIT_INSTRUMENT_TAG[%i]XML_SLASH/XML_XPATH_DRUMKIT_LAYER_TAG[%i]) + + + + +/*---------------------------------------------------------------------------------*/ +/* LibSamplerate */ +/*---------------------------------------------------------------------------------*/ + +// Quality of conversion for libsamplerate. +// See http://www.mega-nerd.com/SRC/api_misc.html#Converters +// for info about availble qualities +#define RATE_CONV_QUALITY SRC_SINC_MEDIUM_QUALITY /*---------------------------------------------------------------------------------*/ -/* TypeDefs */ +/* Layer / Instrument / Kit */ /*---------------------------------------------------------------------------------*/ +typedef struct DRT_Layer +{ + short Id; + char FileName[ FILENAME_SIZE]; + float *Sample_Ptr; + long Sample_Size; + SF_INFO *SF_Info_Ptr; + double Min; + double Max; + double Gain; + double Pitch; +} DRT_Layer; + + + typedef struct DRT_Instrument { - short Id; - char Name[ NAME_SIZE]; - char FileName[ FILENAME_SIZE]; - double Gain; - char *Sample_Ptr; - long Sample_Size; + short Id; + char Name[ NAME_SIZE]; + double Gain; + double Pan_Left; + double Pan_Right; + NDT_Root *Layer_DS_Ptr; } DRT_Instrument; @@ -169,9 +243,9 @@ typedef struct DRT_Instrument typedef struct DRT_Kit { short Id; - char Name[ NAME_SIZE]; - char Desc[ DESC_SIZE]; - char FileName[ FILENAME_SIZE]; + char Name[ NAME_SIZE]; + char Desc[ DESC_SIZE]; + char DirName[ DIRNAME_SIZE]; NDT_Root *Instrument_DS_Ptr; } DRT_Kit; @@ -187,12 +261,67 @@ typedef struct DRT_Library typedef struct DRT_Base { NDT_Root *Kit_DS_Ptr; + double SampleRate; } DRT_Base; +/*---------------------------------------------------------------------------------*/ +/* XML_Query */ +/*---------------------------------------------------------------------------------*/ + +#define XML_QUERY_VALUE_UNKNOWN (short) 0 +#define XML_QUERY_VALUE_STRING (short) 1 +#define XML_QUERY_VALUE_INT (short) 2 +#define XML_QUERY_VALUE_LONG (short) 3 +#define XML_QUERY_VALUE_LONGLONG (short) 4 +#define XML_QUERY_VALUE_FLOAT (short) 5 +#define XML_QUERY_VALUE_DOUBLE (short) 6 + +typedef struct DRT_XML_Query +{ + char *Query_Name; + char *XPath_Query; + short Value_Type; + long Value_Offset; + short Value_Len; +} DRT_XML_Query; + + + +DRT_XML_Query DRG_XML_Query_Tab_Layer[] = +{ + { "File Name", XML_XPATH_DRUMKIT_FILENAME_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Layer, FileName), FILENAME_LEN }, + { "Min", XML_XPATH_DRUMKIT_MIN_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Min), 0 }, + { "Max", XML_XPATH_DRUMKIT_MAX_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Max), 0 }, + { "Gain", XML_XPATH_DRUMKIT_GAIN_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Gain), 0 }, + { "Pitch", XML_XPATH_DRUMKIT_PITCH_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Layer, Pitch), 0 }, + { NULL, NULL, XML_QUERY_VALUE_UNKNOWN, 0, 0 } +}; + +DRT_XML_Query DRG_XML_Query_Tab_Instrument[] = +{ + { "Id", XML_XPATH_DRUMKIT_ID_STR, XML_QUERY_VALUE_LONG, offsetof( DRT_Instrument, Id), 0 }, + { "Name", XML_XPATH_DRUMKIT_NAME_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Instrument, Name), NAME_LEN }, + { "Gain", XML_XPATH_DRUMKIT_GAIN_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Instrument, Gain), 0 }, + { "Pan_Left", XML_XPATH_DRUMKIT_PAN_LEFT_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Instrument, Pan_Left), 0 }, + { "Pan_Right", XML_XPATH_DRUMKIT_PAN_RIGHT_STR, XML_QUERY_VALUE_DOUBLE, offsetof( DRT_Instrument, Pan_Right), 0 }, + { NULL, NULL, XML_QUERY_VALUE_UNKNOWN, 0, 0 } +}; + +DRT_XML_Query DRG_XML_Query_Tab_Kit[] = +{ + { "File", XML_XPATH_DRUMKIT_NAME_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Kit, Name), NAME_LEN }, + { "Desc", XML_XPATH_DRUMKIT_INFO_STR, XML_QUERY_VALUE_STRING, offsetof( DRT_Kit, Desc), DESC_LEN }, + { NULL, NULL, XML_QUERY_VALUE_UNKNOWN, 0, 0 } +}; + + + + + /*----------------------------------------------------------------------------*/ /* Prototypes */ /*----------------------------------------------------------------------------*/ @@ -201,8 +330,41 @@ typedef struct DRT_Base /* DS Managers */ /*---------------------------------------------------------------------------------*/ +NDT_Status DR_Layer_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); NDT_Status DR_Instrument_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); -NDT_Status DR_Kit_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); +NDT_Status DR_Kit_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Add */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Add( DRT_Layer **, NDT_Root *, DRT_Layer *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Sample_Load( DRT_Layer *, DRT_Kit *, double); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Sample_UnLoad */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Sample_UnLoad( DRT_Layer *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Layer_Dump */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Layer_Dump( DRT_Layer *, long); @@ -210,7 +372,7 @@ NDT_Status DR_Kit_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, /* DR_Instrument_Add */ /*----------------------------------------------------------------------------*/ -DRT_Status DR_Instrument_Add( DRT_Instrument **, NDT_Root *, char *, char *, double, char *, long); +DRT_Status DR_Instrument_Add( DRT_Instrument **, NDT_Root *, DRT_Instrument *); @@ -226,7 +388,15 @@ DRT_Status DR_Instrument_Dump( DRT_Instrument *, long); /* DR_Kit_Add */ /*----------------------------------------------------------------------------*/ -DRT_Status DR_Kit_Add( DRT_Kit **, NDT_Root *, char *, char *, char *); +DRT_Status DR_Kit_Add( DRT_Kit **, NDT_Root *, DRT_Kit *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Sample_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Sample_Load( DRT_Kit *, double); @@ -238,6 +408,38 @@ DRT_Status DR_Kit_Dump( DRT_Kit *, long); +/*---------------------------------------------------------------------------------*/ +/* DR_XML_Node_Exist */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_XML_Node_Exist( xmlDocPtr, xmlXPathContextPtr, char *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_XML_Query_Tab_Exec */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_XML_Query_Tab_Exec( void *, xmlDocPtr, xmlXPathContextPtr, char *, DRT_XML_Query *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_XML_Value_Get */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_XML_Value_Get( char *, long, xmlDocPtr, xmlXPathContextPtr, char *, char *); + + + +/*---------------------------------------------------------------------------------*/ +/* DR_Kit_Load */ +/*---------------------------------------------------------------------------------*/ + +DRT_Status DR_Kit_Load( DRT_Base *, char *); + + + /*----------------------------------------------------------------------------*/ /* DR_Kits_Load */ /*----------------------------------------------------------------------------*/ diff --git a/go.sh b/go.sh index 76523ca..d3b5646 100755 --- a/go.sh +++ b/go.sh @@ -2,5 +2,5 @@ gcc -g -c -I . -o libnode.o libnode.c #gcc -g -I . -L . -shared -o drummer.so -fPIC drummer.c -gcc -g -I. -I/usr/include/libxml2 -o drummer -fPIC libnode.o -ldl -lxml2 -lz -llzma -lm drummer.c +gcc -g -I. -I/usr/include/libxml2 -o drummer -fPIC libnode.o -ldl -lxml2 -lz -llzma -lm -lsndfile -lsamplerate drummer.c #gcc -g -I. -I/usr/include/libxml2 -o xpath -fPIC -ldl -lxml2 -lz -llzma -lm xpath.c