From 7f4b2fe9c63f8c5d194a0243b153dd338f47c108 Mon Sep 17 00:00:00 2001 From: martincameron Date: Wed, 3 Jun 2020 21:16:22 +0100 Subject: [PATCH] Support loading IFF and raw samples with no extension. --- README.md | 2 +- Tracker3.java | 63 +++++++++++++++++++++++++++------------------------ 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 808218f..d563482 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A simple music editor for 4 and 8 channel Protracker modules. Modules and samples can be loaded by pressing DIR and navigating to the file. -Samples must have the file extension ".WAV" ".IFF" or ".RAW". +Hold shift to load IFF-8SVX and signed 8-bit RAW samples with no file extension. Notes can be entered using a virtual piano keyboard (QWERTY layout). diff --git a/Tracker3.java b/Tracker3.java index e85b670..44ce7fb 100644 --- a/Tracker3.java +++ b/Tracker3.java @@ -396,10 +396,10 @@ public synchronized void keyPressed( KeyEvent e ) switch( gadType[ focus ] ) { case GAD_TYPE_TEXTBOX: - keyTextbox( focus, e.getKeyChar(), e.getKeyCode() ); + keyTextbox( focus, e.getKeyChar(), e.getKeyCode(), e.isShiftDown() ); break; case GAD_TYPE_LISTBOX: - keyListbox( focus, e.getKeyChar(), e.getKeyCode() ); + keyListbox( focus, e.getKeyChar(), e.getKeyCode(), e.isShiftDown() ); trigger( -1, mapEventKey( KEY_MAP, e.getKeyCode() ) ); break; case GAD_TYPE_PATTERN: @@ -460,10 +460,10 @@ public synchronized void mousePressed( MouseEvent e ) clickTextbox( clicked ); break; case GAD_TYPE_SLIDER: - clickSlider( clicked ); + clickSlider( clicked, e.isShiftDown() ); break; case GAD_TYPE_LISTBOX: - clickListbox( clicked ); + clickListbox( clicked, e.isShiftDown() ); break; case GAD_TYPE_PATTERN: clickPattern( clicked, e.isShiftDown() ); @@ -471,7 +471,7 @@ public synchronized void mousePressed( MouseEvent e ) default: if( clicked > 0 ) { - action( clicked ); + action( clicked, e.isShiftDown() ); } } focus = clicked; @@ -489,13 +489,13 @@ public synchronized void mouseReleased( MouseEvent e ) { gadSelected[ focus ] = false; gadRedraw[ focus ] = true; - action( focus ); + action( focus, e.isShiftDown() ); focus = 0; repaint(); } break; case GAD_TYPE_SLIDER: - action( focus ); + action( focus, e.isShiftDown() ); focus = 0; repaint(); break; @@ -853,7 +853,7 @@ private void clickTextbox( int gadnum ) gadRedraw[ gadnum ] = true; } - private void keyTextbox( int gadnum, char chr, int key ) + private void keyTextbox( int gadnum, char chr, int key, boolean shift ) { int columns = ( gadWidth[ gadnum ] - 16 ) / 8; String text = gadText[ gadnum ][ 0 ]; @@ -924,7 +924,7 @@ private void keyTextbox( int gadnum, char chr, int key ) default: if( chr == 10 ) { - action( gadnum ); + action( gadnum, shift ); text = gadText[ gadnum ][ 0 ]; focus = 0; } @@ -962,7 +962,7 @@ private void drawSlider( Graphics g, int gadnum ) raiseBox( g, x + 2, y + d + 2, w - 4, s ); } - private void clickSlider( int gadnum ) + private void clickSlider( int gadnum, boolean shift ) { int ss = ( gadHeight[ gadnum ] - 12 ) * gadRange[ gadnum ] / gadMax[ gadnum ] + 8; int so = ( gadHeight[ gadnum ] - 12 ) * gadValue[ gadnum ] / gadMax[ gadnum ]; @@ -976,7 +976,7 @@ private void clickSlider( int gadnum ) } gadValue[ gadnum ] = sp; gadRedraw[ gadLink[ gadnum ] > 0 ? gadLink[ gadnum ] : gadnum ] = true; - action( gadnum ); + action( gadnum, shift ); } else if( clickY > ( sy + ss ) ) { @@ -987,7 +987,7 @@ else if( clickY > ( sy + ss ) ) } gadValue[ gadnum ] = sp; gadRedraw[ gadLink[ gadnum ] > 0 ? gadLink[ gadnum ] : gadnum ] = true; - action( gadnum ); + action( gadnum, shift ); } } @@ -1070,14 +1070,14 @@ else if( gadValues[ gadnum ] != null && idx < gadValues[ gadnum ].length ) } } - private void clickListbox( int gadnum ) + private void clickListbox( int gadnum, boolean shift ) { int time = ( int ) System.currentTimeMillis(); int dt = time - gadRange[ gadnum ]; int item = gadValue[ gadnum ] + ( clickY - gadY[ gadnum ] - 6 ) / 16; if( item == gadItem[ gadnum ] && dt > 0 && dt < 500 ) { - action( gadnum ); + action( gadnum, shift ); gadRange[ gadnum ] = 0; } else @@ -1091,7 +1091,7 @@ private void clickListbox( int gadnum ) } } - private void keyListbox( int gadnum, char chr, int key ) + private void keyListbox( int gadnum, char chr, int key, boolean shift ) { int item = gadItem[ gadnum ]; switch( key ) @@ -1124,7 +1124,7 @@ private void keyListbox( int gadnum, char chr, int key ) default: if( chr == 10 ) { - action( gadnum ); + action( gadnum, shift ); } break; } @@ -1693,7 +1693,7 @@ private void escape( int gadnum ) } } - private void action( int gadnum ) + private void action( int gadnum, boolean shift ) { try { @@ -1726,13 +1726,17 @@ private void action( int gadnum ) else { selectedFile = gadItem[ GADNUM_DIR_LISTBOX ]; - load( file ); + load( file, shift ); } } else { - selectedFile = 0; - listDir( file.getParentFile() ); + file = file.getParentFile(); + if( file != null ) + { + selectedFile = 0; + listDir( file ); + } } } break; @@ -1808,8 +1812,6 @@ private void action( int gadnum ) play(); } break; - default: - System.out.println( gadnum ); } } catch( Exception e ) @@ -2209,7 +2211,7 @@ private void optimize() listInstruments(); } - private void load( File file ) throws IOException + private void load( File file, boolean shift ) throws IOException { String extension = file.getName().toLowerCase(); if( extension.length() > 3 ) @@ -2220,13 +2222,16 @@ private void load( File file ) throws IOException { loadWav( file, 0 ); } - else if( extension.equals( ".iff" ) ) - { - loadIff( file ); - } - else if( extension.equals( ".raw" ) ) + else if( extension.equals( ".iff" ) || extension.equals( ".raw" ) || shift ) { - loadRaw( file ); + try + { + loadIff( file ); + } + catch( IllegalArgumentException e ) + { + loadRaw( file ); + } } else {