HISE Logo Forum
    • Categories
    • Register
    • Login

    Copy & Save '.mid file' to 'folder' || Help.

    Scheduled Pinned Locked Moved Solved Scripting
    22 Posts 3 Posters 85 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.
    • d.healeyD
      d.healey @Chazrox
      last edited by

      @Chazrox File.copy() ;)

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

      ChazroxC 1 Reply Last reply Reply Quote 0
      • ChazroxC
        Chazrox @d.healey
        last edited by

        @d-healey I need to understand something. Docs says that File.copy(var target) target == the NEW file? So that would be the new name? Then just throw that into a variable and File.move() to directory?

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

          @Chazrox Pass in a File object.

          For example

          
          inline function copyMidiFile(original)
          {
              local filename = original.toString(original.Filename);
              local newFile = FileSystem.getFolder(FileSystem.AppData).getChildFile(filename);
              original.copy(newFile);
          }
          

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

          ChazroxC 2 Replies Last reply Reply Quote 1
          • ChazroxC
            Chazrox @d.healey
            last edited by

            @d-healey Thank you! I'll try this now. 🙏

            1 Reply Last reply Reply Quote 0
            • ChazroxC
              Chazrox @d.healey
              last edited by Chazrox

              @d-healey no errors but its not working..
              can you spot it? 🙏

               original = FileSystem.fromAbsolutePath(full); // full is the full filepath name from the file dropped. 
              
                  if (original == undefined)
                  {
                      
                  }
                  else
                  {
                      local filename;
                      filename = original.toString(original.Filename);
              
                      local appDataDir;
                      appDataDir = FileSystem.getFolder(FileSystem.AppData); 
              
                      local newFile;
                      newFile = appDataDir.getChildFile(filename);
              
                      original.copy(newFile);
                      original.move(appDataDir);
              
                      Console.print("Saved copy to AppData: " + newFile.toString(newFile.FullPath));
                  }
              
              d.healeyD 1 Reply Last reply Reply Quote 0
              • d.healeyD
                d.healey @Chazrox
                last edited by

                @Chazrox

                In what way is it not working?

                // Why the empty if statement?
                if (original == undefined)
                {        
                }
                
                // Each of these can be one line
                local filename;
                filename = original.toString(original.Filename);
                
                local appDataDir;
                appDataDir = FileSystem.getFolder(FileSystem.AppData); 
                
                local newFile;
                newFile = appDataDir.getChildFile(filename);
                
                // Why are you copying then overwriting it with the original?
                original.copy(newFile);
                original.move(appDataDir);
                

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

                ChazroxC 1 Reply Last reply Reply Quote 0
                • ChazroxC
                  Chazrox @d.healey
                  last edited by

                  @d-healey

                  Why the empty if statement?

                  I had something there but deleted it. I just removed it.

                  Why are you copying then overwriting it with the original?

                  I dont know what Im doing lol. I was just trying things because it wasnt working.

                  @d-healey said in Copy & Save '.mid file' to 'folder' || Example?:

                  In what way is it not working?

                  When I drop the .mid file on my panel, the rest of the script executes but this part of it doesnt. I dont see any files in AppData or any other directory that I test.

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

                    @Chazrox said in Copy & Save '.mid file' to 'folder' || Example?:

                    When I drop the .mid file on my panel, the rest of the script executes but this part of it doesnt. I dont see any files in AppData or any other directory that I test.

                    Can you show me where you are calling your function?

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

                    ChazroxC 1 Reply Last reply Reply Quote 0
                    • ChazroxC
                      Chazrox @d.healey
                      last edited by Chazrox

                      @d-healey complete mess at the moment but have a look.

                      inline function onpnlMIDIFilesFileDrop_B(obj)
                      {
                          // Maintain hover state for paint()
                          local prevHover;
                          prevHover = this.data.hover ? 1 : 0;
                      
                          this.data.hover = (obj.hover && !obj.drop) ? 1 : 0;
                      
                          if ((this.data.hover ? 1 : 0) != prevHover)
                              this.repaint();
                      
                          // Hover hint
                          if (obj.hover && !obj.drop)
                          {
                              this.data.text    = "Drop to load!";
                              this.data.dropped = false;
                              this.changed();
                              return;
                          }
                      
                          
                          if (!obj.drop || obj.fileName == undefined)
                              return;
                      
                          // Parse basename (no path, no extension)
                          local full;
                          full = obj.fileName;
                      
                          local slash;
                          slash = Math.max(full.lastIndexOf("/"), full.lastIndexOf("\\"));
                      
                          local dot;
                          dot = full.lastIndexOf(".");
                          if (dot < 0) dot = full.length;
                      
                          local base;
                          base = full.substring(slash + 1, dot);
                      
                          this.data.filename = base;   // paint()
                          this.data.fileName = base;   // sync
                      
                          // Hide the slider while bounds/values are inconsistent
                          RangeSlider.set("visible", 0);
                      
                          // Load into MIDIPlayer1 (track 1)
                          MIDIPlayer1.setFile(full, true, true);
                          if (MIDIPlayer1.setTrack != undefined) MIDIPlayer1.setTrack(1);
                      
                          // Start polling until the events are actually available
                          midiRangeTimer.stopTimer();
                          midiRangeTimer.startTimer(50);
                      
                          // -----------------------------------------------------------
                          // COPY DROPPED FILE INTO AppData 
                          // -----------------------------------------------------------
                          local original;
                          original = FileSystem.fromAbsolutePath(full);
                      
                          if (original == !undefined)
                          {
                              local filename;
                              filename = original.toString(original.Filename);
                      
                              local appDataDir;
                              appDataDir = FileSystem.getFolder(FileSystem.Downloads);
                      
                              local newFile;
                              newFile = appDataDir.getChildFile(filename);
                      
                              original.copy(newFile);
                              //original.move(appDataDir);
                      
                              Console.print("Saved copy to AppData: " + newFile.toString(newFile.FullPath));
                          }
                      
                          // Your existing flow
                          // Save As "FAVORITE" Midi File in AppDataFolder
                          // SaveFavoriteMidiFiles();
                      
                          // setAnalysisWindowFull();
                          disableAllChords();
                          // groupMidiNotesByTimeInWindow(analyzeStartMs, analyzeEndMs);
                          // RangeSlider.setValue({ min: RangeSlider.get("min"), max: RangeSlider.get("max")});
                          disableAllChords();
                          // addChordsFromCurrentWindow();
                      
                          // UI flags
                          this.data.text    = "Loaded";
                          this.data.dropped = true;
                          this.data.hover   = false;
                          this.changed();
                          this.repaint();
                      
                          knbSmartStrength.changed();
                          pnlCustomMidiPanel.sendRepaintMessage();
                          pnlCustomMidiRipView.sendRepaintMessage();
                      }
                      
                      d.healeyD 1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @Chazrox
                        last edited by

                        @Chazrox I'd start with some Console.prints to see where the processing is getting up to. Is the filename you're storing what you expect it to be, is original a file object - instead of == undefined, use if (isDefined(original) && original.isFile()) to be certain.

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

                        ChazroxC 1 Reply Last reply Reply Quote 0
                        • ChazroxC
                          Chazrox @d.healey
                          last edited by

                          @d-healey ok. I'll check all of that now.

                          1 Reply Last reply Reply Quote 0
                          • ChazroxC
                            Chazrox
                            last edited by Chazrox

                            This is where im at now, still not working completely. All of the functions work in this code block except for the part where I want the dropped file saved to the AppData folder. Can anyone help with this please? 🙏

                            Scroll down a little bit...

                            //! onPnlMIDIFilesFileDrop ---------------------------------------------------------------
                            inline function onpnlMIDIFilesFileDrop_B(obj)
                            {
                                // HOVER STATE
                                prevHover = this.data.hover ? 1 : 0;
                            
                                this.data.hover = (obj.hover && !obj.drop) ? 1 : 0;
                            
                                if ((this.data.hover ? 1 : 0) != prevHover)
                                {
                                	this.repaint();
                                }
                            
                                // HOVER CHECK
                                if (obj.hover && !obj.drop)
                                {
                                    this.data.text    = "Drop to load!";
                                    this.data.dropped = false;
                                    this.changed();
                                    return;
                                }
                               
                                if (!obj.drop || obj.fileName == undefined)
                                {
                                	return;	
                                }
                            
                                // PARSE BASE NAME
                                local full = obj.fileName;   
                                local slash = Math.max(full.lastIndexOf("/"), full.lastIndexOf("\\"));   
                                local dot = full.lastIndexOf(".");
                                
                                if (dot < 0) 
                                {
                                	dot = full.length;
                                }
                                
                                local base = full.substring(slash + 1, dot);
                            
                                this.data.filename = base;   // paint()
                                this.data.fileName = base;   // sync
                            	
                            	Console.print("BASE__" + base);
                                // HIDE RANGE SLIDER WHILE NO EVENTS
                                RangeSlider.set("visible", 0);
                            
                                // LOAD MIDI PLAYER TRACK 1
                                MIDIPlayer1.setFile(full, true, true);
                                if (MIDIPlayer1.setTrack != undefined) MIDIPlayer1.setTrack(1);
                            		
                            	// START POLLING EVENTS
                            	midiRangeTimer.stopTimer();
                            	midiRangeTimer.startTimer(50);
                                // -----------------------------------------------------------
                                // COPY DROPPED FILE INTO AppData 
                                // -----------------------------------------------------------
                               
                            	local original = FileSystem.fromAbsolutePath(full);
                            	local filename =  original.toString(this.data.Filename);
                                if (isDefined(original) && original.isFile())
                                {
                                          
                            		Console.print(filename.toString());
                                   	Console.print("ORIGINAL__" + original);
                                    
                                    local appDataDir = FileSystem.getFolder(FileSystem.Downloads);
                                    local newFile = appDataDir.getChildFile(filename);
                            
                                    original.copy(newFile);
                                   // newFile.move(appDataDir);
                            		Console.print("NEWNEWNEW" + newFile);
                                }
                            	
                                Console.print("Saved copy to AppData: " + newFile.toString(newFile.FullPath));
                            	
                            		
                               
                                // Save As "FAVORITE" Midi File in AppDataFolder
                                // SaveFavoriteMidiFiles();
                            
                                // setAnalysisWindowFull();
                                disableAllChords();
                                // groupMidiNotesByTimeInWindow(analyzeStartMs, analyzeEndMs);
                                // RangeSlider.setValue({ min: RangeSlider.get("min"), max: RangeSlider.get("max")});
                                disableAllChords();
                                // addChordsFromCurrentWindow();
                            
                                // UI flags
                                this.data.text    = "Loaded";
                                this.data.dropped = true;
                                this.data.hover   = false;
                                this.changed();
                                this.repaint();
                            
                                knbSmartStrength.changed();
                                pnlCustomMidiPanel.sendRepaintMessage();
                                pnlCustomMidiRipView.sendRepaintMessage();
                            }
                            

                            none of my .prints return any results in that section either.

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

                              @Chazrox said in Copy & Save '.mid file' to 'folder' || Help.:
                              [snip]

                              Ok lets start with your code...

                              
                              
                                  // PARSE BASE NAME
                                  local full = obj.fileName;   
                              }
                              

                              and later:

                              local original = FileSystem.fromAbsolutePath(full);
                              

                              So you are taking the filename from the obj and (later)asking for the actual file using .fromAbsolutePath()

                              ..but absolute path wants just that - an absolute path not the file name....so something like C:\documents\myfolder\myfilename.mid

                              so this:

                              local original = FileSystem.fromAbsolutePath(full);
                              

                              is probably failing - I think. so this:

                              if (isDefined(original) && original.isFile())
                                  {
                              
                                  etc. etc...
                              

                              is going to return false - and not execute....you need to do a LOT more Console.print debugging....

                              like this:

                              //! onPnlMIDIFilesFileDrop ---------------------------------------------------------------
                              inline function onpnlMIDIFilesFileDrop_B(obj)
                              {
                                  // HOVER STATE
                                  prevHover = this.data.hover ? 1 : 0;
                              
                                  this.data.hover = (obj.hover && !obj.drop) ? 1 : 0;
                              
                                  if ((this.data.hover ? 1 : 0) != prevHover)
                                  {
                                  	this.repaint();
                                  }
                              
                                  // HOVER CHECK
                                  if (obj.hover && !obj.drop)
                                  {
                                      this.data.text    = "Drop to load!";
                                      this.data.dropped = false;
                                      this.changed();
                                      return;
                                  }
                                 
                                  if (!obj.drop || obj.fileName == undefined)
                                  {
                                  	return;	
                                  }
                              
                                  // PARSE BASE NAME
                                  local full = obj.fileName;   
                                  local slash = Math.max(full.lastIndexOf("/"), full.lastIndexOf("\\"));   
                                  local dot = full.lastIndexOf(".");
                              
                              //============
                                   Console.print("full contains:" + full);
                              //=============
                                  
                                  if (dot < 0) 
                                  {
                                  	dot = full.length;
                                  }
                                  
                                  local base = full.substring(slash + 1, dot);
                              
                                  this.data.filename = base;   // paint()
                                  this.data.fileName = base;   // sync
                              	
                              	Console.print("BASE__" + base);
                                  // HIDE RANGE SLIDER WHILE NO EVENTS
                                  RangeSlider.set("visible", 0);
                              
                                  // LOAD MIDI PLAYER TRACK 1
                                  MIDIPlayer1.setFile(full, true, true);
                                  if (MIDIPlayer1.setTrack != undefined) MIDIPlayer1.setTrack(1);
                              		
                              	// START POLLING EVENTS
                              	midiRangeTimer.stopTimer();
                              	midiRangeTimer.startTimer(50);
                                  // -----------------------------------------------------------
                                  // COPY DROPPED FILE INTO AppData 
                                  // -----------------------------------------------------------
                                 
                              	local original = FileSystem.fromAbsolutePath(full);
                              //===========
                                    Console.print("Original contains:" + original);
                                    Console.print("Original is defined ==:" + isDefined(original));
                                     Console.print("Original is a file ==:" + original.isFile());
                              //===========
                              	local filename =  original.toString(this.data.Filename);
                                  if (isDefined(original) && original.isFile())
                                  {
                                            
                              		Console.print(filename.toString());
                                     	Console.print("ORIGINAL__" + original);
                                      
                                      local appDataDir = FileSystem.getFolder(FileSystem.Downloads);
                                      local newFile = appDataDir.getChildFile(filename);
                              
                                      original.copy(newFile);
                                     // newFile.move(appDataDir);
                              		Console.print("NEWNEWNEW" + newFile);
                                  }
                              	
                                  Console.print("Saved copy to AppData: " + newFile.toString(newFile.FullPath));
                              	
                              		
                                 
                                  // Save As "FAVORITE" Midi File in AppDataFolder
                                  // SaveFavoriteMidiFiles();
                              
                                  // setAnalysisWindowFull();
                                  disableAllChords();
                                  // groupMidiNotesByTimeInWindow(analyzeStartMs, analyzeEndMs);
                                  // RangeSlider.setValue({ min: RangeSlider.get("min"), max: RangeSlider.get("max")});
                                  disableAllChords();
                                  // addChordsFromCurrentWindow();
                              
                                  // UI flags
                                  this.data.text    = "Loaded";
                                  this.data.dropped = true;
                                  this.data.hover   = false;
                                  this.changed();
                                  this.repaint();
                              
                                  knbSmartStrength.changed();
                                  pnlCustomMidiPanel.sendRepaintMessage();
                                  pnlCustomMidiRipView.sendRepaintMessage();
                              }
                              

                              HISE Development for hire.
                              www.channelrobot.com

                              LindonL ChazroxC 3 Replies Last reply Reply Quote 1
                              • LindonL
                                Lindon @Lindon
                                last edited by

                                @Lindon said in Copy & Save '.mid file' to 'folder' || Help.:

                                local filename = original.toString(this.data.Filename);

                                also whilst we are here, Im not sure you can say this:

                                
                                	local filename =  original.toString(this.data.Filename);
                                

                                what I think you mean is this:

                                
                                	local filename =  original.toString(original.Filename);
                                

                                But its not going to work anyway until you get a file into original, not a text string...

                                HISE Development for hire.
                                www.channelrobot.com

                                ChazroxC 2 Replies Last reply Reply Quote 2
                                • ChazroxC
                                  Chazrox @Lindon
                                  last edited by Chazrox

                                  @Lindon bro Thanks!

                                  Im gonna check this out right now and report back. 🙏
                                  I really appreciate the time brotha!

                                  These are a bunch of new api's for me so im sure I made alot of mistakes and asking chat gpt to help sometimes make things worse. lol

                                  1 Reply Last reply Reply Quote 0
                                  • ChazroxC
                                    Chazrox @Lindon
                                    last edited by

                                    @Lindon said in Copy & Save '.mid file' to 'folder' || Help.:

                                    you need to do a LOT more Console.print debugging....

                                    I really should. 🙏

                                    1 Reply Last reply Reply Quote 0
                                    • ChazroxC
                                      Chazrox @Lindon
                                      last edited by Chazrox

                                      @Lindon

                                      I was setting my B panels callback to my A panel....thats why none of my prints were hitting. When I was dropping on panel B, Panel A script was running which is already doing what it needs to do fine.

                                      uhggh.. lol.
                                      its one letter sometimes messing your whole day up. haha.

                                      const var pnlMIDIFiles_B = Content.getComponent("pnlMIDIFiles_B");
                                      pnlMIDIFiles_B.setFileDropCallback("All Callbacks", "*.mid", onpnlMIDIFilesFileDrop_B);
                                      
                                      

                                      Your prints you added are extensive and im going to follow that from now on! Thank You sir! Im getting alot of info from these prints which I should help big time. Again 🙏

                                      Screenshot 2025-08-31 at 4.22.36 AM.png

                                      1 Reply Last reply Reply Quote 0
                                      • ChazroxC
                                        Chazrox @Lindon
                                        last edited by Chazrox

                                        @Lindon @d-healey I GOT IT. 🙏 🙏 🙏

                                        After going through all the debugs I figured it out. Thank you guys so much. This was the last function I needed for my plugin which is just save a history of dropped files...and aside from some visual tweaks.....IM DONE!! Im on to the next step. Now i'll be buggin you guys about code-signing soon. haha. 🤛 Thanks so much!

                                        1 Reply Last reply Reply Quote 1
                                        • ChazroxC Chazrox has marked this topic as solved
                                        • ChazroxC
                                          Chazrox
                                          last edited by

                                          I'll be sharing a cleaned up snippet version and make an example of this for anybody that might be looking for it. Thanks again guys! 🙏

                                          1 Reply Last reply Reply Quote 0
                                          • ChazroxC
                                            Chazrox
                                            last edited by Chazrox

                                            This post is deleted!
                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            19

                                            Online

                                            1.9k

                                            Users

                                            12.4k

                                            Topics

                                            108.1k

                                            Posts