I am Coding Create Instruments as Directories

You name it!
ccherrett
Advanced User
Posts: 162
Joined: Wed Jan 23, 2008 11:24 pm
Contact:

I am Coding Create Instruments as Directories

Post by ccherrett » Fri Sep 26, 2008 9:35 am

I am (and my friend) trying to code into linuxsampler and Fantasia the ability to create extra directories out of the names of files found when adding instruments to the database. The reason is for clarity as well as the way VSL gig files are structured. In a VSL gig file you will have many articulations of that instrument. So when Fantasia scans the folder it results in all gig files in that directory being dumped into one directory and makes the database unusable. Creating the database on 300GB of files is very hard and error prone to do.

The import of a directory does this right now.
Image

So I am trying to make a separate checkbox to allow for that file to be used as a directory name and all associated articulations dumped into that directory
Image

So far we have been able to track through:

We have found out that we need to create a brand new flag to the LSCP protocol to speak to linuxsampler to allow us to create folders based on instrument file name.

JSampler:
JSAddDbInstrumentsFromDirDlg.java in Fantasia (added check box to for file names as dir)
/home/chris/cvs-projects/cvs-jsampler-keyboard/jsampler/src/org/jsampler/task/InstrumentsDb.java adding to addDbInstruments a boolean to pass along to the next functions

JLSCP:
src/org/linuxsampler/lscp/Client.java
in this file we overload the addDbInstruments to accept our boolean and then pass that into the buffer writer to be accepted into the socket connection of linuxsampler.

Linuxsampler:
common/File.cpp (This is the end target for getting the protocol into the linuxsampler db)

We now need to figure out what to do with the boolean when passed to the database. How is it read and then wrote to the sqlite3 DB.

Can someone please help to guide us as to the correct way to continue? Is there an easier path? Am I on the right path?

Thanks!
Christopher Cherrett
Founder of The Open Octave Project
http://www.openoctave.org

grishata
Developer
Posts: 138
Joined: Thu Jan 24, 2008 7:21 pm
Location: Bulgaria
Contact:

Re: I am Coding Create Instruments as Directories

Post by grishata » Fri Sep 26, 2008 8:55 pm

ccherrett wrote:We now need to figure out what to do with the boolean when passed to the database. How is it read and then wrote to the sqlite3 DB.
You should look in the linuxsampler/src/db/ directory and more specifically the AddInstruments methods in linuxsampler/src/db/InstrumentsDb.h

Also you should extend the ADD DB_INSTRUMENTS lscp command, which format currently is:

ADD DB_INSTRUMENTS [NON_MODAL] [<mode>] <db_dir> <file_path> [<instr_index>]

Maybe something like:
ADD DB_INSTRUMENTS [NON_MODAL] [<mode> [TO_SUBDIRECTORIES]] <db_dir> <file_path> [<instr_index>]

btw, I would prefer something like "Add instruments to separate directories" instead of "Create instruments as directories"

ccherrett
Advanced User
Posts: 162
Joined: Wed Jan 23, 2008 11:24 pm
Contact:

Re: I am Coding Create Instruments as Directories

Post by ccherrett » Fri Sep 26, 2008 11:23 pm

grishata,

Could you possibly help me to understand what is happening when Fantasia passed information to linuxsampler?

As I see it your are building up a LSCP string command and passing it over a socket to linuxsampler. At this point I am unclear on how to make linuxsampler deal with the new option being passed in the LSCP command.

I have looked at /src/db/InstrumentsDb.cpp and am wondering do you mean doing something like this?

Code: Select all

     int InstrumentsDb::AddInstruments(ScanMode Mode, String DbDir, String FsDir, bool bBackground) {
         dmsg(2,("InstrumentsDb: AddInstruments(Mode=%d,DbDir=%s,FsDir=%s,bBackground=%d)\n", Mode, DbDir.c_str(), FsDir.c_str(), bBackground));
         if(!bBackground) {
             switch (Mode) {
                 case NON_RECURSIVE:
                     AddInstrumentsNonrecursive(DbDir, FsDir);
                     break;
                 case RECURSIVE:
                     AddInstrumentsRecursive(DbDir, FsDir);
                     break;
                case RECURSIVE INST_IN_DIR:
                     AddInstrumentsRecursive(DbDir, FsDir,InstNameDir);
                     break;
                case FLAT:
                     AddInstrumentsRecursive(DbDir, FsDir, true);
                     break;
                default:
                     throw Exception("Unknown scan mode");
             }
             return -1;
         }
I still do not understand how this function get's fired on the linuxserver end. Does the LSCP command need to be parsed by me in another place other than /src/db/InstrumentsDb.cpp?

Thanks!
Christopher Cherrett
Founder of The Open Octave Project
http://www.openoctave.org

ccherrett
Advanced User
Posts: 162
Joined: Wed Jan 23, 2008 11:24 pm
Contact:

Re: I am Coding Create Instruments as Directories

Post by ccherrett » Fri Sep 26, 2008 11:36 pm

I make it into this function and cannot see where it goes. Scan only seems to scan the directories but this function does not return anything. I feel lost in code :) I followed to DirectoryWalker, however it just seems to validate if it is a directory. What am I doing wrong here?

Thanks!

Code: Select all

        void InstrumentsDb::AddInstrumentsRecursive(String DbDir, String FsDir, bool Flat, ScanProgress* pProgress) {
            dmsg(2,("InstrumentsDb: AddInstrumentsRecursive(DbDir=%s,FsDir=%s,Flat=%d)\n", DbDir.c_str(), FsDir.c_str(), Flat));
            if (pProgress != NULL) {
                InstrumentFileCounter c;
                pProgress->SetTotalFileCount(c.Count(FsDir));
            }
    
            DirectoryScanner d;
            d.Scan(DbDir, FsDir, Flat, pProgress);
        } 
Christopher Cherrett
Founder of The Open Octave Project
http://www.openoctave.org

grishata
Developer
Posts: 138
Joined: Thu Jan 24, 2008 7:21 pm
Location: Bulgaria
Contact:

Re: I am Coding Create Instruments as Directories

Post by grishata » Sat Sep 27, 2008 12:18 am

ccherrett wrote:Could you possibly help me to understand what is happening when Fantasia passed information to linuxsampler?
LinuxSampler parses the lscp commands using an automatically generated parser by a parser generator, usually bison.
The grammar is located in linuxsampler/src/network/lscp.y
Look around line 188
Usually, it calls some method from linuxsampler/src/network/lscpserver.cpp

grishata
Developer
Posts: 138
Joined: Thu Jan 24, 2008 7:21 pm
Location: Bulgaria
Contact:

Re: I am Coding Create Instruments as Directories

Post by grishata » Sat Sep 27, 2008 12:51 am

ccherrett wrote:I make it into this function and cannot see where it goes. Scan only seems to scan the directories but this function does not return anything. I feel lost in code :) I followed to DirectoryWalker, however it just seems to validate if it is a directory. What am I doing wrong here?
Scan calls:

Code: Select all

           /**
             * Walks through the directory tree that is located under the
             * directory <b>Dir</b>, and calls <b>pWalker->DirectoryEntry()</b>
             * once for each directory in the tree and <b>pWalker->FileEntry()</b>
             * once for each file in the tree. Note that this method can be 
             * recursively invoked from within the callback functions
             * <b>pWalker->DirectoryEntry()</b> and <b>pWalker->FileEntry()</b>.
             * @throws Exception If the specified path is missing or is not a directory.
             * Exception is also thrown, and the directory tree walk is stopped,
             * if <b>pWalker->DirectoryEntry()</b> or <b>pWalker->FileEntry()</b>
             * throws Exception.
             */
            static void WalkDirectoryTree(std::string Dir, DirectoryWalker* pWalker);
which calls pWalker->DirectoryEntry() once for each directory in the subtree, in this case DirectoryScanner::DirectoryEntry()

grishata
Developer
Posts: 138
Joined: Thu Jan 24, 2008 7:21 pm
Location: Bulgaria
Contact:

Re: I am Coding Create Instruments as Directories

Post by grishata » Sat Sep 27, 2008 1:32 am

btw, if you are not using some IDE like NetBeans, you can find all occurrences of a particular function using the find command, like:

Code: Select all

find linuxsampler/src/ -exec grep -H "SomeFunction(" {} \;

ccherrett
Advanced User
Posts: 162
Joined: Wed Jan 23, 2008 11:24 pm
Contact:

Re: I am Coding Create Instruments as Directories

Post by ccherrett » Sat Sep 27, 2008 3:52 am

I am going in circles with directory walker. I think I am just missing the obvious. Can you point me to the actual function that is writing to sqlite3?

I got stumped at:

Code: Select all

 
        void InstrumentFileCounter::FileEntry(std::string Path) {
            if(Path.length() < 4) return;
            if(!strcasecmp(".gig", Path.substr(Path.length() - 4).c_str())) FileCount++;
        };
It seems to me that all FileEntry() does is increment FileCount. When does the actual file get written to the db?

Thanks!
Christopher Cherrett
Founder of The Open Octave Project
http://www.openoctave.org

ccherrett
Advanced User
Posts: 162
Joined: Wed Jan 23, 2008 11:24 pm
Contact:

Re: I am Coding Create Instruments as Directories

Post by ccherrett » Sat Sep 27, 2008 7:03 am

OK I finally figured it out! :)

I tracked down the INSERT statements and backtracked from there because that is the last step in the chain. It seems to make sense to me know.

Thanks!

I will most likely have this working tomorrow! :)
Christopher Cherrett
Founder of The Open Octave Project
http://www.openoctave.org

ccherrett
Advanced User
Posts: 162
Joined: Wed Jan 23, 2008 11:24 pm
Contact:

Re: I am Coding Create Instruments as Directories

Post by ccherrett » Sat Sep 27, 2008 7:17 am

grishata,

Why not idle in the freenode #linuxsampler irc channel? It would sure help to speed up development. If someone wants to program in blender they can get help instantly in #blendercoders. It encourages development. It sure is tough learning to code an app by code diving. Most people would give up and just ask you to put it in :)

I am always in #linuxsampler

Thanks!
Christopher Cherrett
Founder of The Open Octave Project
http://www.openoctave.org

Post Reply