Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

CHOP_csound_score.C

Go to the documentation of this file.
00001 /*
00002 
00003     CHOP CSound Score Generator Extension
00004 
00005     Version 0.05
00006     Date: September 2, 2003
00007     Author: Mark Story
00008 
00009     Digital Cinema Arts (C) 2003
00010 
00011         TODO: 
00012                 1) User modifiable instrument menu
00013                 2) Channel names for each p-field
00014 */
00015 
00016 #include <math.h>
00017 #include <time.h>
00018 
00019 #include <UT/UT_Math.h>
00020 #include <UT/UT_Floor.h>
00021 #include <OP/OP_Operator.h>
00022 #include <CH/CH_LocalVariable.h>
00023 #include <OP/OP_Node.h>
00024 #include <OP/OP_Network.h>
00025 #include <OP/OP_Director.h>
00026 #include <OP/OP_NodeFlags.h>
00027 #include <PRM/PRM_Include.h>
00028 
00029 #include <CHOP/CHOP_Node.h>
00030 #include <CHOP/CHOP_Handle.h>
00031 #include <CHOP/PRM_ChopShared.h>
00032 
00033 #include <OP/OP_OperatorTable.h>
00034 #include <UT/UT_DSOVersion.h>
00035 
00036 #ifndef MAKING_DSO
00037 #define MAKING_DSO
00038 #endif
00039 #ifdef  MAKING_DSO
00040 
00041 #include "CHOP_csound_score.h"
00042 
00043 #define DEBUG 0
00044 //  int DEBUG = 0;
00045 
00046 /*
00047 #ifdef WIN32
00048 char *debug_str = "0";
00049 #else
00050 char *debug_str = getenv("HOUDINI_DCA_DEBUG");
00051 #endif
00052 */
00053 
00054 
00055 OP_TemplatePair CHOP_csound_score::myTemplatePair(
00056     CHOP_csound_score::myTemplateList, &CHOP_Node::myTemplatePair);
00057 
00058 OP_VariablePair CHOP_csound_score::myVariablePair(
00059     CHOP_csound_score::myVariableList, &CHOP_Node::myVariablePair);
00060 
00061 enum
00062 {
00063     VAR_C                       = 000,
00064     VAR_NC                      = 001,
00065     VAR_INST_NUM        = 003,
00066     VAR_DUR                     = 004
00067 };
00068 
00069 CH_LocalVariable
00070 CHOP_csound_score::myVariableList[] = {
00071     { "C",              VAR_C },
00072     { "NC",             VAR_NC },
00073     { "INST_NUM",       VAR_INST_NUM },
00074     { "DUR",            VAR_DUR },
00075     { 0 }
00076 };
00077 
00078 CHOP_SWITCHER5(14, "Setup", 15, "f-table #1", 15, "f-table #2",  
00079                                 8, "f-table #3", 8, "f-table #4");
00080 
00081 // Names of UI gadgets
00082 static PRM_Name names[] =
00083 {
00084         // Setup page
00085     PRM_Name("score_fname",     "Score Filename"),
00086     PRM_Name("inst",            "Instrument Number"),
00087     PRM_Name("inst_name",       "Instrument Name"),
00088     PRM_Name("use_inst_input",  "Use instrument input"),
00089     PRM_Name("duration_override", "Override default note duration (1 second/sample rate)"),
00090     PRM_Name("duration",        "Event Duration", 1),
00091     PRM_Name("use_event_gate",  "Use event gate input"),
00092     PRM_Name("include_tog",     "Use score include file"),
00093     PRM_Name("include_fname",   "Include Score Filename"),
00094     PRM_Name("time_mode",       "Add offset to note start time"),
00095     PRM_Name("time_offset",     "Offset (Frames)"),
00096         PRM_Name("console_out", "Echo score to console"),
00097     PRM_Name("comment",         "Comments"),
00098     PRM_Name("write_file",  "Write CSound Score File"),
00099 
00100         // f-table #1 page
00101     PRM_Name("ftable_1_on",                     "Generate f-table #1"),
00102     PRM_Name("gen_num_1",                       "GEN Table Type"),
00103     PRM_Name("snd_fname_1",                     "Audio Filename"),
00104     PRM_Name("ftable_1",                        "f-table #"),
00105     PRM_Name("ftable_1_init",                   "f-table Init Time"),
00106     PRM_Name("ftable_1_len",                    "f-table Length"),
00107     PRM_Name("ftable_1_grd_pt",                 "Guard Point"),
00108     PRM_Name("ftable_1_gen_param_1",            "GEN p5"),
00109     PRM_Name("ftable_1_gen_param_2",            "GEN p6"),
00110     PRM_Name("ftable_1_gen_param_3",            "GEN p7"),
00111     PRM_Name("ftable_1_gen_param_4",            "GEN p8"),
00112     PRM_Name("ftable_1_gen_param_5",            "GEN p9"),
00113     PRM_Name("ftable_1_gen_param_6",            "GEN p10"),
00114     PRM_Name("ftable_1_gen_param_7",            "GEN p11"),
00115     PRM_Name("ftable_1_gen_param_8",            "GEN p12"),
00116 
00117         // f-table #2 page
00118     PRM_Name("ftable_2_on",                     "Generate f-table #2"),
00119     PRM_Name("gen_num_2",                       "GEN Table Type"),
00120     PRM_Name("snd_fname_2",                     "Audio Filename"),
00121     PRM_Name("ftable_2",                        "f-table #"),
00122     PRM_Name("ftable_2_init",                   "f-table Init Time"),
00123     PRM_Name("ftable_2_len",                    "f-table Length"),
00124     PRM_Name("ftable_2_grd_pt",                 "Guard Point"),
00125     PRM_Name("ftable_2_gen_param_1",            "GEN p5"),
00126     PRM_Name("ftable_2_gen_param_2",            "GEN p6"),
00127     PRM_Name("ftable_2_gen_param_3",            "GEN p7"),
00128     PRM_Name("ftable_2_gen_param_4",            "GEN p8"),
00129     PRM_Name("ftable_2_gen_param_5",            "GEN p9"),
00130     PRM_Name("ftable_2_gen_param_6",            "GEN p10"),
00131     PRM_Name("ftable_2_gen_param_7",            "GEN p11"),
00132     PRM_Name("ftable_2_gen_param_8",            "GEN p12"),
00133 
00134         // f-table #3 page
00135     PRM_Name("ftable_3_on",             "Generate f-table #3"),
00136     PRM_Name("gen_num_3",               "GEN Table Type"),
00137     PRM_Name("snd_fname_3",             "Audio Filename"),
00138     PRM_Name("ftable_3",                "f-table #"),
00139     PRM_Name("ftable_3_init",           "f-table Init Time"),
00140     PRM_Name("ftable_3_len",            "f-table Length"),
00141     PRM_Name("ftable_3_grd_pt",         "Guard Point"),
00142 
00143     PRM_Name("ftable_3_gen_param",              "GEN parameters"),
00144 
00145 //    PRM_Name("ftable_3_gen_param_1",                  "GEN p5"),
00146 //    PRM_Name("ftable_3_gen_param_2",                  "GEN p6"),
00147 //    PRM_Name("ftable_3_gen_param_3",                  "GEN p7"),
00148 //    PRM_Name("ftable_3_gen_param_4",                  "GEN p8"),
00149 //    PRM_Name("ftable_3_gen_param_5",                  "GEN p9"),
00150 //    PRM_Name("ftable_3_gen_param_6",                  "GEN p10"),
00151 //    PRM_Name("ftable_3_gen_param_7",                  "GEN p11"),
00152 //    PRM_Name("ftable_3_gen_param_8",                  "GEN p12"),
00153 
00154         // f-table #4 page
00155     PRM_Name("ftable_4_on",             "Generate f-table #4"),
00156     PRM_Name("gen_num_4",               "GEN Table Type"),
00157     PRM_Name("snd_fname_4",             "Audio Filename"),
00158     PRM_Name("ftable_4",                "f-table #"),
00159     PRM_Name("ftable_4_init",           "f-table Init Time"),
00160     PRM_Name("ftable_4_len",            "f-table Length"),
00161     PRM_Name("ftable_4_grd_pt",         "Guard Point"),
00162 
00163     PRM_Name("ftable_4_gen_param",              "GEN parameters"),
00164 
00165 //    PRM_Name("ftable_4_gen_param_1",                  "GEN p5"),
00166 //    PRM_Name("ftable_4_gen_param_2",                  "GEN p6"),
00167 //    PRM_Name("ftable_4_gen_param_3",                  "GEN p7"),
00168 //    PRM_Name("ftable_4_gen_param_4",                  "GEN p8"),
00169 //    PRM_Name("ftable_4_gen_param_5",                  "GEN p9"),
00170 //    PRM_Name("ftable_4_gen_param_6",                  "GEN p10"),
00171 //    PRM_Name("ftable_4_gen_param_7",                  "GEN p11"),
00172 //    PRM_Name("ftable_4_gen_param_8",                  "GEN p12"),
00173 
00174 };
00175 
00176 // the instrument name menu
00177 static PRM_Name CHOP_inst_nameMenu[] = {
00178     PRM_Name("000",     "Other"),
00179     PRM_Name("001",     "AcousticGrandPiano"),
00180     PRM_Name("002",     "BrightAcousticPiano"),
00181     PRM_Name("003",     "ElectricGrandPiano"),
00182     PRM_Name("004",     "Honky-tonkPiano"),
00183     PRM_Name("005",     "ElectricPiano1"),
00184     PRM_Name("006",     "ElectricPiano2"),
00185     PRM_Name("007",     "Harpsichord"),
00186     PRM_Name("008",     "Clavi"),
00187     PRM_Name("009",     "Celesta"),
00188     PRM_Name("010",     "Glockenspiel"),
00189     PRM_Name("011",     "MusicBox"),
00190     PRM_Name("012",     "Vibraphone"),
00191     PRM_Name("013",     "Marimba"),
00192     PRM_Name("014",     "Xylophone"),
00193     PRM_Name("015",     "TubularBells"),
00194     PRM_Name("016",     "Dulcimer"),
00195     PRM_Name("017",     "DrawbarOrgan"),
00196     PRM_Name("018",     "PercussiveOrgan"),
00197     PRM_Name("019",     "RockOrgan"),
00198     PRM_Name("020",     "ChurchOrgan"),
00199     PRM_Name("021",     "ReedOrgan"),
00200     PRM_Name("022",     "Accordion"),
00201     PRM_Name("023",     "Harmonica"),
00202     PRM_Name("024",     "TangoAccordion"),
00203     PRM_Name("025",     "AcousticGuitarNylon"),
00204     PRM_Name("026",     "AcousticGuitarSteel"),
00205     PRM_Name("027",     "ElectricGuitarJazz"),
00206     PRM_Name("028",     "ElectricGuitarClean"),
00207     PRM_Name("029",     "ElectricGuitarMuted"),
00208     PRM_Name("030",     "OverdrivenGuitar"),
00209     PRM_Name("031",     "DistortionGuitar"),
00210     PRM_Name("032",     "GuitarHarmonics"),
00211         PRM_Name("033", "AcousticBass"),         
00212         PRM_Name("034", "ElectricBassFinger"),   
00213         PRM_Name("035", "ElectricBassPick"),     
00214         PRM_Name("036", "FretlessBass"),         
00215         PRM_Name("037", "SlapBass1"),            
00216         PRM_Name("038", "SlapBass2"),            
00217         PRM_Name("039", "SynthBass1"),           
00218         PRM_Name("040", "SynthBass2"),           
00219         PRM_Name("041", "Violin"),               
00220         PRM_Name("042", "Viola"),                
00221         PRM_Name("043", "Cello"),                
00222         PRM_Name("044", "Contrabass"),           
00223         PRM_Name("045", "TremoloStrings"),       
00224         PRM_Name("046", "PizzicatoStrings"),     
00225         PRM_Name("047", "OrchestralHarp"),       
00226         PRM_Name("048", "Timpani"),              
00227         PRM_Name("049", "StringEnsemble1"),      
00228         PRM_Name("050", "StringEnsemble2"),      
00229         PRM_Name("051", "SynthStrings1"),        
00230         PRM_Name("052", "SynthStrings2"),        
00231         PRM_Name("053", "ChoirAhhs"),            
00232         PRM_Name("054", "VoiceOohs"),            
00233         PRM_Name("055", "SynthVoice"),           
00234         PRM_Name("056", "OrchestraHit"),         
00235         PRM_Name("057", "Trumpet"),              
00236         PRM_Name("058", "Trombone"),             
00237         PRM_Name("059", "Tuba"),                 
00238         PRM_Name("060", "MutedTrumpet"),         
00239         PRM_Name("061", "FrenchHorn"),           
00240         PRM_Name("062", "BrassSection"),         
00241         PRM_Name("063", "SynthBrass1"),          
00242         PRM_Name("064", "SynthBrass2"),          
00243         PRM_Name("065", "SopranoSax"),
00244         PRM_Name("066", "AltoSax"),
00245         PRM_Name("067", "TenorSax"),
00246         PRM_Name("068", "BaritoneSax"),
00247         PRM_Name("069", "Oboe"),
00248         PRM_Name("070", "EnglishHorn"),
00249         PRM_Name("071", "Bassoon"),
00250         PRM_Name("072", "Clarinet"),
00251         PRM_Name("073", "Piccolo"),
00252         PRM_Name("074", "Flute"),
00253         PRM_Name("075", "Recorder"),
00254         PRM_Name("076", "PanFlute"),
00255         PRM_Name("077", "BlownBottle"),
00256         PRM_Name("078", "Shakuhachi"),
00257         PRM_Name("079", "Whistle"),
00258         PRM_Name("080", "Ocarina"),
00259         PRM_Name("081", "Lead1Square"),
00260         PRM_Name("082", "Lead2SawTooth"),
00261         PRM_Name("083", "Lead3Calliope"),
00262         PRM_Name("084", "Lead4Chiff"),
00263         PRM_Name("085", "Lead5Charang"),
00264         PRM_Name("086", "Lead6Voice"),
00265         PRM_Name("087", "Lead7Fifths"),
00266         PRM_Name("088", "Lead8Bass+Lead"),
00267         PRM_Name("089", "Pad1NewAge"),
00268         PRM_Name("090", "Pad2Warm"),
00269         PRM_Name("091", "Pad3PolySynth"),
00270         PRM_Name("092", "Pad4Choir"),
00271         PRM_Name("093", "Pad5Bowed"),
00272         PRM_Name("094", "Pad6Metallic"),
00273         PRM_Name("095", "Pad7Halo"),
00274         PRM_Name("096", "Pad8Sweep"),
00275         PRM_Name("097", "FX1Rain"),
00276         PRM_Name("098", "FX2Soundtrack"),
00277         PRM_Name("099", "FX3Crystal"),
00278         PRM_Name("100", "FX4Atmosphere"),
00279         PRM_Name("101", "FX5Brightness"),
00280         PRM_Name("102", "FX6Goblins"),
00281         PRM_Name("103", "FX7Echoes"),
00282         PRM_Name("104", "FX8Sci-Fi"),
00283         PRM_Name("105", "Sitar"),
00284         PRM_Name("106", "Banjo"),
00285         PRM_Name("107", "Shamisen"),
00286         PRM_Name("108", "Koto"),
00287         PRM_Name("109", "Kalimba"),
00288         PRM_Name("110", "Bagpipe"),
00289         PRM_Name("111", "Fiddle"),
00290         PRM_Name("112", "Shanai"),
00291         PRM_Name("113", "TinkleBell"),
00292         PRM_Name("114", "Agogo"),
00293         PRM_Name("115", "SteelDrums"),
00294         PRM_Name("116", "Woodblock"),
00295         PRM_Name("117", "TaikoDrum"),
00296         PRM_Name("118", "MelodicTom"),
00297         PRM_Name("119", "SynthDrum"),
00298         PRM_Name("120", "ReverseCymbal"),
00299         PRM_Name("121", "GuitarFretNoise"),
00300         PRM_Name("122", "BreathNoise"),
00301         PRM_Name("123", "Seashore"),
00302         PRM_Name("124", "BirdTweet"),
00303         PRM_Name("125", "TelephoneRing"),
00304         PRM_Name("126", "Helicopter"),
00305         PRM_Name("127", "Applause"),
00306 
00307     PRM_Name(0),
00308 };
00309 
00310 // the GEN table type menu
00311 static PRM_Name CHOP_GEN_type_Menu[] = {
00312     PRM_Name("001",     "1-Soundfile"),
00313     PRM_Name("002",     "2-Numeric Value Access"),
00314     PRM_Name("003",     "3-Waveshaping Polynomials"),
00315     PRM_Name("004",     "4-Amplitude Normalization"),
00316     PRM_Name("005",     "5-Exponential Segment"),
00317     PRM_Name("006",     "6-Cubic Segment"),
00318     PRM_Name("007",     "7-Line Segment"),
00319     PRM_Name("008",     "8-Spline Segment"),
00320     PRM_Name("009",     "9-Sine"),
00321     PRM_Name("010",     "10-Sine"),
00322     PRM_Name("011",     "11-Cosine"),
00323     PRM_Name("012",     "12-Amplitude Normalization"),
00324     PRM_Name("013",     "13-Waveshaping-Chebyshev first order"),
00325     PRM_Name("014",     "14-Waveshaping-Chebyshev second order"),
00326     PRM_Name("015",     "15-Waveshaping-phase-quadrature"),
00327     PRM_Name("017",     "17-Numeric Value Access"),
00328     PRM_Name("019",     "19-Sine"),
00329     PRM_Name("020",     "20-Window Function"),
00330     PRM_Name("021",     "21-Random Function"),
00331     PRM_Name("023",     "23-External File"),
00332     PRM_Name("025",     "25-Line/Exponential Segment"),
00333     PRM_Name("027",     "27-Line/Exponential Segment"),
00334 
00335     PRM_Name(0),
00336 };
00337 
00338 // the GEN table length menu 
00339 static PRM_Name CHOP_f_table_len_Menu[] = {
00340     PRM_Name("128",             "128"),
00341     PRM_Name("256",             "256"),
00342     PRM_Name("512",             "512"),
00343     PRM_Name("1024",    "1024"),
00344     PRM_Name("2048",    "2048"),
00345     PRM_Name("4096",    "4096"),
00346     PRM_Name("8192",    "8192"),
00347     PRM_Name("16384",   "16384"),
00348     PRM_Name("32768",   "32768"),
00349     PRM_Name("65536",   "65536"),
00350 
00351     PRM_Name(0),
00352 };
00353 
00354 static PRM_ChoiceList inst_nameMenu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE | PRM_CHOICELIST_REPLACE), CHOP_inst_nameMenu);
00355 static PRM_ChoiceList GEN_type_Menu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE | PRM_CHOICELIST_REPLACE), CHOP_GEN_type_Menu);
00356 static PRM_ChoiceList f_table_len_Menu((PRM_ChoiceListType)(PRM_CHOICELIST_EXCLUSIVE | PRM_CHOICELIST_REPLACE), CHOP_f_table_len_Menu);
00357 
00358 static PRM_Range   offsetRange(PRM_RANGE_RESTRICTED, -65535, PRM_RANGE_UI, 65536);
00359 
00360 // Setup page defaults
00361 static PRM_Default Default_score_fname(0,"untitled.sco");
00362 static PRM_Default Default_include_fname(0, "csound_header.h");
00363 static PRM_Default Default_comment(0,"Comments");
00364 
00365 // f-table #1 page defaults
00366 static PRM_Default Default_snd_fname_1(0,"untitled.aiff");
00367 static PRM_Default Default_ftable_1_len(0,"1024");
00368 
00369 // f-table #2 page defaults
00370 static PRM_Default Default_snd_fname_2(0,"untitled.aiff");
00371 static PRM_Default Default_ftable_2_len(0,"1024");
00372 
00373 // f-table #3 page defaults
00374 static PRM_Default Default_snd_fname_3(0,"untitled.aiff");
00375 static PRM_Default Default_ftable_3_len(0,"1024");
00376 static PRM_Default Default_ftable_3_gen_parm(0,"0 1 0 1 0 1 0 1 0 1");
00377 
00378 // f-table #4 page defaults
00379 static PRM_Default Default_snd_fname_4(0,"untitled.aiff");
00380 static PRM_Default Default_ftable_4_len(0,"1024");
00381 static PRM_Default Default_ftable_4_gen_parm(0,"0 1 0 1 0 1 0 1 0 1");
00382 
00383 PRM_Template
00384 CHOP_csound_score::myTemplateList[] =
00385 {
00386     PRM_Template(PRM_SWITCHER,  6, &PRMswitcherName, switcher),
00387 
00388         // Setup page
00389         //
00390         // Score Filename
00391     PRM_Template(PRM_FILE,      1, &names[0], &Default_score_fname, 0),
00392 
00393         // Instrument Number
00394     PRM_Template(PRM_INT_J,     1, &names[1], PRMzeroDefaults, 0),
00395 
00396         // Instrument Name Menu
00397     PRM_Template(PRM_ORD,       1, &names[2], PRMzeroDefaults, &inst_nameMenu),
00398 
00399         // Use instrument input
00400     PRM_Template(PRM_TOGGLE,    1, &names[3], PRMzeroDefaults, 0),
00401 
00402         // Override default note duration
00403     PRM_Template(PRM_TOGGLE,    1, &names[4], PRMzeroDefaults, 0),
00404 
00405         // Event Duration
00406     PRM_Template(PRM_FLT_J,     1, &names[5], PRMoneDefaults, 0),
00407 
00408         // Use event gate input
00409     PRM_Template(PRM_TOGGLE,    1, &names[6], PRMzeroDefaults, 0),
00410 
00411         // Use score include file
00412     PRM_Template(PRM_TOGGLE,    1, &names[7], PRMzeroDefaults, 0),
00413 
00414         // Include Score Filename
00415     PRM_Template(PRM_FILE,      1, &names[8], &Default_include_fname, 0),
00416 
00417         // Add offset to time
00418     PRM_Template(PRM_TOGGLE,    1, &names[9], PRMoneDefaults, 0),
00419 
00420         // Amount of time offset
00421     PRM_Template(PRM_FLT_J,     1, &names[10], PRMzeroDefaults, 0, &offsetRange),
00422 
00423         // Echo score to console 
00424     PRM_Template(PRM_TOGGLE,    1, &names[11], PRMzeroDefaults, 0),
00425 
00426         // Comments
00427     PRM_Template(PRM_STRING,    1, &names[12], &Default_comment, 0),
00428 
00429     PRM_Template(PRM_CALLBACK,  1, &names[13], 0, 0, 0,
00430                                 CHOP_csound_score::writeTheFile),
00431 
00432 
00433         // f-table #1
00434         // 
00435         // gen f-table #1
00436     PRM_Template(PRM_TOGGLE,    1, &names[parm_setup_offset + 0], 
00437                                                                         PRMzeroDefaults, 0),
00438         // GEN Table Type
00439     PRM_Template(PRM_ORD,       1, &names[parm_setup_offset + 1], 
00440                                                                         PRMzeroDefaults, 
00441                                                                         &GEN_type_Menu),
00442         // Audio Filename
00443     PRM_Template(PRM_FILE,      1, &names[parm_setup_offset + 2], 
00444                                                                         &Default_snd_fname_1, 0),
00445         // f-table #
00446     PRM_Template(PRM_INT_J,     1, &names[parm_setup_offset + 3], 
00447                                                                         PRMzeroDefaults, 0),
00448         // f-table Init Time
00449     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 4], 
00450                                                                         PRMzeroDefaults, 0),
00451         // f-table Length
00452     PRM_Template(PRM_ORD,       1, &names[parm_setup_offset + 5], 
00453                                                                         &Default_ftable_1_len,
00454                                                                         &f_table_len_Menu),
00455         // Guard Point
00456     PRM_Template(PRM_TOGGLE,    1, &names[parm_setup_offset + 6], 
00457                                                                         PRMzeroDefaults, 0),
00458         // GEN p5
00459     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 7], 
00460                                                                         PRMzeroDefaults, 0),
00461         // GEN p6
00462     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 8], 
00463                                                                         PRMzeroDefaults, 0),
00464         // GEN p7
00465     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 9], 
00466                                                                         PRMzeroDefaults, 0),
00467         // GEN p8
00468     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 10], 
00469                                                                         PRMzeroDefaults, 0),
00470         // GEN p9
00471     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 11], 
00472                                                                         PRMzeroDefaults, 0),
00473         // GEN p10
00474     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 12], 
00475                                                                         PRMzeroDefaults, 0),
00476         // GEN p11
00477     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 13], 
00478                                                                         PRMzeroDefaults, 0),
00479         // GEN p12
00480     PRM_Template(PRM_FLT_J,     1, &names[parm_setup_offset + 14], 
00481                                                                         PRMzeroDefaults, 0),
00482 
00483         // f-table #2
00484         // 
00485         // gen f-table #2
00486     PRM_Template(PRM_TOGGLE,    1, &names[parm_f1_offset + 0], 
00487                                                                         PRMzeroDefaults, 0),
00488         // GEN Table Type
00489     PRM_Template(PRM_ORD,       1, &names[parm_f1_offset + 1], 
00490                                                                         PRMzeroDefaults, 
00491                                                                         &GEN_type_Menu),
00492         // Audio Filename
00493     PRM_Template(PRM_FILE,      1, &names[parm_f1_offset + 2], 
00494                                                                         &Default_snd_fname_2, 0),
00495         // f-table #
00496     PRM_Template(PRM_INT_J,     1, &names[parm_f1_offset + 3], 
00497                                                                         PRMzeroDefaults, 0),
00498         // f-table Init Time
00499     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 4], 
00500                                                                         PRMzeroDefaults, 0),
00501         // f-table Length
00502     PRM_Template(PRM_ORD,       1, &names[parm_f1_offset + 5], 
00503                                                                         &Default_ftable_2_len,
00504                                                                         &f_table_len_Menu),
00505         // Guard Point
00506     PRM_Template(PRM_TOGGLE,    1, &names[parm_f1_offset + 6], 
00507                                                                         PRMzeroDefaults, 0),
00508         // GEN p5
00509     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 7], 
00510                                                                         PRMzeroDefaults, 0),
00511         // GEN p6
00512     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 8], 
00513                                                                         PRMzeroDefaults, 0),
00514         // GEN p7
00515     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 9], 
00516                                                                         PRMzeroDefaults, 0),
00517         // GEN p8
00518     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 10], 
00519                                                                         PRMzeroDefaults, 0),
00520         // GEN p9
00521     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 11], 
00522                                                                         PRMzeroDefaults, 0),
00523         // GEN p10
00524     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 12], 
00525                                                                         PRMzeroDefaults, 0),
00526         // GEN p11
00527     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 13], 
00528                                                                         PRMzeroDefaults, 0),
00529         // GEN p12
00530     PRM_Template(PRM_FLT_J,     1, &names[parm_f1_offset + 14], 
00531                                                                         PRMzeroDefaults, 0),
00532 
00533         // f-table #3
00534         // 
00535         // gen f-table #3
00536     PRM_Template(PRM_TOGGLE,    1, &names[parm_f2_offset + 0], 
00537                                                                         PRMzeroDefaults, 0),
00538         // GEN Table Type
00539     PRM_Template(PRM_ORD,       1, &names[parm_f2_offset + 1], 
00540                                                                         PRMzeroDefaults,
00541                                                                         &GEN_type_Menu),
00542         // Audio Filename
00543     PRM_Template(PRM_FILE,      1, &names[parm_f2_offset + 2], 
00544                                                                         &Default_snd_fname_3, 0),
00545         // f-table #
00546     PRM_Template(PRM_INT_J,     1, &names[parm_f2_offset + 3], 
00547                                                                         PRMzeroDefaults, 0),
00548         // f-table Init Time
00549     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 4], 
00550                                                                         PRMzeroDefaults, 0),
00551         // f-table Length
00552     PRM_Template(PRM_ORD,       1, &names[parm_f2_offset + 5], 
00553                                                                         &Default_ftable_3_len,
00554                                                                         &f_table_len_Menu),
00555         // Guard Point
00556     PRM_Template(PRM_TOGGLE,    1, &names[parm_f2_offset + 6], 
00557                                                                         PRMzeroDefaults, 0),
00558         // GEN parameters
00559     PRM_Template(PRM_STRING,    1, &names[parm_f2_offset + 7], 
00560                                                                         &Default_ftable_3_gen_parm, 0),
00561 
00562 /*
00563         // GEN p5
00564     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 7], 
00565                                                                         PRMzeroDefaults, 0),
00566         // GEN p6
00567     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 8], 
00568                                                                         PRMzeroDefaults, 0),
00569         // GEN p7
00570     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 9], 
00571                                                                         PRMzeroDefaults, 0),
00572         // GEN p8
00573     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 10], 
00574                                                                         PRMzeroDefaults, 0),
00575         // GEN p9
00576     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 11], 
00577                                                                         PRMzeroDefaults, 0),
00578         // GEN p10
00579     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 12], 
00580                                                                         PRMzeroDefaults, 0),
00581         // GEN p11
00582     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 13], 
00583                                                                         PRMzeroDefaults, 0),
00584         // GEN p12
00585     PRM_Template(PRM_FLT_J,     1, &names[parm_f2_offset + 14], 
00586                                                                         PRMzeroDefaults, 0),
00587 */
00588 
00589         // f-table #4
00590         // 
00591         // gen f-table #4
00592     PRM_Template(PRM_TOGGLE,    1, &names[parm_f3_offset + 0], 
00593                                                                         PRMzeroDefaults, 0),
00594         // GEN Table Type
00595     PRM_Template(PRM_ORD,       1, &names[parm_f3_offset + 1], 
00596                                                                         PRMzeroDefaults,
00597                                                                         &GEN_type_Menu),
00598         // Audio Filename
00599     PRM_Template(PRM_FILE,      1, &names[parm_f3_offset + 2], 
00600                                                                         &Default_snd_fname_4, 0),
00601         // f-table #
00602     PRM_Template(PRM_INT_J,     1, &names[parm_f3_offset + 3], 
00603                                                                         PRMzeroDefaults, 0),
00604         // f-table Init Time
00605     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 4], 
00606                                                                         PRMzeroDefaults, 0),
00607         // f-table Length
00608     PRM_Template(PRM_ORD,       1, &names[parm_f3_offset + 5], 
00609                                                                         &Default_ftable_4_len,
00610                                                                         &f_table_len_Menu),
00611         // Guard Point
00612     PRM_Template(PRM_TOGGLE,    1, &names[parm_f3_offset + 6], 
00613                                                                         PRMzeroDefaults, 0),
00614         // GEN parameters
00615     PRM_Template(PRM_STRING,    1, &names[parm_f3_offset + 7], 
00616                                                                         &Default_ftable_4_gen_parm, 0),
00617 
00618 /*
00619         // GEN p5
00620     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 7], 
00621                                                                         PRMzeroDefaults, 0),
00622         // GEN p6
00623     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 8], 
00624                                                                         PRMzeroDefaults, 0),
00625         // GEN p7
00626     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 9], 
00627                                                                         PRMzeroDefaults, 0),
00628         // GEN p8
00629     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 10], 
00630                                                                         PRMzeroDefaults, 0),
00631         // GEN p9
00632     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 11], 
00633                                                                         PRMzeroDefaults, 0),
00634         // GEN p10
00635     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 12], 
00636                                                                         PRMzeroDefaults, 0),
00637         // GEN p11
00638     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 13], 
00639                                                                         PRMzeroDefaults, 0),
00640         // GEN p12
00641     PRM_Template(PRM_FLT_J,     1, &names[parm_f3_offset + 14], 
00642                                                                         PRMzeroDefaults, 0),
00643 */
00644 
00645     PRM_Template(),
00646 };
00647 
00648 OP_Node *
00649 CHOP_csound_score::myConstructor(OP_Network             *net,
00650                              const char         *name,
00651                              OP_Operator        *op)
00652 {
00653     return new CHOP_csound_score(net, name, op);
00654 }
00655 
00656 
00657 // add this operator to the OP table
00658 void
00659 newChopOperator(OP_OperatorTable *table)
00660     {
00661     table->addOperator(
00662         new OP_Operator("csound_score",                 // Internal name
00663                         "CSound Score Generator",           // UI name
00664                          CHOP_csound_score::myConstructor,  // CHOP constructor
00665                         &CHOP_csound_score::myTemplatePair, // Parameters
00666                          1,                          // Min # of inputs
00667                          3,                          // Max # of inputs
00668                         &CHOP_csound_score::myVariablePair) // Local variables
00669     );
00670 }
00671 
00672 #endif
00673 
00674 
00675 // The Constructor
00676 CHOP_csound_score::CHOP_csound_score( OP_Network        *net,
00677                           const char    *name,
00678                           OP_Operator   *op)
00679                         : CHOP_Node(net, name, op),
00680                 myExpandArray()
00681 {
00682     myParmBase = getParmList()->getParmIndex( names[0].getToken() );
00683 
00684         // init local vars
00685     my_C = 0;
00686     my_NC = 0;
00687     my_INST_NUM = 0;
00688     my_DUR = 0;
00689 
00690         // setup page 
00691         score_fname = "untitled.sco";
00692     inst = 101;
00693     inst_name = 0;
00694     use_inst_in = 0;
00695     dur_override = 0;
00696     duration = 0.033333333;
00697     use_event_gate = 0;
00698     inc_tog = 0;
00699         inc_fname = "csound_header.h";
00700     console_out = 0;
00701         comment = "Comments";
00702 
00703     // f-table #1 parms
00704     snd_fname_1 = "";
00705     ftable_1_on = 0;
00706     ftable_1 = 1;
00707     gen_num_1 = 0;
00708     ftable_1_init = 0;
00709     ftable_1_len = 0;
00710     ftable_1_grd_pt = 0;
00711     ftable_1_gen_param_1 = 0;
00712     ftable_1_gen_param_2 = 0;
00713     ftable_1_gen_param_3 = 0;
00714     ftable_1_gen_param_4 = 0;
00715     ftable_1_gen_param_5 = 0;
00716     ftable_1_gen_param_6 = 0;
00717     ftable_1_gen_param_7 = 0;
00718     ftable_1_gen_param_8 = 0;
00719 
00720     // f-table #2 parms
00721     snd_fname_2 = "";
00722     ftable_2_on = 0;
00723     ftable_2 = 2;
00724     gen_num_2 = 0;
00725     ftable_2_init = 0;
00726     ftable_2_len = 0;
00727     ftable_2_grd_pt = 0;
00728     ftable_2_gen_param_1 = 0;
00729     ftable_2_gen_param_2 = 0;
00730     ftable_2_gen_param_3 = 0;
00731     ftable_2_gen_param_4 = 0;
00732     ftable_2_gen_param_5 = 0;
00733     ftable_2_gen_param_6 = 0;
00734     ftable_2_gen_param_7 = 0;
00735     ftable_2_gen_param_8 = 0;
00736 
00737     // f-table #3 parms
00738     snd_fname_3 = "";
00739     ftable_3_on = 0;
00740     ftable_3 = 3;
00741     gen_num_3 = 0;
00742     ftable_3_init = 0;
00743     ftable_3_len = 0;
00744     ftable_3_grd_pt = 0;
00745     ftable_3_gen_param = "";
00746 
00747 /*
00748     ftable_3_gen_param_1 = 0;
00749     ftable_3_gen_param_2 = 0;
00750     ftable_3_gen_param_3 = 0;
00751     ftable_3_gen_param_4 = 0;
00752     ftable_3_gen_param_5 = 0;
00753     ftable_3_gen_param_6 = 0;
00754     ftable_3_gen_param_7 = 0;
00755     ftable_3_gen_param_8 = 0;
00756 */
00757 
00758     // f-table #4 parms
00759     snd_fname_4 = "";
00760     ftable_4_on = 0;
00761     ftable_4 = 4;
00762     gen_num_4 = 0;
00763     ftable_4_init = 0;
00764     ftable_4_len = 0;
00765     ftable_4_grd_pt = 0;
00766     ftable_4_gen_param = "";
00767 
00768 /*
00769     ftable_4_gen_param_1 = 0;
00770     ftable_4_gen_param_2 = 0;
00771     ftable_4_gen_param_3 = 0;
00772     ftable_4_gen_param_4 = 0;
00773     ftable_4_gen_param_5 = 0;
00774     ftable_4_gen_param_6 = 0;
00775     ftable_4_gen_param_7 = 0;
00776     ftable_4_gen_param_8 = 0;
00777 */
00778 
00779 /*
00780     if(debug_str != "0") {
00781         DEBUG = atoi(debug_str); }
00782     else {
00783         DEBUG = 0; }
00784 */
00785 
00786 
00787 
00788 if(DEBUG > 0) {
00789         printf("\n**** CHOP CSound Score DSO ****\n");
00790         printf("**** CONSTRUCTOR ****\n\n");
00791 
00792         printf("score fname: %s\n", (const char *)score_fname); 
00793         printf("inst: %d\n", inst); 
00794         printf("inst_name: %d\n", inst_name); 
00795         printf("use_inst_in: %d\n", use_inst_in); 
00796         printf("duration override: %d\n", dur_override); 
00797         printf("event duration: %f\n", duration); 
00798         printf("use_event_gate: %d\n", use_event_gate); 
00799         printf("include toggle: %d\n", inc_tog); 
00800         printf("include  fname: %s\n", (const char *)inc_fname); 
00801         printf("console out: %d\n", console_out); 
00802         printf("comment: %s\n", (const char *)comment); 
00803 
00804 }
00805 
00806 }
00807 
00808 CHOP_csound_score::~CHOP_csound_score()
00809 {
00810 if(DEBUG > 0) {
00811         printf("\n**** CHOP CSound Score DSO ****\n");
00812         printf("**** DESTRUCTOR ****\n\n");
00813 }
00814 }
00815 
00816 unsigned
00817 CHOP_csound_score::disableParms()
00818 {
00819     unsigned    changes = CHOP_Node::disableParms();
00820 
00821     return changes;
00822 }
00823 
00824 
00825 // write the score file header including the f-tbales
00826 // and an include file in the user requested it
00827 bool
00828 CHOP_csound_score::writeHeader(FILE *fp)
00829 {
00830 struct          tm *time_ptr;
00831 time_t          create_time;
00832 FILE            *inc_fp;
00833 
00834 // Get the current time
00835 create_time = time(NULL);
00836 time_ptr = localtime(&create_time);
00837 char            str[255];
00838 char            ftable_1_str[255] = "";
00839 char            ftable_2_str[255] = "";
00840 char            ftable_3_str[255] = "";
00841 char            ftable_4_str[255] = "";
00842 
00843 // start to build the f-table strings 
00844 if(ftable_1_on) {
00845         if((gen_num_1 == 1) || (gen_num_1 == 23)) {
00846                 sprintf(ftable_1_str, "f%d\t%f\t%d\t%s\n", 
00847                         ftable_1, ftable_1_init, 
00848                         gen_num_1, (const char *)snd_fname_1);  
00849         }
00850         else {          
00851                 sprintf(ftable_1_str, 
00852                         "f%d\t%f\t%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
00853                         ftable_1, ftable_1_init, ftable_1_len, gen_num_1, 
00854                         ftable_1_gen_param_1, ftable_1_gen_param_2, 
00855                         ftable_1_gen_param_3, ftable_1_gen_param_4,
00856                         ftable_1_gen_param_5, ftable_1_gen_param_6,
00857                         ftable_1_gen_param_7, ftable_1_gen_param_8);
00858         }
00859 }
00860 
00861 if(ftable_2_on) {
00862         if((gen_num_2 == 1) || (gen_num_2 == 23)) {
00863                 sprintf(ftable_2_str, "f%d\t%f\t%d\t%s\n", 
00864                         ftable_2, ftable_2_init, 
00865                         gen_num_2, (const char *)snd_fname_2);  
00866         }
00867         else {          
00868                 sprintf(ftable_2_str, 
00869                         "f%d\t%f\t%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
00870                         ftable_2, ftable_2_init, ftable_2_len, gen_num_2, 
00871                         ftable_2_gen_param_1, ftable_2_gen_param_2, 
00872                         ftable_2_gen_param_3, ftable_2_gen_param_4,
00873                         ftable_2_gen_param_5, ftable_2_gen_param_6,
00874                         ftable_2_gen_param_7, ftable_2_gen_param_8);
00875         }
00876 }
00877 
00878 if(ftable_3_on) {
00879         if((gen_num_3 == 1) || (gen_num_3 == 23)) {
00880                 sprintf(ftable_3_str, "f%d\t%f\t%d\t%s\n", 
00881                         ftable_3, ftable_3_init, 
00882                         gen_num_3, (const char *)snd_fname_3);  
00883         }
00884         else {          
00885                 sprintf(ftable_3_str, 
00886 //                      "f%d\t%f\t%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
00887                         "f%d\t%f\t%d\t%d\t%s\n",
00888                         ftable_3, ftable_3_init, ftable_3_len, gen_num_3, 
00889                         (const char *)ftable_3_gen_param); 
00890 /*
00891                         ftable_3_gen_param_1, ftable_3_gen_param_2, 
00892                         ftable_3_gen_param_3, ftable_3_gen_param_4,
00893                         ftable_3_gen_param_5, ftable_3_gen_param_6,
00894                         ftable_3_gen_param_7, ftable_3_gen_param_8);
00895 */
00896 
00897         }
00898 }
00899 
00900 if(ftable_4_on) {
00901         if((gen_num_4 == 1) || (gen_num_4 == 23)) {
00902                 sprintf(ftable_4_str, "f%d\t%f\t%d\t%s\n", 
00903                         ftable_4, ftable_4_init, 
00904                         gen_num_4, (const char *)snd_fname_4);  
00905         }
00906         else {          
00907                 sprintf(ftable_4_str, 
00908 //                      "f%d\t%f\t%d\t%d\t%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n",
00909                         "f%d\t%f\t%d\t%d\t%s\n",
00910                         ftable_4, ftable_4_init, ftable_4_len, gen_num_4, 
00911                         (const char *)ftable_4_gen_param); 
00912 /*
00913                         ftable_4_gen_param_1, ftable_4_gen_param_2, 
00914                         ftable_4_gen_param_3, ftable_4_gen_param_4,
00915                         ftable_4_gen_param_5, ftable_4_gen_param_6,
00916                         ftable_4_gen_param_7, ftable_4_gen_param_8);
00917 */
00918 
00919         }
00920 }
00921 
00922 // if user wants the data echoed to the console
00923 if((DEBUG > 0) || console_out) {
00924         printf("; CSound Score generated by DCA CSound Score Generator CHOP \n");
00925         printf("; %s\n", asctime(time_ptr));
00926         printf("; %s\n\n", (const char *)comment);
00927                 
00928         printf("%s%s%s%s\n", 
00929                         ftable_1_str, ftable_2_str, ftable_3_str, ftable_4_str);
00930 }
00931 
00932 fprintf(fp, "; CSound Score generated by DCA CSound Score Generator CHOP\n");
00933 fprintf(fp, "; %s\n", asctime(time_ptr));
00934 fprintf(fp, "; %s\n", (const char *)comment);
00935 fprintf(fp, "%s%s%s%s\n",
00936                 ftable_1_str, ftable_2_str, ftable_3_str, ftable_4_str);
00937 
00938 // If an include has been specified, open the file.
00939 if(inc_tog) {
00940         fprintf(fp, "; CSound score include file: %s\n\n", 
00941                         (const char *)inc_fname);
00942 
00943         if((DEBUG > 0) || console_out) {        
00944                                 printf("; CSound score include file: %s\n\n",
00945                                 (const char *)inc_fname); 
00946         }
00947 
00948         // Open the score include file for reading
00949         if((inc_fp=fopen(inc_fname,"r")) == NULL) {
00950                 cout.setf(ios::unitbuf);
00951                 cout << "Cannot open score include file for reading\n";
00952         addError(CHOP_ERROR_MESSAGE);
00953                 return false;
00954         }
00955         // read the entire include file and print to the score file
00956         while(!feof(inc_fp)) {
00957                 if(fgets(str, 255, inc_fp))
00958                         if((DEBUG > 0) || console_out) { printf("%s", str); }
00959                         fprintf(fp, str); 
00960                 }
00961         fclose(inc_fp);
00962         }
00963 
00964 fflush(fp);
00965 return true;
00966 }
00967 
00968 
00969 // get UI parameters
00970 void
00971 CHOP_csound_score::getUIParms(OP_Context &context)
00972 {
00973 UT_String menu_str = "";
00974 
00975 // setup page parms
00976 SCORE_FNAME(score_fname, context.myTime);
00977 inst = INST(context.myTime);
00978 inst_name = INST_NAME(context.myTime);
00979 
00980 if(inst_name != 0) {
00981         inst = inst_name;
00982         SET_INST(context.myTime, inst_name);
00983 }
00984 
00985 // Setup page
00986 use_inst_in = USE_INST_IN(context.myTime);
00987 dur_override = DUR_OVERRIDE(context.myTime);
00988 if(dur_override)        
00989         duration = DURATION(context.myTime);
00990 use_event_gate = USE_EVENT_GATE(context.myTime);
00991 inc_tog = INC_TOG(context.myTime);
00992 INC_FNAME(inc_fname, context.myTime);
00993 time_mode = TIME_MODE(context.myTime);
00994 time_offset = TIME_OFFSET(context.myTime);
00995 console_out = CONSOLE_OUT(context.myTime);
00996 COMMENT(comment, context.myTime);
00997 
00998 
00999 // f-table #1 parms
01000 SND_FNAME_1(snd_fname_1, context.myTime); 
01001 ftable_1_on = FTBL_1_ON(context.myTime); 
01002 ftable_1 = FTBL_1(context.myTime); 
01003 GEN_NUM_1(menu_str, context.myTime);
01004 gen_num_1 = atoi((const char *)menu_str);
01005 ftable_1_init = FTBL_1_INIT(context.myTime); 
01006 FTBL_1_LEN(menu_str, context.myTime);
01007 ftable_1_len = atoi((const char *)menu_str);
01008 ftable_1_grd_pt = FTBL_1_GRD_PT(context.myTime); 
01009 if(ftable_1_grd_pt)  
01010         ftable_1_len += 1; 
01011 ftable_1_gen_param_1 = FTBL_1_GEN_PARM1(context.myTime); 
01012 ftable_1_gen_param_2 = FTBL_1_GEN_PARM2(context.myTime); 
01013 ftable_1_gen_param_3 = FTBL_1_GEN_PARM3(context.myTime); 
01014 ftable_1_gen_param_4 = FTBL_1_GEN_PARM4(context.myTime); 
01015 ftable_1_gen_param_5 = FTBL_1_GEN_PARM5(context.myTime); 
01016 ftable_1_gen_param_6 = FTBL_1_GEN_PARM6(context.myTime); 
01017 ftable_1_gen_param_7 = FTBL_1_GEN_PARM7(context.myTime); 
01018 ftable_1_gen_param_8 = FTBL_1_GEN_PARM8(context.myTime); 
01019 
01020 
01021 // f-table #2 parms
01022 SND_FNAME_2(snd_fname_2, context.myTime); 
01023 ftable_2_on = FTBL_2_ON(context.myTime); 
01024 ftable_2 = FTBL_2(context.myTime); 
01025 GEN_NUM_2(menu_str, context.myTime);
01026 gen_num_2 = atoi((const char *)menu_str);
01027 ftable_2_init = FTBL_2_INIT(context.myTime); 
01028 FTBL_2_LEN(menu_str, context.myTime);
01029 ftable_2_len = atoi((const char *)menu_str);
01030 ftable_2_grd_pt = FTBL_2_GRD_PT(context.myTime); 
01031 if(ftable_2_grd_pt) 
01032         ftable_2_len += 1;
01033 ftable_2_gen_param_1 = FTBL_2_GEN_PARM1(context.myTime);
01034 ftable_2_gen_param_2 = FTBL_2_GEN_PARM2(context.myTime);
01035 ftable_2_gen_param_3 = FTBL_2_GEN_PARM3(context.myTime);
01036 ftable_2_gen_param_4 = FTBL_2_GEN_PARM4(context.myTime);
01037 ftable_2_gen_param_5 = FTBL_2_GEN_PARM5(context.myTime);
01038 ftable_2_gen_param_6 = FTBL_2_GEN_PARM6(context.myTime);
01039 ftable_2_gen_param_7 = FTBL_2_GEN_PARM7(context.myTime);
01040 ftable_2_gen_param_8 = FTBL_2_GEN_PARM8(context.myTime);
01041 
01042 
01043 // f-table #3 parms
01044 SND_FNAME_3(snd_fname_3, context.myTime); 
01045 ftable_3_on = FTBL_3_ON(context.myTime);
01046 ftable_3 = FTBL_3(context.myTime);  
01047 GEN_NUM_3(menu_str, context.myTime);
01048 gen_num_3 = atoi((const char *)menu_str);
01049 ftable_3_init = FTBL_3_INIT(context.myTime); 
01050 FTBL_3_LEN(menu_str, context.myTime);
01051 ftable_3_len = atoi((const char *)menu_str);
01052 ftable_3_grd_pt = FTBL_3_GRD_PT(context.myTime); 
01053 if(ftable_3_grd_pt) 
01054         ftable_3_len += 1;
01055 
01056 FTBL_3_GEN_PARM(ftable_3_gen_param, context.myTime); 
01057 
01058 /*
01059 ftable_3_gen_param_1 = FTBL_3_GEN_PARM1(context.myTime); 
01060 ftable_3_gen_param_2 = FTBL_3_GEN_PARM2(context.myTime); 
01061 ftable_3_gen_param_3 = FTBL_3_GEN_PARM3(context.myTime); 
01062 ftable_3_gen_param_4 = FTBL_3_GEN_PARM4(context.myTime); 
01063 ftable_3_gen_param_5 = FTBL_3_GEN_PARM5(context.myTime); 
01064 ftable_3_gen_param_6 = FTBL_3_GEN_PARM6(context.myTime); 
01065 ftable_3_gen_param_7 = FTBL_3_GEN_PARM7(context.myTime); 
01066 ftable_3_gen_param_8 = FTBL_3_GEN_PARM8(context.myTime); 
01067 */
01068 
01069 
01070 // f-table #4 parms
01071 SND_FNAME_4(snd_fname_4, context.myTime); 
01072 ftable_4_on = FTBL_4_ON(context.myTime); 
01073 ftable_4 = FTBL_4(context.myTime); 
01074 GEN_NUM_4(menu_str, context.myTime);
01075 gen_num_4 = atoi((const char *)menu_str);
01076 ftable_4_init = FTBL_4_INIT(context.myTime); 
01077 FTBL_4_LEN(menu_str, context.myTime);
01078 ftable_4_len = atoi((const char *)menu_str);
01079 ftable_4_grd_pt = FTBL_4_GRD_PT(context.myTime); 
01080 if(ftable_4_grd_pt) 
01081         ftable_4_len += 1;
01082 
01083 FTBL_4_GEN_PARM(ftable_4_gen_param, context.myTime); 
01084 
01085 /*
01086 ftable_4_gen_param_1 = FTBL_4_GEN_PARM1(context.myTime); 
01087 ftable_4_gen_param_2 = FTBL_4_GEN_PARM2(context.myTime); 
01088 ftable_4_gen_param_3 = FTBL_4_GEN_PARM3(context.myTime); 
01089 ftable_4_gen_param_4 = FTBL_4_GEN_PARM4(context.myTime); 
01090 ftable_4_gen_param_5 = FTBL_4_GEN_PARM5(context.myTime); 
01091 ftable_4_gen_param_6 = FTBL_4_GEN_PARM6(context.myTime); 
01092 ftable_4_gen_param_7 = FTBL_4_GEN_PARM7(context.myTime); 
01093 ftable_4_gen_param_8 = FTBL_4_GEN_PARM8(context.myTime); 
01094 */
01095 
01096 
01097 }
01098 
01099 
01100 OP_ERROR
01101 CHOP_csound_score::cookMyChop(OP_Context &context)
01102 {
01103 CL_Track                *track;
01104 const CL_Clip   *parent_clip;
01105 const CL_Track  *parent_track;
01106 const CL_Clip   *event_clip;
01107 const CL_Track  *event_track;
01108 const CL_Clip   *inst_clip;
01109 const CL_Track  *inst_track;
01110 float           *data;
01111 const float     *event_data;
01112 const float     *inst_data;
01113 float                   _data[MAX_CHANNELS];
01114 int                             event_NC = 0;
01115 int                             inst_NC = 0;
01116 int                             parent_NC = 0;
01117 int                             event_gate = 1;
01118 
01119 int                             i = 0, j = 0;
01120 int                             trk_len = 0;
01121 FILE                    *fp;
01122 char                    str[255];
01123 
01124 for(i=0; i < MAX_CHANNELS; i++) { _data[i] = 0; }
01125 
01126 // Get the UI parameters
01127 getUIParms(context);
01128 
01129 // Set the local variables
01130 my_DUR = duration;
01131 my_INST_NUM = inst;
01132 
01133 if(DEBUG > 0) {
01134         printf("\n**** CHOP CSound Score DSO ****\n");
01135         printf("**** COOK MY CHOP ****\n\n");
01136         printf("context.myTime: %f \n", context.myTime);
01137         printf("track length: %d\n", myClip->getTrackLength()); 
01138 
01139         printf("score fname: %s\n", (const char *)score_fname); 
01140         printf("inst: %d\n", inst); 
01141         printf("inst_name: %d\n", inst_name); 
01142         printf("use_inst_in: %d\n", use_inst_in); 
01143         printf("duration override: %d\n", dur_override); 
01144         printf("event duration: %f\n", duration); 
01145         printf("use_event_gate: %d\n", use_event_gate); 
01146         printf("include toggle: %d\n", inc_tog); 
01147         printf("include  fname: %s\n", (const char *)inc_fname); 
01148         printf("console out: %d\n", console_out); 
01149         printf("comment: %s\n", (const char *)comment); 
01150 
01151         printf("f-table #1 len: %d\n", ftable_1_len); 
01152         printf("GEN #1 : %d\n", gen_num_1); 
01153 
01154         printf("f-table #2 len: %d\n", ftable_2_len); 
01155         printf("GEN #2 : %d\n", gen_num_2); 
01156 
01157         printf("f-table #3 len: %d\n", ftable_3_len); 
01158         printf("GEN #3 : %d\n", gen_num_3); 
01159 
01160         printf("f-table #4 len: %d\n", ftable_4_len); 
01161         printf("GEN #4 : %d\n", gen_num_4); 
01162 
01163 }
01164 
01165 // Open file for writing
01166 if((fp=fopen(score_fname,"wa")) == NULL) {
01167         cerr.setf(ios::unitbuf);
01168         cerr << "Cannot open text file for writing\n";
01169         // set unsuccessful result
01170         addWarning(CHOP_ERROR_MESSAGE, "Cannot open text file for writing");
01171         addError(CHOP_ERROR_MESSAGE);
01172         return error();
01173 }
01174 
01175 // get the data channels and track length
01176 parent_clip = copyInput(context, 0, 1, 1);
01177 // get the number of data channels
01178 parent_NC = parent_clip->getNumTracks();
01179 my_NC = myClip->getNumTracks();
01180 trk_len = myClip->getTrackLength();
01181 
01182 if(!dur_override)       
01183         duration = (1/myClip->getSampleRate());
01184 
01185 if(DEBUG > 1) { 
01186         printf("my_NC = %d\n", my_NC); 
01187         printf("trk_len = %d\n", trk_len);
01188 }       
01189 
01190 // If too many input channels, return error
01191 if(my_NC > MAX_CHANNELS) {
01192         addWarning(CHOP_ERROR_MESSAGE, "Too many input channels");
01193         addError(CHOP_ERROR_MESSAGE);
01194     return error();
01195 }
01196 
01197 if(DEBUG > 0) {
01198         UT_String this_chop_path;
01199 
01200         printf("number of connected inputs: %d\n", nConnectedInputs());
01201         getFullPath(this_chop_path);
01202         printf("Full path: %s\n", (const char *)this_chop_path);
01203         printf("parent_NC = %d\n", parent_NC);
01204         printf("my_NC = %d\n", my_NC);
01205 }
01206 
01207 // if the user want's to control the instrument number from input #2 data
01208 if (use_inst_in) {      
01209         // get the instrument input clip and check for valid input
01210         inst_clip = inputClip(1, context);
01211         if (!inst_clip) { 
01212                 addError(OP_ERR_NUMSRC_TOO_FEW);
01213                 return error();
01214         }
01215         inst_NC = inst_clip->getNumTracks();
01216         inst_track = inst_clip->getTrack(0);
01217         inst_data = inst_track->getData();
01218         if(DEBUG > 1) { printf("inst_NC = %d\n", inst_NC); }
01219 }
01220 
01221 
01222 // if the user want's to toggle the data writes with the event input
01223 if (use_event_gate) {   
01224         // get the event input clip and check for valid input
01225         event_clip = inputClip(2, context);
01226         if (!event_clip) { 
01227                 addError(OP_ERR_NUMSRC_TOO_FEW);
01228                 return error();
01229         }
01230         event_NC = event_clip->getNumTracks();
01231         event_track = event_clip->getTrack(0);
01232         event_data = event_track->getData();
01233         if(DEBUG > 1) { printf("event_NC = %d\n", event_NC); }
01234 }
01235 else {
01236         // if no event toggle selected, set event gate true
01237         event_gate = 1;
01238 }
01239 
01240 // write the file header
01241 if(!writeHeader(fp)) {
01242         return error();
01243 }
01244 
01245 // loop through entire track length
01246 for(i=0; i < trk_len; i++) {
01247 
01248         // if user wants to gate the data writes, get the event trigger for the frame
01249         if (use_event_gate) 
01250                 event_gate = (int)event_data[i]; 
01251 
01252         // if event gate is true 
01253         if(event_gate != 0) {
01254 
01255                 if (use_inst_in) 
01256                         inst = (int)inst_data[i]; 
01257 
01258                 // write the instrument number, start time and duration
01259         fprintf(fp, "i %d\t%.8f\t%.8f\t", inst, (myClip->getFrame(time_mode ? (i + time_offset) : i,
01260                                  myClip->getSampleRate()) - 1)/myClip->getSampleRate(), duration);
01261 
01262                 if(console_out) 
01263                 printf("i %d\t%.8f\t%.8f\t", inst, (myClip->getFrame(time_mode ? (i + time_offset) : i,
01264                                         myClip->getSampleRate()) - 1)/myClip->getSampleRate(), duration); 
01265 
01266                 if(DEBUG > 1) {
01267                 printf("i %d\t%.8f\t%.8f\n", inst, (myClip->getFrame(time_mode ? (i + time_offset) : i,
01268                                         myClip->getSampleRate()) - 1)/myClip->getSampleRate(), duration); 
01269                         printf("event_gate = %d\n", event_gate);
01270                         }
01271 
01272                 // loop thru all channels 
01273                 for(my_C = 0; my_C < my_NC; my_C++) {
01274         
01275                         // get my track
01276                         track = myClip->getTrack(my_C);
01277         
01278                         // get pointers to the data for this track
01279                         data = track->getData();
01280 
01281                         _data[my_C] = data[i];
01282 
01283                 fprintf(fp, "%f\t", _data[my_C]); 
01284 
01285                         if(console_out) 
01286                                 printf("%f\t", _data[my_C]);
01287 
01288                         if(DEBUG > 2) 
01289                                 printf("_data = %f\tdata = %f\t my_C = %d\n", _data[my_C], data[i],  my_C);
01290 
01291                 } // end foreach channel
01292 
01293                 // add \n to end of line
01294         fprintf(fp, "\n"); 
01295 
01296                 // if user wants the data echoed to the console
01297                 if(console_out) printf("\n");
01298 
01299     fflush(fp);
01300         } // end if (event_gate) 
01301 
01302         if(DEBUG > 1) { 
01303                 printf("index = %d\t event_gate = %d\n", i, event_gate); 
01304         }
01305                 
01306 } // end foreach index
01307 
01308 
01309 //      reset my_C (?), close file and return
01310 my_C = 0;
01311 fclose(fp);
01312 
01313 return error();
01314 }
01315 
01316 float
01317 CHOP_csound_score::getVariableValue(int index, int)
01318 {
01319     switch( index )
01320     {
01321         case VAR_C:
01322             return my_C;
01323 
01324         case VAR_NC:
01325             return my_NC;
01326 
01327         case VAR_DUR:
01328             return my_DUR;
01329 
01330         case VAR_INST_NUM:
01331             return my_INST_NUM;
01332 
01333         default:
01334             return CHOP_Node::getVariableValue(index);
01335     }
01336 }
01337 
01338 const char *
01339 CHOP_csound_score::inputLabel(unsigned) const
01340 {
01341     return "Instrument Index";
01342 }
01343 
01344 
01345 int CHOP_csound_score::writeTheFile(void *data, int index,
01346         float time, const PRM_Template *tplate ) {
01347 
01348     if(DEBUG > 0)
01349         cout << "writeTheFile() - Writing the Real Flow SD File" << endl;
01350 
01351     CHOP_csound_score *me = (CHOP_csound_score *) data;
01352 
01353     me->calledFromCallback = true;
01354     me->myCallBackFlags = 0;
01355 
01356     OP_Context myContext(time);
01357 
01358 //    myContext.setData(data, OP_GEOMETRY_DATA);
01359 
01360 //  me->cookMySop(myContext);
01361 
01362     me->myCallBackError = me->cookMyChop(myContext);
01363 
01364 //  me->reportCallBackErrors();
01365 
01366     return 1;
01367 }
01368 
01369 

Generated on Wed Sep 17 11:11:53 2003 for Houdini/CSound Extensions by doxygen1.3