2024-04-14 16:17:19 +02:00
/*----------------------------------------------------------------------------*/
2024-04-21 20:16:18 +02:00
/* datastruct.c */
2024-04-14 16:17:19 +02:00
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* This file is part of Drummer. */
/* */
/* Drummer is free software: you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* Drummer is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with Drummer. If not, see <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
2024-04-21 20:16:18 +02:00
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
# define _DATASTRUCT_C_
# include <drummer.h>
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
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 ;
2022-04-21 01:27:08 +02:00
strncpy ( ( * Layer_Ptr_Ptr ) - > FileName , Layer_Template_Ptr - > FileName , DRD_FILENAME_SIZE ) ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
( * Layer_Ptr_Ptr ) - > Sample_Ptr = Layer_Template_Ptr - > Sample_Ptr ;
( * Layer_Ptr_Ptr ) - > Sample_Size = Layer_Template_Ptr - > Sample_Size ;
( * Layer_Ptr_Ptr ) - > SF_Info_Ptr = Layer_Template_Ptr - > SF_Info_Ptr ;
( * 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 ;
( * Layer_Ptr_Ptr ) - > Instrument_Ptr = Layer_Template_Ptr - > Instrument_Ptr ;
2022-03-27 11:33:37 +02:00
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 " ;
2022-04-20 12:37:32 +02:00
DR_Layer_Sample_UnLoad ( Layer_Ptr ) ;
2022-03-27 11:33:37 +02:00
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 :
{
2022-04-21 01:27:08 +02:00
printf ( " Unknown COMP idx (%d)! \n " , Index_Id ) ;
2022-03-27 11:33:37 +02:00
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_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 ( Layer_Count_Ptr , user_args , long * ) ;
ND_VA_ARG_GET ( Sample_Count_Ptr , user_args , long * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Layer * Layer_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_STATS_GET " ;
( * Layer_Count_Ptr ) + + ;
if ( Layer_Ptr - > Sample_Ptr ! = NULL )
{
( * Sample_Count_Ptr ) + + ;
}
return ( NDS_OK ) ;
}
case NDD_CMD_SAMPLE_LOAD :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
2022-04-27 23:13:33 +02:00
DRT_Layer * Layer_Ptr = Node_Ptr - > Value ;
DRT_Status status ;
2022-03-27 11:33:37 +02:00
Command_Name = " NDD_CMD_SAMPLE_LOAD " ;
2022-04-27 23:13:33 +02:00
if ( Layer_Ptr - > Instrument_Ptr - > Kit_Ptr - > Base_Ptr - > Task_Load_Layer_Flag = = DRD_TRUE )
{
2022-05-14 23:53:23 +02:00
status = DR_Task_Run ( DRD_TASK_CMD_LAYER_LOAD , ( void * ) Layer_Ptr ) ;
2022-04-27 23:13:33 +02:00
}
else
{
status = DR_Layer_Sample_Load ( Layer_Ptr ) ;
}
if ( status ! = DRS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-21 01:27:08 +02:00
return ( NDS_OK ) ; // Continue even if sample loading fail...
2022-03-27 11:33:37 +02:00
}
else
{
return ( NDS_OK ) ;
}
}
2022-04-20 12:37:32 +02:00
case NDD_CMD_SAMPLE_UNLOAD :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
2022-04-27 23:13:33 +02:00
2022-04-20 12:37:32 +02:00
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Kit_Ptr , user_args , DRT_Kit * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Layer * Layer_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_SAMPLE_UNLOAD " ;
if ( DR_Layer_Sample_UnLoad ( Layer_Ptr ) ! = DRS_OK )
{
2022-04-21 01:27:08 +02:00
return ( NDS_OK ) ; // Continue even if sample unloading fail...
2022-04-20 12:37:32 +02:00
}
else
{
return ( NDS_OK ) ;
}
}
default :
2022-03-27 11:33:37 +02:00
{
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 ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
NDT_Status DR_Instrument_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: Instrument_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 ( Instrument_Ptr , * Args_Ptr , DRT_Instrument * ) ;
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 ( Instrument_Ptr_Ptr , * Args_Ptr , DRT_Instrument * * ) ;
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 ;
2022-04-21 01:27:08 +02:00
strncpy ( ( * Instrument_Ptr_Ptr ) - > Name , Instrument_Template_Ptr - > Name , DRD_NAME_SIZE ) ;
2022-03-27 11:33:37 +02:00
( * 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 ;
2022-04-27 23:13:33 +02:00
( * Instrument_Ptr_Ptr ) - > Kit_Ptr = Instrument_Template_Ptr - > Kit_Ptr ;
2022-03-27 11:33:37 +02:00
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 )
{
2022-04-21 01:27:08 +02:00
printf ( " DR_Instrument_Manager: ND_DataStruct_Open() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
}
else
{
return ( NDS_KO ) ;
}
}
case NDD_CMD_VALUE_FREE :
{
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 ) ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_COMP :
{
ND_VA_ARG_GET ( Instrument1_Ptr , * Args_Ptr , DRT_Instrument * ) ;
ND_VA_ARG_GET ( Instrument2_Ptr , * Args_Ptr , DRT_Instrument * ) ;
long rc ;
Command_Name = " NDD_CMD_VALUE_COMP " ;
switch ( Index_Id )
{
case 0 :
{
rc = Instrument1_Ptr - > Id - Instrument2_Ptr - > Id ;
break ;
}
case 1 :
{
rc = strcmp ( Instrument1_Ptr - > Name , Instrument2_Ptr - > Name ) ;
break ;
}
default :
{
2022-04-21 01:27:08 +02:00
printf ( " Unknown COMP idx (%d)! \n " , Index_Id ) ;
2022-03-27 11:33:37 +02:00
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_Instrument * Instrument_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_VALUE_PRINT " ;
if ( DR_Instrument_Dump ( Instrument_Ptr , + + ( * Count_Ptr ) ) ! = DRS_OK )
{
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
}
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_CLOSE ( lib_args ) ;
NDT_Status nd_status ;
DRT_Instrument * Instrument_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_INFO_PRINT " ;
if ( ( nd_status = ND_DataStruct_Info_Print ( Out , Instrument_Ptr - > Layer_DS_Ptr , NDD_RECURSIVE_MODE_PARENT_CHILD , 0 , 0 ) ) ! = NDS_OK )
{
2022-04-21 01:27:08 +02:00
printf ( " DR_Instrument_Manager: ND_DataStruct_Info_Print() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
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 ( Out , user_args , FILE * ) ;
ND_VA_ARG_GET ( Count_Ptr , user_args , long * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Instrument * Instrument_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_INDEX_PRINT " ;
if ( DR_Instrument_Dump ( Instrument_Ptr , + + ( * Count_Ptr ) ) ! = DRS_OK )
{
return ( NDS_KO ) ;
}
else
{
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 ( Instrument_Count_Ptr , user_args , long * ) ;
ND_VA_ARG_GET ( Layer_Count_Ptr , user_args , long * ) ;
ND_VA_ARG_GET ( Sample_Count_Ptr , user_args , long * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Instrument * Instrument_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_STATS_GET " ;
( * Instrument_Count_Ptr ) + + ;
// (*Layers_Count_Ptr) += Instrument_Ptr->Layer_DS_Ptr->Index_Tab[NDD_INDEX_PRIMARY].Node_Number;
// return( NDS_OK);
return ( ND_DataStruct_Traverse ( Instrument_Ptr - > Layer_DS_Ptr , NDD_CMD_STATS_GET , Layer_Count_Ptr , Sample_Count_Ptr ) ) ;
}
case NDD_CMD_SAMPLE_LOAD :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
DRT_Instrument * Instrument_Ptr = Node_Ptr - > Value ;
2022-04-27 23:13:33 +02:00
DRT_Status status ;
2022-03-27 11:33:37 +02:00
Command_Name = " NDD_CMD_SAMPLE_LOAD " ;
2022-04-27 23:13:33 +02:00
if ( Instrument_Ptr - > Kit_Ptr - > Base_Ptr - > Task_Load_Instrument_Flag = = DRD_TRUE )
{
2022-05-14 23:53:23 +02:00
status = DR_Task_Run ( DRD_TASK_CMD_INSTRUMENT_LOAD , ( void * ) Instrument_Ptr ) ;
2022-04-27 23:13:33 +02:00
}
else
{
status = DR_Instrument_Sample_Load ( Instrument_Ptr ) ;
}
if ( status ! = DRS_OK )
{
return ( NDS_OK ) ; // Continue even if sample loading fail...
}
else
{
return ( NDS_OK ) ;
}
2022-03-27 11:33:37 +02:00
}
2022-04-20 12:37:32 +02:00
case NDD_CMD_SAMPLE_UNLOAD :
{
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_LIST_CLOSE ( user_args ) ;
DRT_Instrument * Instrument_Ptr = Node_Ptr - > Value ;
2022-04-27 23:13:33 +02:00
2022-04-20 12:37:32 +02:00
Command_Name = " NDD_CMD_SAMPLE_UNLOAD " ;
2022-04-27 23:13:33 +02:00
if ( DR_Instrument_Sample_UnLoad ( Instrument_Ptr ) ! = DRS_OK )
{
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
// return( ND_DataStruct_Traverse( Instrument_Ptr->Layer_DS_Ptr, NDD_CMD_SAMPLE_UNLOAD, Kit_Ptr));
2022-04-20 12:37:32 +02:00
}
2022-03-27 11:33:37 +02:00
default :
{
printf ( " Instrument_Manager() called with an undefined command %d \n " , Command ) ;
return ( NDS_ERRAPI ) ;
}
}
printf ( " Instrument_Manager() called with command %d (%s) \n " , Command , Command_Name ) ;
return ( NDS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
NDT_Status DR_Kit_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: Kit_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 ( Kit_Ptr , * Args_Ptr , DRT_Kit * ) ;
Command_Name = " NDD_CMD_INDEX_GET " ;
switch ( Cmd )
{
/*
case NDT_CMD_SOME_USER_CMD :
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = NDD_CMD_SOME_OTHER_CMD ;
break ;
}
. . .
*/
2022-04-20 12:37:32 +02:00
case NDD_CMD_VALUE_FIND :
{
2022-04-27 23:13:33 +02:00
if ( Kit_Ptr - > Id ! = DRD_ID_UNKNOWN )
2022-04-20 12:37:32 +02:00
{
* Reply_Index_Id_Ptr = 0 ;
}
else
{
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "IDX 1!\n");
2022-04-20 12:37:32 +02:00
* Reply_Index_Id_Ptr = 1 ;
}
* Reply_Command_Ptr = Cmd ;
break ;
}
case NDD_CMD_INDEX0_PRINT :
2022-03-27 11:33:37 +02:00
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = Cmd ;
break ;
}
case NDD_CMD_VALUE_PRINT :
case NDD_CMD_INDEX1_PRINT :
2022-04-27 23:13:33 +02:00
{
* Reply_Index_Id_Ptr = 0 ;
* Reply_Command_Ptr = Cmd ;
break ;
}
case NDD_CMD_ID_REFRESH :
2022-03-27 11:33:37 +02:00
{
* 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 ( 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 ;
Command_Name = " NDD_CMD_VALUE_ALLOC " ;
if ( ( * Kit_Ptr_Ptr = ( DRT_Kit * ) malloc ( sizeof ( DRT_Kit ) ) ) ! = NULL )
{
2022-04-27 23:13:33 +02:00
( * Kit_Ptr_Ptr ) - > Id = Root_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
( * Kit_Ptr_Ptr ) - > Logical_Id = Kit_Template_Ptr - > Logical_Id ;
( * Kit_Ptr_Ptr ) - > Status = Kit_Template_Ptr - > Status ;
2022-03-27 11:33:37 +02:00
2022-04-21 01:27:08 +02:00
strncpy ( ( * Kit_Ptr_Ptr ) - > Name , Kit_Template_Ptr - > Name , DRD_NAME_SIZE ) ;
strncpy ( ( * Kit_Ptr_Ptr ) - > Desc , Kit_Template_Ptr - > Desc , DRD_DESC_SIZE ) ;
strncpy ( ( * Kit_Ptr_Ptr ) - > DirName , Kit_Template_Ptr - > DirName , DRD_DIRNAME_SIZE ) ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
( * Kit_Ptr_Ptr ) - > Base_Ptr = Kit_Template_Ptr - > Base_Ptr ;
2022-03-27 11:33:37 +02:00
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 )
{
2022-04-21 01:27:08 +02:00
printf ( " DR_Kit_Manager: ND_DataStruct_Open() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( NDS_KO ) ;
}
return ( NDS_OK ) ;
}
else
{
return ( NDS_KO ) ;
}
}
case NDD_CMD_VALUE_FREE :
{
ND_VA_ARG_GET ( Kit_Ptr , * Args_Ptr , DRT_Kit * ) ;
NDT_Status nd_status ;
Command_Name = " NDD_CMD_VALUE_FREE " ;
if ( ( nd_status = ND_DataStruct_Close ( Kit_Ptr - > Instrument_DS_Ptr ) ) ! = NDS_OK )
{
printf ( " DR_Kit_Manager: Can't close Kit_DS (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
free ( Kit_Ptr ) ;
return ( NDS_OK ) ;
}
case NDD_CMD_VALUE_COMP :
{
ND_VA_ARG_GET ( Kit1_Ptr , * Args_Ptr , DRT_Kit * ) ;
ND_VA_ARG_GET ( Kit2_Ptr , * Args_Ptr , DRT_Kit * ) ;
long rc ;
Command_Name = " NDD_CMD_VALUE_COMP " ;
switch ( Index_Id )
{
case 0 :
{
rc = Kit1_Ptr - > Id - Kit2_Ptr - > Id ;
break ;
}
case 1 :
{
2022-04-27 23:13:33 +02:00
if ( ( Kit1_Ptr - > Name [ 0 ] ! = 0 ) & & ( Kit2_Ptr - > Name [ 0 ] ! = 0 ) )
{
rc = strcmp ( Kit1_Ptr - > Name , Kit2_Ptr - > Name ) ;
}
else
{
rc = Kit1_Ptr - > Logical_Id - Kit2_Ptr - > Logical_Id ;
// fprintf( stderr, "Comp: (%ld) - (%ld) = (%ld)\n", Kit1_Ptr->Logical_Id, Kit2_Ptr->Logical_Id, rc);
}
2022-03-27 11:33:37 +02:00
break ;
}
default :
{
2022-04-21 01:27:08 +02:00
printf ( " Unknown COMP idx (%d)! \n " , Index_Id ) ;
2022-03-27 11:33:37 +02:00
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_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_VALUE_PRINT " ;
2022-04-27 23:13:33 +02:00
/*
fprintf ( stderr , " CurId: (%03ld) " , Kit_Ptr - > Id ) ;
fprintf ( stderr , " ParentId: " ) ;
if ( Node_Ptr - > Parent = = NULL )
{
fprintf ( stderr , " NULL " ) ;
}
else
{
fprintf ( stderr , " (%03ld) " , ( ( DRT_Kit * ) Node_Ptr - > Parent - > Value ) - > Id ) ;
}
fprintf ( stderr , " LeftId: " ) ;
if ( Node_Ptr - > Left = = NULL )
{
fprintf ( stderr , " NULL " ) ;
}
else
{
fprintf ( stderr , " (%03ld) " , ( ( DRT_Kit * ) Node_Ptr - > Left - > Value ) - > Id ) ;
}
fprintf ( stderr , " RightId: " ) ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
if ( Node_Ptr - > Right = = NULL )
{
fprintf ( stderr , " NULL " ) ;
}
else
{
fprintf ( stderr , " (%03ld) " , ( ( DRT_Kit * ) Node_Ptr - > Right - > Value ) - > Id ) ;
}
fprintf ( stderr , " \n " ) ;
return ( NDS_OK ) ;
*/
2022-03-27 11:33:37 +02:00
if ( DR_Kit_Dump ( Kit_Ptr , + + ( * Count_Ptr ) ) ! = DRS_OK )
{
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
}
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_CLOSE ( lib_args ) ;
NDT_Status nd_status ;
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_INFO_PRINT " ;
if ( ( nd_status = ND_DataStruct_Info_Print ( Out , Kit_Ptr - > Instrument_DS_Ptr , NDD_RECURSIVE_MODE_PARENT_CHILD , 0 , 0 ) ) ! = NDS_OK )
{
2022-04-21 01:27:08 +02:00
printf ( " DR_Kit_Manager: ND_DataStruct_Info_Print() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
return ( NDS_OK ) ;
}
2022-04-27 23:13:33 +02:00
case NDD_CMD_GRAPH_PRINT :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_GRAPH_PRINT " ;
fprintf ( stderr , " node%03ld [ label = \" <f0> | <f1> %03ld \\ n%20s | <f2> \" ]; \n " , Kit_Ptr - > Id , Kit_Ptr - > Id , Kit_Ptr - > Name ) ;
if ( Node_Ptr - > Left ! = NULL )
{
fprintf ( stderr , " node%03ld:f0 -> node%03ld:f1; \n " , Kit_Ptr - > Id , ( ( DRT_Kit * ) Node_Ptr - > Left - > Value ) - > Id ) ;
}
if ( Node_Ptr - > Right ! = NULL )
{
fprintf ( stderr , " node%03ld:f2 -> node%03ld:f1; \n " , Kit_Ptr - > Id , ( ( DRT_Kit * ) Node_Ptr - > Right - > Value ) - > Id ) ;
}
fprintf ( stderr , " \n " ) ;
return ( NDS_OK ) ;
}
2022-03-27 11:33:37 +02:00
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_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_INDEX_PRINT " ;
if ( DR_Kit_Dump ( Kit_Ptr , + + ( * Count_Ptr ) ) ! = DRS_OK )
{
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
}
2022-04-27 23:13:33 +02:00
case NDD_CMD_ID_REFRESH :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
ND_VA_LIST_OPEN ( user_args , * Args_Ptr ) ;
ND_VA_ARG_GET ( Count_Ptr , user_args , DRT_Kit_Id * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_ID_REFRESH " ;
Kit_Ptr - > Logical_Id = ( * Count_Ptr ) + + ;
return ( NDS_OK ) ;
}
2022-03-27 11:33:37 +02:00
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 ( Kit_Count_Ptr , user_args , long * ) ;
ND_VA_ARG_GET ( Instrument_Count_Ptr , user_args , long * ) ;
ND_VA_ARG_GET ( Layer_Count_Ptr , user_args , long * ) ;
ND_VA_ARG_GET ( Sample_Count_Ptr , user_args , long * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_STATS_GET " ;
( * Kit_Count_Ptr ) + + ;
return ( ND_DataStruct_Traverse ( Kit_Ptr - > Instrument_DS_Ptr , NDD_CMD_STATS_GET , Instrument_Count_Ptr , Layer_Count_Ptr , Sample_Count_Ptr ) ) ;
}
case NDD_CMD_SAMPLE_LOAD :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
2022-04-27 23:13:33 +02:00
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
DRT_Status status ;
2022-03-27 11:33:37 +02:00
Command_Name = " NDD_CMD_SAMPLE_LOAD " ;
2022-04-27 23:13:33 +02:00
if ( Kit_Ptr - > Base_Ptr - > Task_Load_Kit_Flag = = DRD_TRUE )
{
2022-05-14 23:53:23 +02:00
status = DR_Task_Run ( DRD_TASK_CMD_KIT_LOAD , ( void * ) Kit_Ptr ) ;
2022-04-27 23:13:33 +02:00
}
else
{
status = DR_Kit_Sample_Load ( Kit_Ptr ) ;
}
if ( status ! = DRS_OK )
2022-04-21 01:27:08 +02:00
{
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
}
case NDD_CMD_SAMPLE_UNLOAD :
{
ND_VA_ARG_GET ( Next_Node_Ptr , * Args_Ptr , NDT_Node * ) ;
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_SAMPLE_UNLOAD " ;
if ( DR_Kit_Sample_UnLoad ( Kit_Ptr ) ! = DRS_OK )
{
return ( NDS_KO ) ;
}
else
{
return ( NDS_OK ) ;
}
2022-03-27 11:33:37 +02:00
}
/*
case NDD_CMD_PHONEBOOK_SAVE :
{
2022-04-20 12:37:32 +02:00
*/ /*
2022-03-27 11:33:37 +02:00
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 ) ;
ND_VA_ARG_GET ( Out , user_args , FILE * ) ;
ND_VA_ARG_GET ( Count_Ptr , user_args , long * ) ;
ND_VA_LIST_CLOSE ( user_args ) ;
DRT_Kit * Kit_Ptr = Node_Ptr - > Value ;
Command_Name = " NDD_CMD_PHONEBOOK_SAVE " ;
fprintf ( Out , " %s:%s:%s:%s \n " , Kit_Ptr - > Number , Kit_Ptr - > Name , Kit_Ptr - > Address , Kit_Ptr - > Email ) ;
( * Count_Ptr ) + + ;
return ( NDS_OK ) ;
}
*/
default :
{
printf ( " Kit_Manager() called with an undefined command %d \n " , Command ) ;
return ( NDS_ERRAPI ) ;
}
}
printf ( " Kit_Manager() called with command %d (%s) \n " , Command , Command_Name ) ;
return ( NDS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Layer_Add */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Layer_Add ( DRT_Layer * * Layer_Ptr_Ptr , NDT_Root * DS_Ptr , DRT_Layer * Layer_Template_Ptr )
{
NDT_Status nd_status ;
2023-08-17 19:45:24 +02:00
if ( ( nd_status = ND_Value_Alloc ( ( void * * ) Layer_Ptr_Ptr , DS_Ptr , Layer_Template_Ptr ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-21 01:27:08 +02:00
printf ( " Can't allocate new layer: ND_Value_Alloc() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
else
{
if ( ( nd_status = ND_DataStruct_Value_Add ( DS_Ptr , ( void * ) * Layer_Ptr_Ptr ) ) ! = NDS_OK )
{
2022-04-21 01:27:08 +02:00
printf ( " Can't add new layer: ND_Value_Add() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
}
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-27 23:13:33 +02:00
/* DR_Layer_Sample_Load */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
DRT_Status DR_Layer_Sample_Load ( DRT_Layer * Layer_Ptr )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
DRT_Status status ;
SNDFILE * sndf_ptr ;
2022-05-14 23:53:23 +02:00
DRT_SampleRate samplerate = DRG_Base . SampleRate ;
2022-03-27 11:33:37 +02:00
2022-04-21 01:27:08 +02:00
// fprintf( stderr, "Loading: [%s]\n", Layer_Ptr->FileName);
2022-03-27 11:33:37 +02:00
2022-04-20 12:37:32 +02:00
if ( Layer_Ptr - > SF_Info_Ptr ! = NULL )
{
if ( Layer_Ptr - > Sample_Ptr ! = NULL )
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Skiping: [%s] \n " , Layer_Ptr - > FileName ) ;
2022-04-20 12:37:32 +02:00
return ( DRS_OK ) ;
}
else
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Freeing SF_Info: [%s] \n " , Layer_Ptr - > FileName ) ;
2022-04-20 12:37:32 +02:00
free ( Layer_Ptr - > SF_Info_Ptr ) ;
}
}
else
{
if ( Layer_Ptr - > Sample_Ptr ! = NULL )
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Freeing Sample: [%s] \n " , Layer_Ptr - > FileName ) ;
2022-04-20 12:37:32 +02:00
free ( Layer_Ptr - > Sample_Ptr ) ;
}
}
2022-03-27 11:33:37 +02:00
if ( ( Layer_Ptr - > SF_Info_Ptr = malloc ( sizeof ( SF_INFO ) ) ) = = NULL )
{
2022-04-21 01:27:08 +02:00
fprintf ( stderr , " Can't allocate SF_Info buffer! \n " ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
memset ( Layer_Ptr - > SF_Info_Ptr , 0 , sizeof ( SF_INFO ) ) ;
if ( ( sndf_ptr = sf_open ( Layer_Ptr - > FileName , SFM_READ , Layer_Ptr - > SF_Info_Ptr ) ) = = NULL )
{
2024-04-21 20:16:18 +02:00
LG_LOG_WARNING_2 ( " Can't open sample file [%s] (%ld)! " , Layer_Ptr - > FileName , ( long ) sf_strerror ( ( SNDFILE * ) ( Layer_Ptr - > Sample_Ptr ) ) ) ;
2022-03-27 11:33:37 +02:00
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
{
2022-04-20 12:37:32 +02:00
Layer_Ptr - > Sample_Size = Layer_Ptr - > SF_Info_Ptr - > frames * Layer_Ptr - > SF_Info_Ptr - > channels ;
2022-03-27 11:33:37 +02:00
2022-04-20 12:37:32 +02:00
if ( ( Layer_Ptr - > Sample_Ptr = malloc ( Layer_Ptr - > Sample_Size * sizeof ( float ) ) ) = = NULL )
2022-03-27 11:33:37 +02:00
{
2022-04-20 12:37:32 +02:00
fprintf ( stderr , " Can't allocate sample memory: (%ld) for [%s]! \n " , Layer_Ptr - > Sample_Size , Layer_Ptr - > FileName ) ;
2022-03-27 11:33:37 +02:00
status = DRS_KO ;
}
else
{
2022-04-20 12:37:32 +02:00
sf_read_float ( sndf_ptr , Layer_Ptr - > Sample_Ptr , ( Layer_Ptr - > Sample_Size ) ) ;
2022-03-27 11:33:37 +02:00
status = DRS_OK ;
// convert rate if needed
2022-04-27 23:13:33 +02:00
if ( Layer_Ptr - > SF_Info_Ptr - > samplerate ! = samplerate )
2022-03-27 11:33:37 +02:00
{
int src_status ;
SRC_DATA src_data ;
long out_size ;
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "Resampling: [%s] (%d)->(%d)\n", Layer_Ptr->FileName, Layer_Ptr->SF_Info_Ptr->samplerate, samplerate);
2022-04-20 12:37:32 +02:00
2022-03-27 11:33:37 +02:00
src_data . data_in = Layer_Ptr - > Sample_Ptr ;
src_data . input_frames = Layer_Ptr - > SF_Info_Ptr - > frames ;
2022-04-27 23:13:33 +02:00
src_data . src_ratio = ( double ) samplerate / Layer_Ptr - > SF_Info_Ptr - > samplerate ;
2022-03-27 11:33:37 +02:00
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 )
{
2022-04-20 12:37:32 +02:00
fprintf ( stderr , " Can't allocate resample memory: (%ld) for [%s]! \n " , out_size , Layer_Ptr - > FileName ) ;
2022-03-27 11:33:37 +02:00
status = DRS_KO ;
}
else
{
2022-04-21 01:27:08 +02:00
if ( ( src_status = src_simple ( & src_data , DRD_RATE_CONV_QUALITY , Layer_Ptr - > SF_Info_Ptr - > channels ) ) ! = 0 )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " Can't convert rate for [%s]: [%s] \n " , Layer_Ptr - > FileName , src_strerror ( src_status ) ) ;
free ( src_data . data_out ) ;
}
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 = src_data . data_out ;
2022-04-20 12:37:32 +02:00
Layer_Ptr - > Sample_Size = src_data . output_frames_gen * Layer_Ptr - > SF_Info_Ptr - > channels ;
2022-04-27 23:13:33 +02:00
Layer_Ptr - > SF_Info_Ptr - > samplerate = samplerate ;
2022-03-27 11:33:37 +02:00
Layer_Ptr - > SF_Info_Ptr - > frames = src_data . output_frames_gen ;
}
}
}
}
}
sf_close ( sndf_ptr ) ;
}
2022-04-20 12:37:32 +02:00
2022-03-27 11:33:37 +02:00
return ( status ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
/* DR_Layer_Sample_UnLoad */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Layer_Sample_UnLoad ( DRT_Layer * Layer_Ptr )
{
2022-04-21 01:27:08 +02:00
// fprintf( stderr, "UnLoading: [%s]\n", Layer_Ptr->FileName);
2022-04-20 12:37:32 +02:00
if ( Layer_Ptr - > Sample_Ptr ! = NULL )
{
2022-04-21 01:27:08 +02:00
// fprintf( stderr, "Freeing Sample!\n");
2022-04-20 12:37:32 +02:00
free ( Layer_Ptr - > Sample_Ptr ) ;
}
if ( Layer_Ptr - > SF_Info_Ptr ! = NULL )
{
2022-04-21 01:27:08 +02:00
// fprintf( stderr, "Freeing SF_Info!\n");
2022-04-20 12:37:32 +02:00
free ( Layer_Ptr - > SF_Info_Ptr ) ;
}
return ( NDS_OK ) ;
2022-03-27 11:33:37 +02:00
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
/* DR_Layer_Dump */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Layer_Dump ( DRT_Layer * Layer_Ptr , long count )
{
NDT_Status nd_status ;
2022-04-20 12:37:32 +02:00
fprintf ( stderr , " %03ld) Layer: " , count ) ;
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Id: (% 3ld) File Name: [%s] Sample: [%lx] Sample Size: (%ld) Min: (%f) Max: (%f) Gain: (%f) Pitch: (%f) Intrument Id: (% 3ld) " ,
Layer_Ptr - > Id , Layer_Ptr - > FileName , ( long ) Layer_Ptr - > Sample_Ptr , Layer_Ptr - > Sample_Size , Layer_Ptr - > Min , Layer_Ptr - > Max , Layer_Ptr - > Gain , Layer_Ptr - > Pitch , Layer_Ptr - > Instrument_Ptr - > Id ) ;
2022-04-20 12:37:32 +02:00
if ( Layer_Ptr - > SF_Info_Ptr ! = NULL )
{
fprintf ( stderr , " Channels: (%d) Rate: (%d) \n " , Layer_Ptr - > SF_Info_Ptr - > channels , Layer_Ptr - > SF_Info_Ptr - > samplerate ) ;
}
else
{
fprintf ( stderr , " \n " ) ;
}
2022-03-27 11:33:37 +02:00
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
/* DR_Instrument_Add */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Instrument_Add ( DRT_Instrument * * Instrument_Ptr_Ptr , NDT_Root * DS_Ptr , DRT_Instrument * Instrument_Template_Ptr )
{
NDT_Status nd_status ;
2023-08-17 19:45:24 +02:00
if ( ( nd_status = ND_Value_Alloc ( ( void * * ) Instrument_Ptr_Ptr , DS_Ptr , Instrument_Template_Ptr ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-21 01:27:08 +02:00
printf ( " Can't allocate new instrument: ND_Value_Alloc() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
else
{
if ( ( nd_status = ND_DataStruct_Value_Add ( DS_Ptr , ( void * ) * Instrument_Ptr_Ptr ) ) ! = NDS_OK )
{
2022-04-21 01:27:08 +02:00
printf ( " Can't add new instrument: ND_Value_Add() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
}
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
/* DR_Instrument_Dump */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Instrument_Dump ( DRT_Instrument * Instrument_Ptr , long Count )
{
NDT_Status nd_status ;
long count2 ;
2022-04-20 12:37:32 +02:00
fprintf ( stderr , " %03ld) Instrument: " , Count ) ;
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Id: (% 3ld) Name: [%s] Gain: (%f) Pan Left: (%f) Pan Right: (%f) Kit Id: (% 3ld) \n " ,
Instrument_Ptr - > Id , Instrument_Ptr - > Name , Instrument_Ptr - > Gain , Instrument_Ptr - > Pan_Left , Instrument_Ptr - > Pan_Right , Instrument_Ptr - > Kit_Ptr - > Id ) ;
2022-03-27 11:33:37 +02:00
// 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 )
{
2022-04-21 01:27:08 +02:00
printf ( " Cant't dump layers: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
}
fprintf ( stderr , " \n " ) ;
return ( DRS_OK ) ;
}
2022-04-27 23:13:33 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Instrument_Sample_Load */
/*----------------------------------------------------------------------------*/
DRT_Status DR_Instrument_Sample_Load ( DRT_Instrument * Instrument_Ptr )
{
NDT_Status nd_status ;
if ( ( nd_status = ND_DataStruct_Traverse ( Instrument_Ptr - > Layer_DS_Ptr , NDD_CMD_SAMPLE_LOAD ) ) ! = NDS_OK )
{
printf ( " Cant't load instrument samples: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
return ( DRS_OK ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Instrument_Sample_UnLoad */
/*----------------------------------------------------------------------------*/
DRT_Status DR_Instrument_Sample_UnLoad ( DRT_Instrument * Instrument_Ptr )
{
NDT_Status nd_status ;
if ( ( nd_status = ND_DataStruct_Traverse ( Instrument_Ptr - > Layer_DS_Ptr , NDD_CMD_SAMPLE_UNLOAD ) ) ! = NDS_OK )
{
printf ( " Cant't unload instrument samples: ND_DataStruct_Traverse() failed (%d) \n " , nd_status ) ;
return ( DRS_KO ) ;
}
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Add */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Kit_Add ( DRT_Kit * * Kit_Ptr_Ptr , NDT_Root * DS_Ptr , DRT_Kit * Kit_Template_Ptr )
{
NDT_Status nd_status ;
2023-08-17 19:45:24 +02:00
if ( ( nd_status = ND_Value_Alloc ( ( void * * ) Kit_Ptr_Ptr , DS_Ptr , Kit_Template_Ptr ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-21 01:27:08 +02:00
printf ( " Can't allocate new kit: ND_Value_Alloc() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
else
{
if ( ( nd_status = ND_DataStruct_Value_Add ( DS_Ptr , ( void * * ) * Kit_Ptr_Ptr ) ) ! = NDS_OK )
{
2022-04-21 01:27:08 +02:00
printf ( " Can't add new kit: ND_Value_Add() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
}
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Id_Find */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kit_Id_Find ( DRT_Kit * * Kit_Ptr_Ptr , DRT_Kit_Id Kit_Id )
2022-03-27 11:33:37 +02:00
{
2022-05-14 23:53:23 +02:00
DRT_Status status ;
NDT_Status nd_status ;
DRT_Kit kit_template ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
kit_template . Id = Kit_Id ;
kit_template . Logical_Id = DRD_ID_UNKNOWN ;
kit_template . Name [ 0 ] = ' \0 ' ;
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Value_Find ( ( void * * ) Kit_Ptr_Ptr , DRG_Base . Kit_DS_Ptr , & kit_template ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_ERROR_1 ( " DR_Kit_Id_Find: Find error: (%d)! " , nd_status ) ;
2022-04-20 12:37:32 +02:00
status = DRS_KO ;
}
else
{
if ( * Kit_Ptr_Ptr = = NULL )
{
2024-04-21 20:16:18 +02:00
LG_LOG_WARNING_1 ( " Can't find: Kit with id: (%ld)! " , Kit_Id ) ;
2022-04-20 12:37:32 +02:00
status = DRS_KO ;
}
else
{
status = DRS_OK ;
}
2022-03-27 11:33:37 +02:00
}
2022-04-20 12:37:32 +02:00
return ( status ) ;
}
2022-04-27 23:13:33 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Logical_Id_Find */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kit_Logical_Id_Find ( DRT_Kit * * Kit_Ptr_Ptr , DRT_Kit_Id Kit_Logical_Id )
2022-04-27 23:13:33 +02:00
{
DRT_Status status ;
NDT_Status nd_status ;
DRT_Kit kit_template ;
kit_template . Id = DRD_ID_UNKNOWN ;
kit_template . Logical_Id = Kit_Logical_Id ;
kit_template . Name [ 0 ] = ' \0 ' ;
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Value_Find ( ( void * * ) Kit_Ptr_Ptr , DRG_Base . Kit_DS_Ptr , & kit_template ) ) ! = NDS_OK )
2022-04-27 23:13:33 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_ERROR_1 ( " DR_Kit_Logical_Id_Find: Find error: (%d)! " , nd_status ) ;
2022-04-27 23:13:33 +02:00
status = DRS_KO ;
}
else
{
if ( * Kit_Ptr_Ptr = = NULL )
{
2024-04-21 20:16:18 +02:00
LG_LOG_WARNING_1 ( " DR_Kit_Logical_Id_Find: Can't find: kit with logical id: [%d]! " , Kit_Logical_Id ) ;
2022-04-27 23:13:33 +02:00
status = DRS_KO ;
}
else
{
status = DRS_OK ;
}
}
return ( status ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Name_Find */
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kit_Name_Find ( DRT_Kit * * Kit_Ptr_Ptr , char * Kit_Name )
2022-04-20 12:37:32 +02:00
{
DRT_Status status ;
NDT_Status nd_status ;
DRT_Kit kit_template ;
2022-04-27 23:13:33 +02:00
kit_template . Id = DRD_ID_UNKNOWN ;
kit_template . Logical_Id = DRD_ID_UNKNOWN ;
2022-04-21 01:27:08 +02:00
strncpy ( kit_template . Name , Kit_Name , DRD_NAME_LEN ) ;
2022-04-20 12:37:32 +02:00
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Value_Find ( ( void * * ) Kit_Ptr_Ptr , DRG_Base . Kit_DS_Ptr , & kit_template ) ) ! = NDS_OK )
2022-04-20 12:37:32 +02:00
{
fprintf ( stderr , " DR_Kit_Name_Find: Find error: (%d)! \n " , nd_status ) ;
status = DRS_KO ;
}
else
{
if ( * Kit_Ptr_Ptr = = NULL )
{
fprintf ( stderr , " Can't find: Kit with name: [%s]! \n " , Kit_Name ) ;
status = DRS_KO ;
}
else
{
status = DRS_OK ;
}
}
return ( status ) ;
2022-03-27 11:33:37 +02:00
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Dump */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_Kit_Dump ( DRT_Kit * Kit_Ptr , long Count )
{
NDT_Status nd_status ;
long count2 ;
2022-04-20 12:37:32 +02:00
fprintf ( stderr , " %03ld) DrumKit: " , Count ) ;
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Id: (% 3ld) Logical Id: (% 3ld) Status: [%s] Name: [%s] Descrition: [%.32s] Dir Name: [%s] Sample Rate: (%d) \n " ,
Kit_Ptr - > Id , Kit_Ptr - > Logical_Id , DR_LOAD_STATUS_ASCII_GET ( Kit_Ptr ) , Kit_Ptr - > Name , Kit_Ptr - > Desc , Kit_Ptr - > DirName , Kit_Ptr - > Base_Ptr - > SampleRate ) ;
2022-03-27 11:33:37 +02:00
fprintf ( stderr , " Instruments List: \n " ) ;
2022-04-27 23:13:33 +02:00
if ( Kit_Ptr - > Instrument_DS_Ptr = = NULL )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Uninitialised list! \n " ) ;
2022-03-27 11:33:37 +02:00
}
else
{
2022-04-27 23:13:33 +02:00
if ( Kit_Ptr - > Instrument_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number = = 0 )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Empty list! \n " ) ;
}
else
{
count2 = 0 ;
if ( ( nd_status = ND_DataStruct_Value_Print ( stderr , Kit_Ptr - > Instrument_DS_Ptr , NDD_RECURSIVE_MODE_PARENT_CHILD , 0 , 0 , & count2 ) ) ! = NDS_OK )
{
printf ( " Cant't dump intruments: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
2022-03-27 11:33:37 +02:00
}
}
fprintf ( stderr , " \n " ) ;
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
/* DR_XML_Node_Exist */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
DRT_Status DR_XML_Node_Exist ( xmlDocPtr Xml_Doc , xmlXPathContextPtr Xml_XpathCtx , char * Xpath_Request )
{
DRT_Status status ;
xmlXPathObjectPtr xml_xpathobj ;
xmlNodeSetPtr nodeset ;
char * tmpval_ptr ;
long tmpval_len ;
2022-04-20 12:37:32 +02:00
if ( ( xml_xpathobj = xmlXPathEvalExpression ( ( xmlChar * ) Xpath_Request , Xml_XpathCtx ) ) = = NULL )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " DR_XML_Node_Exist: 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
{
// fprintf( stderr, "[%s] found!\n", Xpath_Request);
status = DRS_OK ;
}
}
xmlXPathFreeObject ( xml_xpathobj ) ;
return ( status ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_XML_Value_Get */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
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 ) ;
2022-04-20 12:37:32 +02:00
if ( ( xml_xpathobj = xmlXPathEvalExpression ( ( xmlChar * ) xpath_request , Xml_XpathCtx ) ) = = NULL )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " DR_XML_Value_Get: xmlXPathEvalExpression failed! [%s] \n " , xpath_request ) ;
status = DRS_KO ;
}
else
{
nodeset = xml_xpathobj - > nodesetval ;
if ( xmlXPathNodeSetIsEmpty ( nodeset ) )
{
2024-04-21 20:16:18 +02:00
LG_LOG_WARNING_1 ( " [%s] not found! " , xpath_request ) ;
2022-03-27 11:33:37 +02:00
status = DRS_KO ;
}
else
{
2022-04-20 12:37:32 +02:00
if ( ( tmpval_ptr = ( char * ) xmlNodeListGetString ( Xml_Doc , nodeset - > nodeTab [ 0 ] - > xmlChildrenNode , 1 ) ) = = NULL )
2022-03-27 11:33:37 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_WARNING_1 ( " [%s] value not found! " , xpath_request ) ;
2022-03-27 11:33:37 +02:00
status = DRS_KO ;
}
else
{
// fprintf( stderr, "[%s] = [%s] found!\n", nodeset->nodeTab[0]->name, tmpval_ptr);
if ( ( tmpval_len = strlen ( tmpval_ptr ) ) > Max_Len )
{
2022-04-20 12:37:32 +02:00
fprintf ( stderr , " Value too long (%ld)>(%ld)! \n " , tmpval_len , Max_Len ) ;
2022-03-27 11:33:37 +02:00
status = DRS_OK ;
}
else
{
strcpy ( Value_Ptr , tmpval_ptr ) ;
status = DRS_OK ;
}
}
xmlFree ( tmpval_ptr ) ;
}
}
xmlXPathFreeObject ( xml_xpathobj ) ;
return ( status ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_XML_Query_Tab_Exec */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
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 ;
2022-04-21 01:27:08 +02:00
char reply_str [ DRD_DESC_SIZE ] ;
2022-03-27 11:33:37 +02:00
int i ;
i = 0 ;
while ( XML_Query_Tab [ i ] . XPath_Query ! = NULL )
{
2022-04-21 01:27:08 +02:00
if ( ( status = DR_XML_Value_Get ( reply_str , DRD_DESC_LEN , XML_Doc , XML_XpathCtx , Xpath_Head , XML_Query_Tab [ i ] . XPath_Query ) ) ! = DRS_OK )
2022-03-27 11:33:37 +02:00
{
strcpy ( reply_str , " " ) ;
}
switch ( XML_Query_Tab [ i ] . Value_Type )
{
2022-04-21 01:27:08 +02:00
case DRD_XML_QUERY_VALUE_STRING :
2022-03-27 11:33:37 +02:00
{
strncpy ( ( Value_Ptr + XML_Query_Tab [ i ] . Value_Offset ) , reply_str , XML_Query_Tab [ i ] . Value_Len ) ;
break ;
}
2022-04-21 01:27:08 +02:00
case DRD_XML_QUERY_VALUE_INT :
2022-03-27 11:33:37 +02:00
{
* ( ( int * ) ( Value_Ptr + XML_Query_Tab [ i ] . Value_Offset ) ) = atoi ( reply_str ) ;
break ;
}
2022-04-21 01:27:08 +02:00
case DRD_XML_QUERY_VALUE_LONG :
2022-03-27 11:33:37 +02:00
{
* ( ( long * ) ( Value_Ptr + XML_Query_Tab [ i ] . Value_Offset ) ) = strtol ( reply_str , NULL , 10 ) ;
break ;
}
2022-04-21 01:27:08 +02:00
case DRD_XML_QUERY_VALUE_LONGLONG :
2022-03-27 11:33:37 +02:00
{
* ( ( long long * ) ( Value_Ptr + XML_Query_Tab [ i ] . Value_Offset ) ) = strtoll ( reply_str , NULL , 10 ) ;
break ;
}
2022-04-21 01:27:08 +02:00
case DRD_XML_QUERY_VALUE_FLOAT :
2022-03-27 11:33:37 +02:00
{
* ( ( float * ) ( Value_Ptr + XML_Query_Tab [ i ] . Value_Offset ) ) = strtof ( reply_str , NULL ) ;
break ;
}
2022-04-21 01:27:08 +02:00
case DRD_XML_QUERY_VALUE_DOUBLE :
2022-03-27 11:33:37 +02:00
{
* ( ( 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 ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Load */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kit_Load ( char * FileName )
2022-03-27 11:33:37 +02:00
{
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 ;
2022-04-21 01:27:08 +02:00
char tmp_filename [ DRD_FILENAME_SIZE ] ;
2022-03-27 11:33:37 +02:00
char xpath_head [ 1024 ] ;
char reply_str [ 256 ] ;
int instrument , layer ;
short i ;
2022-04-27 23:13:33 +02:00
kit_template . Id = DRD_ID_UNKNOWN ;
kit_template . Logical_Id = DRD_ID_UNKNOWN ;
kit_template . Status = DRD_LOAD_STATUS_UNLOADED ;
2022-05-14 23:53:23 +02:00
kit_template . Base_Ptr = & DRG_Base ;
2022-03-27 11:33:37 +02:00
layer_template . Sample_Ptr = NULL ;
layer_template . Sample_Size = 0 ;
2022-04-20 12:37:32 +02:00
layer_template . SF_Info_Ptr = NULL ;
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
// fprintf( stderr, "Loading: [%s]...\n", FileName);
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " Loading: [%s]... " , FileName ) ;
2022-03-27 11:33:37 +02:00
2022-04-21 01:27:08 +02:00
if ( strlen ( FileName ) > DRD_FILENAME_LEN )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " Kit file name too long [%s]! " , FileName ) ;
status = DRS_KO ;
}
else
{
strcpy ( tmp_filename , FileName ) ;
strcpy ( kit_template . DirName , dirname ( tmp_filename ) ) ;
if ( ( xml_doc = xmlParseFile ( FileName ) ) = = NULL )
{
fprintf ( stderr , " xml_doc failed! \n " ) ;
status = DRS_KO ;
}
else
{
if ( ( xml_xpathCtx = xmlXPathNewContext ( xml_doc ) ) = = NULL )
{
fprintf ( stderr , " xmlXPathNewContext failed! \n " ) ;
status = DRS_KO ;
}
else
{
2022-04-20 12:37:32 +02:00
if ( xmlXPathRegisterNs ( xml_xpathCtx , ( xmlChar * ) " drumkit " , ( xmlChar * ) " http://www.hydrogen-music.org/drumkit " ) ! = 0 )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " Error: unable to register default NS! \n " ) ;
status = DRS_KO ;
}
2022-04-21 01:27:08 +02:00
if ( ( status = DR_XML_Node_Exist ( xml_doc , xml_xpathCtx , DRD_XML_XPATH_DRUMKIT_BASE_STR ) ! = DRS_OK ) )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " Bad drumkit file! \n " ) ;
}
else
{
2022-04-21 01:27:08 +02:00
DR_XML_Query_Tab_Exec ( & kit_template , xml_doc , xml_xpathCtx , DRD_XML_XPATH_DRUMKIT_BASE_STR , DRG_XML_Query_Tab_Kit ) ;
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
if ( ( status = DR_Kit_Add ( & kit_ptr , DRG_Base . Kit_DS_Ptr , & kit_template ) ) ! = DRS_OK )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " Can't create a new kit! \n " ) ;
}
else
{
// fprintf( stderr, "New kit!\n");
status = DRS_OK ;
instrument = 1 ;
2022-04-27 23:13:33 +02:00
instrument_template . Kit_Ptr = kit_ptr ;
2022-03-27 11:33:37 +02:00
while ( ( status = = DRS_OK )
2022-04-21 01:27:08 +02:00
& & ( sprintf ( xpath_head , DRD_XML_XPATH_DRUMKIT_INSTRUMENT_FULL , instrument ) > 0 )
2022-03-27 11:33:37 +02:00
& & ( DR_XML_Node_Exist ( xml_doc , xml_xpathCtx , xpath_head ) = = 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
{
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");
}
layer = 1 ;
2022-04-27 23:13:33 +02:00
layer_template . Instrument_Ptr = instrument_ptr ;
2022-03-27 11:33:37 +02:00
while ( ( status = = DRS_OK )
2022-04-21 01:27:08 +02:00
& & ( sprintf ( xpath_head , DRD_XML_XPATH_DRUMKIT_LAYER_FULL , instrument , layer ) > 0 )
2022-03-27 11:33:37 +02:00
& & ( 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 + + ;
}
}
}
xmlXPathFreeContext ( xml_xpathCtx ) ;
}
xmlFreeDoc ( xml_doc ) ;
}
}
xmlCleanupParser ( ) ;
return ( status ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Sample_Load */
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
2022-04-27 23:13:33 +02:00
DRT_Status DR_Kit_Sample_Load ( DRT_Kit * Kit_Ptr )
2022-04-20 12:37:32 +02:00
{
NDT_Status nd_status ;
2022-04-27 23:13:33 +02:00
2022-04-21 01:27:08 +02:00
if ( DR_LOAD_STATUS_LOADED_IS ( Kit_Ptr ) )
2022-04-20 12:37:32 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " Loading kit samples: [%s] Skiped! " , Kit_Ptr - > Name ) ;
2022-04-20 12:37:32 +02:00
}
2022-04-21 01:27:08 +02:00
else
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " Loading kit samples: [%s]! " , Kit_Ptr - > Name ) ;
2022-04-21 01:27:08 +02:00
2022-04-27 23:13:33 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( Kit_Ptr - > Instrument_DS_Ptr , NDD_CMD_SAMPLE_LOAD ) ) ! = NDS_OK )
2022-04-21 01:27:08 +02:00
{
printf ( " Cant't load kit samples: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
2022-04-20 12:37:32 +02:00
2022-05-14 23:53:23 +02:00
if ( DRG_Base . Task_Sync_Kit_Flag = = DRD_TRUE )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
if ( DR_Task_Wait ( ) ! = DRS_OK )
2022-04-27 23:13:33 +02:00
{
printf ( " DR_Task_Wait failed (%d)! \n " ) ;
return ( DRS_KO ) ;
}
}
2022-04-21 01:27:08 +02:00
Kit_Ptr - > Status = DRD_LOAD_STATUS_LOADED ;
}
2022-04-20 12:37:32 +02:00
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kit_Sample_UnLoad */
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
DRT_Status DR_Kit_Sample_UnLoad ( DRT_Kit * Kit_Ptr )
{
NDT_Status nd_status ;
2022-04-21 01:27:08 +02:00
if ( ! DR_LOAD_STATUS_LOADED_IS ( Kit_Ptr ) )
2022-04-20 12:37:32 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " UnLoading kit samples: [%s] Skiped! " , Kit_Ptr - > Name ) ;
2022-04-21 01:27:08 +02:00
}
else
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " UnLoading kit samples: [%s]! " , Kit_Ptr - > Name ) ;
2022-04-21 01:27:08 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( Kit_Ptr - > Instrument_DS_Ptr , NDD_CMD_SAMPLE_UNLOAD , Kit_Ptr ) ) ! = NDS_OK )
{
printf ( " Cant't unload kit samples: ND_DataStruct_Traverse() failed (%d) \n " , nd_status ) ;
return ( DRS_KO ) ;
}
Kit_Ptr - > Status = DRD_LOAD_STATUS_UNLOADED ;
2022-04-20 12:37:32 +02:00
}
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-27 23:13:33 +02:00
/* DR_Kits_Sample_Load */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kits_Sample_Load ( )
2022-04-20 12:37:32 +02:00
{
2022-04-27 23:13:33 +02:00
NDT_Status nd_status ;
2022-04-20 12:37:32 +02:00
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_0 ( " Loading kits samples! " ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( DRG_Base . Kit_DS_Ptr , NDD_CMD_SAMPLE_LOAD ) ) ! = NDS_OK )
2022-04-20 12:37:32 +02:00
{
2022-04-27 23:13:33 +02:00
printf ( " Cant't load kit samples: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
2022-04-20 12:37:32 +02:00
return ( DRS_KO ) ;
}
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( DRG_Base . Task_Sync_Kits_Flag = = DRD_TRUE )
2022-04-20 12:37:32 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_0 ( " Synchronising... " ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( DR_Task_Wait ( ) ! = DRS_OK )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " DR_Task_Wait failed (%d)! \n " ) ;
return ( DRS_KO ) ;
}
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_0 ( " Sync done! " ) ;
2022-04-20 12:37:32 +02:00
}
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-27 23:13:33 +02:00
/* DR_Kits_Sample_UnLoad */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kits_Sample_UnLoad ( )
2022-04-20 12:37:32 +02:00
{
2022-04-27 23:13:33 +02:00
NDT_Status nd_status ;
2022-04-20 12:37:32 +02:00
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_0 ( " UnLoading kits samples! " ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( DRG_Base . Kit_DS_Ptr , NDD_CMD_SAMPLE_UNLOAD , DRG_Base . SampleRate ) ) ! = NDS_OK )
2022-04-20 12:37:32 +02:00
{
2022-04-27 23:13:33 +02:00
printf ( " Cant't unload kit samples: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
2022-04-20 12:37:32 +02:00
return ( DRS_KO ) ;
}
2022-04-27 23:13:33 +02:00
2022-04-20 12:37:32 +02:00
return ( DRS_OK ) ;
}
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-27 23:13:33 +02:00
/* DR_Kits_Load */
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
2022-04-20 12:37:32 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kits_Load ( )
2022-03-27 11:33:37 +02:00
{
DRT_Status status ;
NDT_Status nd_status ;
2022-04-21 01:27:08 +02:00
char glob_pattern [ ] = " ~/.hydrogen/data/drumkits/*/drumkit.xml " ;
2022-03-27 11:33:37 +02:00
// char glob_pattern[] = "~/.hydrogen/data/drumkits/AVL-BlackPearl-4A-1.1/drumkit.xml";
// char glob_pattern[] = "~/.hydrogen/data/drumkits/Mars Lindrum: 02-Kit 2/drumkit.xml";
2022-04-21 01:27:08 +02:00
// char glob_pattern[] = "~/.hydrogen/data/drumkits/Mars Mod */drumkit.xml";
2022-03-27 11:33:37 +02:00
glob_t glob_struct ;
int i ;
2022-04-27 23:13:33 +02:00
DRT_Kit_Id count = 0L ;
2022-03-27 11:33:37 +02:00
LIBXML_TEST_VERSION ;
if ( glob ( glob_pattern , ( GLOB_NOSORT + GLOB_TILDE ) , NULL , & glob_struct ) ! = 0 )
{
fprintf ( stderr , " glob() error! \n " ) ;
status = DRS_KO ;
}
else
{
for ( i = 0 ; i < glob_struct . gl_pathc ; i + + )
{
// printf( "[%s]\n", glob_struct.gl_pathv[i]);
2022-05-14 23:53:23 +02:00
if ( ( status = DR_Kit_Load ( glob_struct . gl_pathv [ i ] ) ) ! = DRS_OK )
2022-03-27 11:33:37 +02:00
{
fprintf ( stderr , " Can't load kit [%s]! \n " , glob_struct . gl_pathv [ i ] ) ;
}
}
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( DRG_Base . Kit_DS_Ptr , NDD_CMD_ID_REFRESH , & count ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
printf ( " Can't refresh kit id: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
status = DRS_KO ;
}
else
{
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Convert ( DRG_Base . Kit_DS_Ptr , DRG_Kit_DS_Index_Tab_Final ) ) ! = NDS_OK )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " ND_DataStruct_Convert() failed (%d)! \n " , status ) ;
status = DRS_KO ;
}
else
{
status = DRS_OK ;
}
2022-03-27 11:33:37 +02:00
}
}
globfree ( & glob_struct ) ;
2022-05-14 23:53:23 +02:00
// DR_Kits_Dump();
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
// DRG_Base.SampleRate=44100;
2022-03-27 11:33:37 +02:00
/*
status = DR_Layer_Sample_Load ( ( DRT_Layer * ) (
( ( DRT_Instrument * ) (
2022-05-14 23:53:23 +02:00
( ( DRT_Kit * ) ( DRG_Base . Kit_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Head - > Value ) )
2022-03-27 11:33:37 +02:00
- > Instrument_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Head - > Value ) )
- > Layer_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Head - > Value ) ,
2022-05-14 23:53:23 +02:00
( DRT_Kit * ) ( DRG_Base . Kit_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Head - > Value ) , DRG_Base . SampleRate ) ;
2022-03-27 11:33:37 +02:00
*/
2022-04-21 01:27:08 +02:00
2022-03-27 11:33:37 +02:00
/*
2022-05-14 23:53:23 +02:00
if ( DRG_Base . Kit_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Head ! = NULL )
2022-03-27 11:33:37 +02:00
{
2022-05-14 23:53:23 +02:00
status = DR_Kit_Sample_Load ( ( DRT_Kit * ) ( DRG_Base . Kit_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Head - > Value ) ,
DRG_Base . SampleRate ) ;
2022-03-27 11:33:37 +02:00
}
2022-04-20 12:37:32 +02:00
*/
2022-05-14 23:53:23 +02:00
// status = DR_Kits_Sample_Load();
2022-03-27 11:33:37 +02:00
return ( status ) ;
}
2022-04-27 23:13:33 +02:00
2024-04-10 10:05:11 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kits_Name_Get */
/*----------------------------------------------------------------------------*/
DRT_Status DR_Kits_Name_Get ( DRT_Kit_Name * * Kit_Name_Tab_Ptr , long * Kit_Number_Ptr )
{
NDT_Status nd_status ;
NDT_Node * node_cur_ptr ;
DRT_Kit * kit_cur_ptr ;
long kit_id ;
* Kit_Number_Ptr = DRG_Base . Kit_DS_Ptr - > Index_Tab [ NDD_INDEX_PRIMARY ] . Node_Number ;
if ( * Kit_Number_Ptr = = 0 )
{
* Kit_Name_Tab_Ptr = NULL ;
return ( DRS_OK ) ;
}
else
{
if ( ( nd_status = ND_Index_Node_First_Get ( & node_cur_ptr , DRG_Base . Kit_DS_Ptr , 1 ) ) ! = NDS_OK )
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " Can't find the first kit: ND_Index_Node_First_Get() failed (%d)! " , nd_status ) ;
2024-04-10 10:05:11 +02:00
* Kit_Name_Tab_Ptr = NULL ;
return ( DRS_KO ) ;
}
else
{
if ( ( * Kit_Name_Tab_Ptr = malloc ( sizeof ( DRT_Kit_Name ) * * Kit_Number_Ptr ) ) = = NULL )
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_0 ( " Can't allocate kit name tab memory! " ) ;
2024-04-10 10:05:11 +02:00
* Kit_Name_Tab_Ptr = NULL ;
return ( DRS_KO ) ;
}
else
{
kit_id = 0 ;
while ( node_cur_ptr ! = NULL )
{
kit_cur_ptr = node_cur_ptr - > Value ;
2024-04-21 20:16:18 +02:00
// LG_LOG_INFO_1( "Kit Name: [%s]", kit_cur_ptr->Name);
2024-04-10 10:05:11 +02:00
( * Kit_Name_Tab_Ptr ) [ kit_id ] . Id = kit_cur_ptr - > Id ;
( * Kit_Name_Tab_Ptr ) [ kit_id ] . Logical_Id = kit_cur_ptr - > Logical_Id ;
strcpy ( ( * Kit_Name_Tab_Ptr ) [ kit_id ] . Name , kit_cur_ptr - > Name ) ;
kit_id + + ;
if ( ( nd_status = ND_Index_Node_Next_Get ( & node_cur_ptr , node_cur_ptr ) ) ! = NDS_OK )
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_1 ( " Can't find the next kit: ND_Index_Node_Next_Get() failed (%d)! " , nd_status ) ;
2024-04-10 10:05:11 +02:00
node_cur_ptr = NULL ;
}
}
return ( DRS_OK ) ;
}
}
}
}
2022-04-27 23:13:33 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kits_Stats_Dump */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kits_Stats_Dump ( )
2022-04-27 23:13:33 +02:00
{
NDT_Status nd_status ;
DRT_Id kit_count = 0 ;
DRT_Id instrument_count = 0 ;
DRT_Id layer_count = 0 ;
DRT_Id sample_count = 0 ;
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( DRG_Base . Kit_DS_Ptr , NDD_CMD_STATS_GET , & kit_count , & instrument_count , & layer_count , & sample_count ) ) ! = NDS_OK )
2022-04-27 23:13:33 +02:00
{
printf ( " Can't compute stats: ND_DataStruct_Traverse() failed (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
2022-03-27 11:33:37 +02:00
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_4 ( " Number of Kits: (%ld) Number of Instruments: (%ld) Number of Layers: (%ld) Number of Loaded Samples: (%ld) " , kit_count , instrument_count , layer_count , sample_count ) ;
2022-04-27 23:13:33 +02:00
return ( DRS_OK ) ;
}
2022-03-27 11:33:37 +02:00
2022-04-21 01:27:08 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Kits_Dump */
/*----------------------------------------------------------------------------*/
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kits_Dump ( )
2022-03-27 11:33:37 +02:00
{
NDT_Status nd_status ;
2022-04-27 23:13:33 +02:00
DRT_Kit_Id count = 0 ;
2022-03-27 11:33:37 +02:00
fprintf ( stderr , " \n " ) ;
2022-05-14 23:53:23 +02:00
fprintf ( stderr , " Sample Rate: (%d) \n " , DRG_Base . SampleRate ) ;
2022-03-27 11:33:37 +02:00
fprintf ( stderr , " DrumKit List: \n " ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Value_Print ( stderr , DRG_Base . Kit_DS_Ptr , NDD_RECURSIVE_MODE_PARENT_CHILD , 0 , 0 , & count ) ) ! = NDS_OK )
2022-04-27 23:13:33 +02:00
{
printf ( " Can't dump kits: ND_DataStruct_Value_Print() failed (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
2022-05-14 23:53:23 +02:00
if ( DR_Kits_Stats_Dump ( ) ! = DRS_OK )
2022-04-27 23:13:33 +02:00
{
return ( DRS_KO ) ;
}
return ( DRS_OK ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Kits_Graph_Dump */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Kits_Graph_Dump ( )
2022-04-27 23:13:33 +02:00
{
NDT_Status nd_status ;
fprintf ( stderr , " digraph G \n { \n node [shape = record]; \n \n " ) ;
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Traverse ( DRG_Base . Kit_DS_Ptr , NDD_CMD_GRAPH_PRINT ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
printf ( " Can't dump graph kits: ND_DataStruct_Value_Print() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " } \n " ) ;
return ( DRS_OK ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Task_Tread */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
static void * DR_Task_Thread ( )
2022-04-27 23:13:33 +02:00
{
pthread_t my_thread_id = pthread_self ( ) ;
short task_id ;
// fprintf( stderr, "Start Task Thread (%d)!\n", my_thread_id);
2022-05-14 23:53:23 +02:00
for ( task_id = 0 ; ( DRG_Base . Task_Tab [ task_id ] . Thread ! = my_thread_id ) & & ( task_id < DRG_Base . Task_Number ) ; task_id + + ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( task_id = = DRG_Base . Task_Number )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Can't find my id: (%d)! \n " , my_thread_id ) ;
}
else
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "I'm: (%02d)!\n", task_id);
2022-05-14 23:53:23 +02:00
pthread_mutex_lock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
do
{
2022-05-14 23:53:23 +02:00
switch ( DRG_Base . Task_Tab [ task_id ] . Command )
2022-04-27 23:13:33 +02:00
{
case DRD_TASK_CMD_TASK_SPAWN :
{
// fprintf( stderr, "I'm: (%02d) Spawning!\n", task_id);
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ task_id ] . Status = DRD_TASK_STATUS_RUNNING ;
DRG_Base . Task_Tab [ task_id ] . Count = 0L ;
2022-04-27 23:13:33 +02:00
break ;
}
case DRD_TASK_CMD_TASK_KILL :
{
// fprintf( stderr, "I'm: (%02d) Killing!\n", task_id);
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ task_id ] . Status = DRD_TASK_STATUS_KILLED ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
break ;
}
case DRD_TASK_CMD_INSTRUMENT_LOAD :
case DRD_TASK_CMD_LAYER_LOAD :
case DRD_TASK_CMD_KIT_LOAD :
{
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ task_id ] . Status = DRD_TASK_STATUS_RUNNING ;
// DRG_Base.Task_Count_Waiting--;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
switch ( DRG_Base . Task_Tab [ task_id ] . Command )
2022-04-27 23:13:33 +02:00
{
case DRD_TASK_CMD_LAYER_LOAD :
{
2022-05-14 23:53:23 +02:00
DR_Layer_Sample_Load ( ( DRT_Layer * ) ( DRG_Base . Task_Tab [ task_id ] . Target_Ptr ) ) ;
2022-04-27 23:13:33 +02:00
break ;
}
case DRD_TASK_CMD_INSTRUMENT_LOAD :
{
2022-05-14 23:53:23 +02:00
DR_Instrument_Sample_Load ( ( DRT_Instrument * ) ( DRG_Base . Task_Tab [ task_id ] . Target_Ptr ) ) ;
2022-04-27 23:13:33 +02:00
break ;
}
case DRD_TASK_CMD_KIT_LOAD :
{
2022-05-14 23:53:23 +02:00
DR_Kit_Sample_Load ( ( DRT_Kit * ) ( DRG_Base . Task_Tab [ task_id ] . Target_Ptr ) ) ;
2022-04-27 23:13:33 +02:00
break ;
}
}
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ task_id ] . Count + + ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_mutex_lock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
break ;
}
default :
{
2022-05-14 23:53:23 +02:00
printf ( " DR_Task_Thread called with an undefined command [%d] [%s] \n " , DRG_Base . Task_Tab [ task_id ] . Command , DR_TASK_CMD_ASCII_GET ( & ( DRG_Base . Task_Tab [ task_id ] ) ) ) ;
2022-04-27 23:13:33 +02:00
}
}
2022-05-14 23:53:23 +02:00
if ( DR_TASK_STATUS_RUNNING_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) )
2022-04-27 23:13:33 +02:00
{
// fprintf( stderr, "I'm: (%02d) Waiting!\n", task_id);
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ task_id ] . Status = DRD_TASK_STATUS_WAITING ;
DRG_Base . Task_Tab [ task_id ] . Command = DRD_TASK_CMD_NONE ;
DRG_Base . Task_Tab [ task_id ] . Target_Ptr = NULL ;
DRG_Base . Task_Count_Waiting + + ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_cond_signal ( & ( DRG_Base . Task_Cond ) ) ;
pthread_cond_wait ( & ( DRG_Base . Task_Tab [ task_id ] . Cond ) , & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
}
}
2022-05-14 23:53:23 +02:00
while ( ! DR_TASK_STATUS_KILLED_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "I'm: (%02d) and killed!\n", task_id);
}
return ( 0 ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Task_Id_Run */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Task_Id_Run ( DRT_Task_Id Task_Id , DRT_Task_Command Command , void * Target_Ptr )
2022-04-27 23:13:33 +02:00
{
DRT_Status status ;
2022-05-14 23:53:23 +02:00
// pthread_mutex_lock( &( DRG_Base.Task_Mutex));
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( ! DR_TASK_STATUS_WAITING_IS ( & ( DRG_Base . Task_Tab [ Task_Id ] ) ) )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
fprintf ( stderr , " Task_Id_Run: Inconsistent task status: [%s]! \n " , DR_TASK_STATUS_ASCII_GET ( & ( DRG_Base . Task_Tab [ Task_Id ] ) ) ) ;
// pthread_mutex_unlock( &( DRG_Base.Task_Mutex));
2022-04-27 23:13:33 +02:00
status = DRS_KO ;
}
else
{
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ Task_Id ] . Command = Command ;
DRG_Base . Task_Tab [ Task_Id ] . Target_Ptr = Target_Ptr ;
DRG_Base . Task_Count_Waiting - - ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_cond_signal ( & ( DRG_Base . Task_Tab [ Task_Id ] . Cond ) ) ;
// pthread_mutex_unlock( &( DRG_Base.Task_Mutex));
2022-04-27 23:13:33 +02:00
2022-04-29 20:48:54 +02:00
2022-04-27 23:13:33 +02:00
status = DRS_OK ;
}
return ( status ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Task_Kill */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Task_Id_Kill ( DRT_Task_Id Task_Id )
2022-04-27 23:13:33 +02:00
{
DRT_Status status ;
2022-05-14 23:53:23 +02:00
pthread_mutex_lock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( ! DR_TASK_STATUS_WAITING_IS ( & ( DRG_Base . Task_Tab [ Task_Id ] ) ) )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
fprintf ( stderr , " Task_Kill: Inconsistent task status: [%s]! \n " , DR_TASK_STATUS_ASCII_GET ( & ( DRG_Base . Task_Tab [ Task_Id ] ) ) ) ;
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
status = DRS_KO ;
}
else
{
// fprintf( stderr, "Killing task id: (%d)!\n", Task_Id);
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ Task_Id ] . Command = DRD_TASK_CMD_TASK_KILL ;
DRG_Base . Task_Tab [ Task_Id ] . Target_Ptr = NULL ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_cond_signal ( & ( DRG_Base . Task_Tab [ Task_Id ] . Cond ) ) ;
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
status = DRS_OK ;
}
return ( status ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Task_Run */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Task_Run ( DRT_Task_Command Command , void * Target_Ptr )
2022-04-27 23:13:33 +02:00
{
DRT_Task_Id task_id ;
DRT_Boolean found = DRD_FALSE ;
2022-04-29 20:48:54 +02:00
// fprintf( stderr, "Task Run: Called!\n");
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Count_Run + + ;
2022-04-29 20:48:54 +02:00
while ( found ! = DRD_TRUE )
{
2022-05-14 23:53:23 +02:00
pthread_mutex_lock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-29 20:48:54 +02:00
2022-05-14 23:53:23 +02:00
if ( DRG_Base . Task_Count_Waiting > 0 )
2022-04-29 20:48:54 +02:00
{
2022-05-14 23:53:23 +02:00
// while( ( task_id < DRG_Base.Task_Number) && ( found != DRD_TRUE))
for ( task_id = 0 ; ( task_id < DRG_Base . Task_Number ) & & ( found ! = DRD_TRUE ) ; task_id + + )
2022-04-29 20:48:54 +02:00
{
2022-05-14 23:53:23 +02:00
if ( DR_TASK_STATUS_WAITING_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) & & DR_TASK_CMD_NONE_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) )
2022-04-29 20:48:54 +02:00
{
2022-05-14 23:53:23 +02:00
// pthread_mutex_unlock( &( DRG_Base.Task_Mutex));
2022-04-29 20:48:54 +02:00
// fprintf( stderr, "Task Run: Found (%d)!\n", task_id);
2022-05-14 23:53:23 +02:00
if ( DR_Task_Id_Run ( task_id , Command , Target_Ptr ) ! = DRS_OK )
2022-04-29 20:48:54 +02:00
{
fprintf ( stderr , " Can't run task ! \n " ) ;
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-29 20:48:54 +02:00
return ( DRS_KO ) ;
}
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-29 20:48:54 +02:00
found = DRD_TRUE ;
}
}
if ( found ! = DRD_TRUE )
{
2022-05-14 23:53:23 +02:00
DR_Tasks_Dump ( ) ;
DRG_Base . Task_Count_FakeWU + + ;
2022-04-29 20:48:54 +02:00
}
}
if ( found ! = DRD_TRUE )
{
// fprintf( stderr, "Task Run: Sleeping!\n");
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Count_Sleep + + ;
2022-04-29 20:48:54 +02:00
2022-05-14 23:53:23 +02:00
pthread_cond_wait ( & ( DRG_Base . Task_Cond ) , & ( DRG_Base . Task_Mutex ) ) ;
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-29 20:48:54 +02:00
}
}
return ( DRS_OK ) ;
}
/*
2022-05-14 23:53:23 +02:00
DRT_Status DR_Task_Run ( DRT_Task_Command Command , void * Target_Ptr )
2022-04-29 20:48:54 +02:00
{
DRT_Task_Id task_id ;
DRT_Boolean found = DRD_FALSE ;
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "Task Run: Called!\n");
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Count_Run + + ;
2022-04-27 23:13:33 +02:00
while ( found ! = DRD_TRUE )
{
task_id = 0 ;
2022-05-14 23:53:23 +02:00
pthread_mutex_lock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
while ( ( task_id < DRG_Base . Task_Number ) & & ( found ! = DRD_TRUE ) )
2022-03-27 11:33:37 +02:00
{
2022-05-14 23:53:23 +02:00
if ( DR_TASK_STATUS_WAITING_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) & & DR_TASK_CMD_NONE_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
// pthread_mutex_unlock( &( DRG_Base.Task_Mutex));
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "Task Run: Found (%d)!\n", task_id);
2022-05-14 23:53:23 +02:00
if ( DR_Task_Id_Run ( task_id , Command , Target_Ptr ) ! = DRS_OK )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Can't run task ! \n " ) ;
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
return ( DRS_KO ) ;
}
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
found = DRD_TRUE ;
}
task_id + + ;
2022-03-27 11:33:37 +02:00
}
2022-04-27 23:13:33 +02:00
if ( found ! = DRD_TRUE )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
// fprintf( stderr, "Task Run: Sleeping!\n");
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Count_Sleep + + ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_cond_wait ( & ( DRG_Base . Task_Cond ) , & ( DRG_Base . Task_Mutex ) ) ;
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
}
}
return ( DRS_OK ) ;
}
2022-04-29 20:48:54 +02:00
*/
2022-04-27 23:13:33 +02:00
/*----------------------------------------------------------------------------*/
/* DR_Task_Wait */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Task_Wait ( )
2022-04-27 23:13:33 +02:00
{
DRT_Task_Id task_id , count = 0 ;
2022-05-14 23:53:23 +02:00
pthread_mutex_lock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
while ( count < DRG_Base . Task_Number )
2022-04-27 23:13:33 +02:00
{
task_id = 0 ;
count = 0 ;
2022-05-14 23:53:23 +02:00
for ( task_id = 0 ; task_id < DRG_Base . Task_Number ; task_id + + )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
if ( DR_TASK_STATUS_WAITING_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) & & DR_TASK_CMD_NONE_IS ( & ( DRG_Base . Task_Tab [ task_id ] ) ) )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
count + + ;
2022-03-27 11:33:37 +02:00
}
}
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( count < DRG_Base . Task_Number )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
// DR_Tasks_Dump();
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
pthread_cond_wait ( & ( DRG_Base . Task_Cond ) , & ( DRG_Base . Task_Mutex ) ) ;
2022-04-27 23:13:33 +02:00
}
}
2022-05-14 23:53:23 +02:00
pthread_mutex_unlock ( & ( DRG_Base . Task_Mutex ) ) ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
return ( DRS_OK ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_Tasks_Dump */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_Tasks_Dump ( )
2022-04-27 23:13:33 +02:00
{
DRT_Task_Id task_id ;
2022-05-14 23:53:23 +02:00
// pthread_mutex_lock( &( DRG_Base.Task_Mutex));
2022-04-27 23:13:33 +02:00
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_6 ( " Task Number: (%d) Task Load Layer: [%s] Task Load Instrument: [%s] Task Load Kit: [%s] Task Sync Kit: [%s] Task Sync Kits: [%s] " ,
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Number , DR_BOOLEAN_VALUE_ASCII_GET ( DRG_Base . Task_Load_Layer_Flag ) , DR_BOOLEAN_VALUE_ASCII_GET ( DRG_Base . Task_Load_Instrument_Flag ) , DR_BOOLEAN_VALUE_ASCII_GET ( DRG_Base . Task_Load_Kit_Flag ) , DR_BOOLEAN_VALUE_ASCII_GET ( DRG_Base . Task_Sync_Kit_Flag ) , DR_BOOLEAN_VALUE_ASCII_GET ( DRG_Base . Task_Sync_Kits_Flag ) ) ;
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_0 ( " Task Tab: " ) ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
for ( task_id = 0 ; task_id < DRG_Base . Task_Number ; task_id + + )
2022-04-27 23:13:33 +02:00
{
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_6 ( " Id: (%02d) Status: [%s] Thread: (%ld) Command: [%s] Target Ptr: [%lx] Count: (%ld) " ,
2022-05-14 23:53:23 +02:00
task_id , DR_TASK_STATUS_ASCII_GET ( & ( DRG_Base . Task_Tab [ task_id ] ) ) , ( long ) ( DRG_Base . Task_Tab [ task_id ] . Thread ) , DR_TASK_CMD_ASCII_GET ( & ( DRG_Base . Task_Tab [ task_id ] ) ) , DRG_Base . Task_Tab [ task_id ] . Target_Ptr , DRG_Base . Task_Tab [ task_id ] . Count ) ;
2022-03-27 11:33:37 +02:00
}
2022-04-27 23:13:33 +02:00
2024-04-21 20:16:18 +02:00
LG_LOG_INFO_4 ( " Task Count Waiting: (%ld) Task Count Run: (%ld) Task Count Sleep: (%ld) Task Count FakeWU: (%ld) " , DRG_Base . Task_Count_Waiting , DRG_Base . Task_Count_Run , DRG_Base . Task_Count_Sleep , DRG_Base . Task_Count_FakeWU ) ;
2022-03-27 11:33:37 +02:00
2022-05-14 23:53:23 +02:00
// pthread_mutex_unlock( &( DRG_Base.Task_Mutex));
2022-04-27 23:13:33 +02:00
return ( DRS_OK ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_DataStruct_Init */
/*----------------------------------------------------------------------------*/
2024-04-21 20:16:18 +02:00
DRT_Status DR_DataStruct_Init ( DRT_SampleRate SampleRate , DRT_Task_Id Task_Number )
2022-04-27 23:13:33 +02:00
{
NDT_Status nd_status ;
DRT_Task_Id task_id ;
if ( ( nd_status = ND_Library_Open ( NDD_TRUE ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Can't open node library (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Open ( & ( DRG_Base . Kit_DS_Ptr ) , DRD_KIT_DS_INDEX_NB , DRG_Kit_DS_Index_Tab_Initial , " Kit_Manager " , DR_Kit_Manager , NULL , NULL , NULL , NULL , NDD_TRUE , NULL ) ) ! = NDS_OK )
2022-03-27 11:33:37 +02:00
{
2022-04-27 23:13:33 +02:00
fprintf ( stderr , " Kit_DS: ND_DataStruct_Open() failed (%d)! \n " , nd_status ) ;
2022-03-27 11:33:37 +02:00
return ( DRS_KO ) ;
}
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
DRG_Base . SampleRate = SampleRate ;
2022-05-11 12:52:37 +02:00
/*
2022-05-14 23:53:23 +02:00
DRG_Base . Velocity_Ignore_Flag = DRD_VELOCITY_IGNORE_FLAG_DEFAULT ;
DRG_Base . Note_Off_Ignore_Flag = DRD_NOTE_OFF_IGNORE_FLAG_DEFAULT ;
DRG_Base . Velocity_Ignore_Note = DRD_VELOCITY_IGNORE_NOTE_DEFAULT ;
DRG_Base . Note_Off_Ignore_Note = DRD_NOTE_OFF_IGNORE_NOTE_DEFAULT ;
2022-05-11 12:52:37 +02:00
*/
2022-05-14 23:53:23 +02:00
DRG_Base . Channel_Id_Ptr = NULL ;
DRG_Base . Base_Note_Ptr = NULL ;
DRG_Base . Velocity_Ignore_Note_Ptr = NULL ;
DRG_Base . Note_Off_Ignore_Note_Ptr = NULL ;
DRG_Base . Velocity_Ignore_Flag_Ptr = NULL ;
DRG_Base . Note_Off_Ignore_Flag_Ptr = NULL ;
DRG_Base . Task_Number = Task_Number ;
DRG_Base . Task_Load_Layer_Flag = DRD_TASK_LOAD_LAYER_DEFAULT ;
DRG_Base . Task_Load_Instrument_Flag = DRD_TASK_LOAD_INSTRUMENT_DEFAULT ;
DRG_Base . Task_Load_Kit_Flag = DRD_TASK_LOAD_KIT_DEFAULT ;
DRG_Base . Task_Sync_Kit_Flag = DRD_TASK_SYNC_KIT_DEFAULT ;
DRG_Base . Task_Sync_Kits_Flag = DRD_TASK_SYNC_KITS_DEFAULT ;
DRG_Base . Task_Count_Waiting = 0L ;
DRG_Base . Task_Count_Run = 0L ;
DRG_Base . Task_Count_Sleep = 0L ;
DRG_Base . Task_Count_FakeWU = 0L ;
if ( ( DRG_Base . Task_Tab = malloc ( sizeof ( DRT_Task ) * Task_Number ) ) = = NULL )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Can't allocate task tab! \n " ) ;
return ( NDS_KO ) ;
}
else
{
2022-05-14 23:53:23 +02:00
if ( pthread_mutex_init ( & ( DRG_Base . Task_Mutex ) , 0 ) )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Could not initialize global task mutex! \n " ) ;
return ( NDS_KO ) ;
}
2022-05-14 23:53:23 +02:00
if ( pthread_cond_init ( & ( DRG_Base . Task_Cond ) , 0 ) )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Could not initialize global task cond! \n " ) ;
return ( NDS_KO ) ;
}
for ( task_id = 0 ; task_id < Task_Number ; task_id + + )
{
2022-05-14 23:53:23 +02:00
DRG_Base . Task_Tab [ task_id ] . Status = DRD_TASK_STATUS_UNSPAWNED ;
DRG_Base . Task_Tab [ task_id ] . Command = DRD_TASK_CMD_TASK_SPAWN ;
DRG_Base . Task_Tab [ task_id ] . Target_Ptr = NULL ;
DRG_Base . Task_Tab [ task_id ] . Count = 0L ;
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
if ( pthread_cond_init ( & ( DRG_Base . Task_Tab [ task_id ] . Cond ) , 0 ) )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Could not initialize task cond! \n " ) ;
return ( NDS_KO ) ;
}
2022-05-14 23:53:23 +02:00
if ( pthread_create ( & ( DRG_Base . Task_Tab [ task_id ] . Thread ) , 0 , ( void * ( * ) ( void * ) ) DR_Task_Thread , NULL ) )
2022-04-27 23:13:33 +02:00
{
fprintf ( stderr , " Could not initialize task thread! \n " ) ;
return ( NDS_KO ) ;
}
}
}
return ( DRS_OK ) ;
}
/*----------------------------------------------------------------------------*/
/* DR_DataStruct_DeInit */
/*----------------------------------------------------------------------------*/
2022-05-14 23:53:23 +02:00
DRT_Status DR_DataStruct_DeInit ( )
2022-04-27 23:13:33 +02:00
{
NDT_Status nd_status ;
DRT_Task_Id task_id ;
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
2022-05-14 23:53:23 +02:00
for ( task_id = 0 ; task_id < DRG_Base . Task_Number ; task_id + + )
2022-04-27 23:13:33 +02:00
{
2022-05-14 23:53:23 +02:00
if ( DR_Task_Id_Kill ( task_id ) ! = DRS_OK )
2022-04-27 23:13:33 +02:00
{
printf ( " Can't kill task: (%d)! \n " , task_id ) ;
return ( NDS_KO ) ;
}
}
2022-03-27 11:33:37 +02:00
2022-04-27 23:13:33 +02:00
// sleep(5);
2022-05-14 23:53:23 +02:00
if ( ( nd_status = ND_DataStruct_Close ( DRG_Base . Kit_DS_Ptr ) ) ! = NDS_OK )
2022-04-27 23:13:33 +02:00
{
printf ( " Can't close Kit_DS (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
if ( ( nd_status = ND_Library_Close ( ) ) ! = NDS_OK )
{
fprintf ( stderr , " Can't close node library (%d)! \n " , nd_status ) ;
return ( DRS_KO ) ;
}
2022-03-27 11:33:37 +02:00
return ( DRS_OK ) ;
}