HISE Logo Forum
    • Categories
    • Register
    • Login

    Get Sample Filename from Sampler using custom Sample Maps.

    Scheduled Pinned Locked Moved General Questions
    samplerfilenameattribute
    72 Posts 4 Posters 4.0k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • trillbillyT
      trillbilly @d.healey
      last edited by

      @d-healey Here is how I am getting the samplemaps into the viewport.

      const var Sampler1 = Synth.getSampler("Sampler1"); //sampler
      const var SampleViewer1 = Content.getComponent("SampleViewer1"); //viewport
      const var list = Sampler.getSampleMapList(); //samplemaps
      
      SampleViewer1.set("useList", true);
      SampleViewer1.set("items", list.join("\n"));
      
      inline function onSampleViewer1Control(component, value)
      {
      	Sampler1.loadSampleMap(list[value]);
      };
      
      Content.getComponent("SampleViewer1").setControlCallback(onSampleViewer1Control);
      

      If I do this, the compile works but does not pass the name to the label.

      const var Sampler1 = Synth.getSampler("Sampler1"); //sampler
      const var SampleViewer1 = Content.getComponent("SampleViewer1"); //viewport
      const var list = Sampler.getSampleMapList(); //samplemaps
      const var SampleName1 = Content.getComponent("SampleName1"); //label
      
      SampleViewer1.set("useList", true);
      SampleViewer1.set("items", list.join("\n"));
      
      inline function onSampleViewer1Control(component, value)
      {
      	Sampler1.loadSampleMap(list[value]);
      	SampleName1.setValue(value);
      };
      
      Content.getComponent("SampleViewer1").setControlCallback(onSampleViewer1Control);
      
      d.healeyD 1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey @trillbilly
        last edited by

        @trillbilly What is value?

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        trillbillyT 1 Reply Last reply Reply Quote 0
        • trillbillyT
          trillbilly @d.healey
          last edited by

          @d-healey Ive got it working with this minor change. Does this look better?

          inline function onSampleViewer1Control(component, value)
          {
          	Sampler1.loadSampleMap(list[value]);
          	SampleName1.setValue(list[value]);
          };
          
          Content.getComponent("SampleViewer1").setControlCallback(onSampleViewer1Control);
          

          This works when using the viewport to change sample. Now the issue is if I use my randomize samplemap button, which does change the sample selected in the viewport, it doesnt update the label.

          I'll dive into the button code and see if I cant figure that out as well.

          d.healeyD 1 Reply Last reply Reply Quote 1
          • d.healeyD
            d.healey @trillbilly
            last edited by

            @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

            Does this look better?

            Looking good

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            trillbillyT 1 Reply Last reply Reply Quote 0
            • trillbillyT
              trillbilly @d.healey
              last edited by

              @d-healey Great. I think I figured out the random button issue too. Does this look solid or am I being hacky somewhere?

              const sampleMapsRAN = Sampler.getSampleMapList();
              
              inline function onShuffleSamplebtn1Control(component, value)
              {
              	if (value)
              	{
              		local index = Math.randInt(0, sampleMapsRAN.length);
              		local sampleMap = sampleMapsRAN[index];
              
              		Sampler1.loadSampleMap(sampleMap);
              		
              		SampleViewer1.setValue(index);
              		SampleName1.setValue(list[index]);
              
              	}
              };
              
              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @trillbilly
                last edited by

                @trillbilly Looks good, you could also remove the nest by returning early (doesn't change the logic, just improves readability).

                	if (!value)
                            return;
                	
                	local index = Math.randInt(0, sampleMapsRAN.length);
                	local sampleMap = sampleMapsRAN[index];
                
                	Sampler1.loadSampleMap(sampleMap);
                		
                	SampleViewer1.setValue(index);
                	SampleName1.setValue(list[index]);
                

                Libre Wave - Freedom respecting instruments and effects
                My Patreon - HISE tutorials
                YouTube Channel - Public HISE tutorials

                trillbillyT 1 Reply Last reply Reply Quote 1
                • trillbillyT
                  trillbilly @d.healey
                  last edited by

                  @d-healey Got it, thank you. Now to figure out how to get the label to change with the sample import. Iv tried adding the bit of code you gave me to the SampleLoadSave.js but this did not work either. Here is what I used and where i added.

                  inline function loadSample(file)
                  {
                  	local s = [Sampler1.parseSampleFile(file)];
                  
                  	local selection = [Sampler1.createSelection(".*")];
                  	SampleName1.get(selection);
                  	
                  	s[0]['LoKey'] = 60;
                  	s[0]['HiKey'] = 60;
                  	s[0]['Root'] = 60;
                  	
                  	Sampler1.loadSampleMapFromJSON(s);
                  }
                  

                  This compiles but 1. does not change the label and 2. does not allow sample to change. So i think im pretty far off or in the wrong location.

                  d.healeyD 1 Reply Last reply Reply Quote 0
                  • d.healeyD
                    d.healey @trillbilly
                    last edited by

                    @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

                    local s = [Sampler1.parseSampleFile(file)];
                    local selection = [Sampler1.createSelection(".*")];

                    What are the square brackets for?

                    SampleName1.get(selection);

                    What's this?

                    Libre Wave - Freedom respecting instruments and effects
                    My Patreon - HISE tutorials
                    YouTube Channel - Public HISE tutorials

                    trillbillyT 1 Reply Last reply Reply Quote 0
                    • trillbillyT
                      trillbilly @d.healey
                      last edited by

                      @d-healey The square bracket for local s = [Sampler1.parseSampleFile(file)]; was in the CustomSampleImport demo already so I figured this is how it was supposed to be.

                      SampleName1.get(selection); is my attempt to read the array and pull the custom sample file name.

                      d.healeyD 1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @trillbilly
                        last edited by

                        @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

                        is my attempt to read the array and pull the custom sample file name.

                        I already gave you the code to get an array of all the samples in the current sample map. All you need to do is loop through the array (or if there's only ever one sample just use the first element) and retrieve the Filename property which you can then process further with the string commands. And at the link I posted before (read every post at that link) you'll see how to retrieve properties - https://forum.hise.audio/topic/64/fun-with-regex/8?_=1708021905238

                        Libre Wave - Freedom respecting instruments and effects
                        My Patreon - HISE tutorials
                        YouTube Channel - Public HISE tutorials

                        trillbillyT 1 Reply Last reply Reply Quote 0
                        • trillbillyT
                          trillbilly @d.healey
                          last edited by

                          @d-healey I know, I can feel you've basically given me the answer and yet its like I'm blind, deaf & dumb. However, of those may be true. I'm looking right over it. I'll go back and figure it out. I need to take a HISE break to work on another HISE project. The cycle...

                          trillbillyT 1 Reply Last reply Reply Quote 1
                          • trillbillyT
                            trillbilly @trillbilly
                            last edited by

                            @d-healey Im able to get the filename to print with this

                            const selection = Sampler1.createSelection(".*");
                            
                            for (s in selection)
                            
                            	{
                            	//Console.print(s.get(Sampler1.FileName));
                            	s.set(Sampler1.Filename, s.get(Sampler1.Filename));
                            	SampleName1.setValue(s[value]);
                            	}
                            

                            I dont see any REGEX property ID for filename, or am looking (once gain) right over the post you're intending me to see.

                            Anymore help/direction is appreciated.

                            d.healeyD 1 Reply Last reply Reply Quote 0
                            • d.healeyD
                              d.healey @trillbilly
                              last edited by

                              @trillbilly

                              s.get(Sampler1.FileName)

                              That's the way to do it.

                              Libre Wave - Freedom respecting instruments and effects
                              My Patreon - HISE tutorials
                              YouTube Channel - Public HISE tutorials

                              oskarshO trillbillyT 2 Replies Last reply Reply Quote 0
                              • oskarshO
                                oskarsh @d.healey
                                last edited by

                                @d-healey if I remember correctly this is not working for custom samplemaps. That's what my original post was all about. If it works by now that would be cool tho.

                                1 Reply Last reply Reply Quote 0
                                • trillbillyT
                                  trillbilly @d.healey
                                  last edited by trillbilly

                                  @d-healey If this is the correct way, what about my script is incorrect? I have also tried

                                  	SampleName1.setValue(s.get(Sampler1.Filename));
                                  

                                  But neither snippet has worked. They have both compiled, but not changed the label.

                                  @oskarsh This is what I was afraid of. How else could you view the name of the currently loaded sample if its a custom samplemap?

                                  d.healeyD LindonL 2 Replies Last reply Reply Quote 0
                                  • d.healeyD
                                    d.healey @trillbilly
                                    last edited by

                                    @trillbilly I don't see in your script where you are setting the text property of the label

                                    Libre Wave - Freedom respecting instruments and effects
                                    My Patreon - HISE tutorials
                                    YouTube Channel - Public HISE tutorials

                                    trillbillyT 1 Reply Last reply Reply Quote 0
                                    • LindonL
                                      Lindon @trillbilly
                                      last edited by

                                      @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

                                      @d-healey If this is the correct way, what about my script is incorrect? I have also tried

                                      	SampleName1.setValue(s.get(Sampler1.Filename));
                                      

                                      But neither snippet has worked. They have both compiled, but not changed the label.

                                      @oskarsh This is what I was afraid of. How else could you view the name of the currently loaded sample if its a custom samplemap?

                                      if:

                                      SampleName1.setValue(s[value]);

                                      is attempting to set the text of a label called SampleName1, then try:

                                      SampleName1.set("text",s[value]);

                                      -- but in your code thats gonna happen a lot of times - once for each sample name in selection

                                      HISE Development for hire.
                                      www.channelrobot.com

                                      1 Reply Last reply Reply Quote 0
                                      • trillbillyT
                                        trillbilly @d.healey
                                        last edited by

                                        @d-healey I assume thats what something like this was doing:

                                        const selection = Sampler1.createSelection(".*");
                                        
                                        for (s in selection)
                                        
                                        	{
                                        	//Console.print(s.get(Sampler1.FileName));
                                        	s.set(Sampler1.Filename, s.get(Sampler1.Filename));
                                        	SampleName1.setValue(s.get(Sampler1.Filename));//label
                                        

                                        Since this changes the label text from a combobox/viewport samplemap:

                                        const var list = Sampler.getSampleMapList();
                                        
                                        inline function onSampleViewer1Control(component, value)//viewport
                                        {
                                        	Sampler1.loadSampleMap(list[value]);
                                        	SampleName1.setValue(list[value]);//label
                                        	
                                        };
                                        
                                        LindonL d.healeyD 2 Replies Last reply Reply Quote 0
                                        • LindonL
                                          Lindon @trillbilly
                                          last edited by

                                          @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

                                          @d-healey I assume thats what something like this was doing:

                                          const selection = Sampler1.createSelection(".*");
                                          
                                          for (s in selection)
                                          
                                          	{
                                          	//Console.print(s.get(Sampler1.FileName));
                                          	s.set(Sampler1.Filename, s.get(Sampler1.Filename));
                                          	SampleName1.setValue(s.get(Sampler1.Filename));//label
                                          

                                          Since this changes the label text from a combobox/viewport samplemap:

                                          const var list = Sampler.getSampleMapList();
                                          
                                          inline function onSampleViewer1Control(component, value)//viewport
                                          {
                                          	Sampler1.loadSampleMap(list[value]);
                                          	SampleName1.setValue(list[value]);//label
                                          	
                                          };
                                          

                                          look at those two pieces of code.... one is passing in something called value (the second piece of code) where as the first has no idea what "value" is....

                                          HISE Development for hire.
                                          www.channelrobot.com

                                          1 Reply Last reply Reply Quote 0
                                          • d.healeyD
                                            d.healey @trillbilly
                                            last edited by

                                            @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

                                            s.set(Sampler1.Filename, s.get(Sampler1.Filename));

                                            What do you think this does?

                                            @trillbilly said in Get Sample Filename from Sampler using custom Sample Maps.:

                                            SampleName1.setValue(s.get(Sampler1.Filename));//label

                                            Try changing the text instead of the value.

                                            Libre Wave - Freedom respecting instruments and effects
                                            My Patreon - HISE tutorials
                                            YouTube Channel - Public HISE tutorials

                                            LindonL trillbillyT 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            20

                                            Online

                                            1.7k

                                            Users

                                            11.8k

                                            Topics

                                            103.2k

                                            Posts